🐛(component): 修复 input-number 小数精度问题
This commit is contained in:
parent
01400f38e5
commit
cc1f6de1b5
@ -89,7 +89,7 @@ const addition = function () {
|
||||
};
|
||||
|
||||
const subtraction = function () {
|
||||
num.value = Number(sub(num.value, props.step));
|
||||
num.value = sub(num.value, props.step);
|
||||
};
|
||||
|
||||
const longDown = function (fn: Function) {
|
||||
|
@ -1,6 +1,6 @@
|
||||
//加法
|
||||
function add(arg1: number, arg2: number) {
|
||||
var r1, r2, m;
|
||||
var r1, r2, m, c;
|
||||
try {
|
||||
r1 = arg1.toString().split(".")[1].length;
|
||||
} catch (e) {
|
||||
@ -11,12 +11,26 @@ function add(arg1: number, arg2: number) {
|
||||
} catch (e) {
|
||||
r2 = 0;
|
||||
}
|
||||
c = Math.abs(r1 - r2);
|
||||
m = Math.pow(10, Math.max(r1, r2));
|
||||
return (arg1 * m + arg2 * m) / m;
|
||||
}
|
||||
if (c > 0) {
|
||||
var cm = Math.pow(10, c);
|
||||
if (r1 > r2) {
|
||||
arg1 = Number(arg1.toString().replace(".", ""));
|
||||
arg2 = Number(arg2.toString().replace(".", "")) * cm;
|
||||
} else {
|
||||
arg1 = Number(arg1.toString().replace(".", "")) * cm;
|
||||
arg2 = Number(arg2.toString().replace(".", ""));
|
||||
}
|
||||
} else {
|
||||
arg1 = Number(arg1.toString().replace(".", ""));
|
||||
arg2 = Number(arg2.toString().replace(".", ""));
|
||||
}
|
||||
return (arg1 + arg2) / m;
|
||||
};
|
||||
//减法
|
||||
function sub(arg1: number, arg2: number) {
|
||||
var r1, r2, m, n;
|
||||
var r1, r2, m, c;
|
||||
try {
|
||||
r1 = arg1.toString().split(".")[1].length;
|
||||
} catch (e) {
|
||||
@ -27,8 +41,21 @@ function sub(arg1: number, arg2: number) {
|
||||
} catch (e) {
|
||||
r2 = 0;
|
||||
}
|
||||
c = Math.abs(r1 - r2);
|
||||
m = Math.pow(10, Math.max(r1, r2));
|
||||
n = r1 >= r2 ? r1 : r2;
|
||||
return ((arg1 * m - arg2 * m) / m).toFixed(n);
|
||||
}
|
||||
if (c > 0) {
|
||||
var cm = Math.pow(10, c);
|
||||
if (r1 > r2) {
|
||||
arg1 = Number(arg1.toString().replace(".", ""));
|
||||
arg2 = Number(arg2.toString().replace(".", "")) * cm;
|
||||
} else {
|
||||
arg1 = Number(arg1.toString().replace(".", "")) * cm;
|
||||
arg2 = Number(arg2.toString().replace(".", ""));
|
||||
}
|
||||
} else {
|
||||
arg1 = Number(arg1.toString().replace(".", ""));
|
||||
arg2 = Number(arg2.toString().replace(".", ""));
|
||||
}
|
||||
return (arg1 - arg2) / m;
|
||||
};
|
||||
export { add, sub };
|
||||
|
@ -110,7 +110,6 @@ const doHidden = function (e?: MouseEvent) {
|
||||
};
|
||||
|
||||
const calcPosistion = function () {
|
||||
|
||||
postionFns[props.position] &&
|
||||
(style.value = postionFns[props.position](
|
||||
triggerRefEl.value,
|
||||
@ -121,7 +120,9 @@ const calcPosistion = function () {
|
||||
|
||||
const updatePosistion = function () {
|
||||
if (innerVisible.value) {
|
||||
popperRefEl.value.offsetWidth === 0 ? nextTick(() => calcPosistion()) : calcPosistion();
|
||||
popperRefEl.value.offsetWidth === 0
|
||||
? nextTick(() => calcPosistion())
|
||||
: calcPosistion();
|
||||
nextTick(() => {
|
||||
calcPosistion();
|
||||
});
|
||||
|
@ -81,7 +81,7 @@ const getOption = (nodes: VNode[], newOptions: any[]) => {
|
||||
// @ts-ignore
|
||||
const label = item.children.default()[0].children;
|
||||
|
||||
if(typeof label == "string") {
|
||||
if (typeof label == "string") {
|
||||
// @ts-ignore
|
||||
item.props.label = label;
|
||||
}
|
||||
|
@ -105,8 +105,12 @@ const clearAllCutEffect = () => {
|
||||
};
|
||||
|
||||
const { t } = useI18n();
|
||||
const text = computed(() =>{ return props.text ? props.text : t("upload.text")});
|
||||
const dragText = computed(() => { return props.dragText ? props.dragText : t("upload.dragText")});
|
||||
const text = computed(() => {
|
||||
return props.text ? props.text : t("upload.text");
|
||||
});
|
||||
const dragText = computed(() => {
|
||||
return props.dragText ? props.dragText : t("upload.dragText");
|
||||
});
|
||||
const defaultErrorMsg = computed(() => t("upload.defaultErrorMsg"));
|
||||
const urlErrorMsg = computed(() => t("upload.urlErrorMsg"));
|
||||
const numberErrorMsg = computed(() => t("upload.numberErrorMsg"));
|
||||
|
@ -13,8 +13,7 @@
|
||||
::: demo 使用 `lay-input-number` 标签, 创建数字输入框
|
||||
|
||||
<template>
|
||||
{{data1}}
|
||||
<lay-input-number v-model="data1" :step="0.1"></lay-input-number>
|
||||
<lay-input-number v-model="data1" :step="0.11"></lay-input-number>
|
||||
<lay-input-number v-model="data2" position="right"></lay-input-number>
|
||||
</template>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user