🐛(component): 修复 input-number 组件经度丢失

This commit is contained in:
就眠儀式
2022-11-08 23:09:56 +08:00
parent 3caf99a721
commit aaebe4f606
4 changed files with 26 additions and 4 deletions

View File

@@ -11,6 +11,7 @@ import { LayIcon } from "@layui/icons-vue";
import layButton from "../button/index.vue";
import { ref, watch, withDefaults, computed, Ref } from "vue";
import { InputNumberSize } from "./interface";
import { add, sub } from "./math"
export interface InputNumberProps {
modelValue?: number;
@@ -84,11 +85,11 @@ const maxControl = computed(() => {
});
const addition = function () {
num.value += Number(props.step);
num.value = add(num.value, props.step);
};
const subtraction = function () {
num.value -= Number(props.step);
num.value = Number(sub(num.value, props.step));
};
const longDown = function (fn: Function) {

View File

@@ -0,0 +1,21 @@
//加法
function add(arg1: number, arg2: number) {
var r1, r2, m;
try { r1 = arg1.toString().split(".")[1].length } catch (e) { r1 = 0 }
try { r2 = arg2.toString().split(".")[1].length } catch (e) { r2 = 0 }
m = Math.pow(10, Math.max(r1, r2))
return (arg1 * m + arg2 * m) / m
}
//减法
function sub(arg1: number, arg2: number) {
var r1, r2, m, n;
try { r1 = arg1.toString().split(".")[1].length } catch (e) { r1 = 0 }
try { r2 = arg2.toString().split(".")[1].length } catch (e) { r2 = 0 }
m = Math.pow(10, Math.max(r1, r2));
n = (r1 >= r2) ? r1 : r2;
return ((arg1 * m - arg2 * m) / m).toFixed(n);
}
export {
add,
sub,
}