From cc1f6de1b53ba54fd0785eea09bb0d1b638a9f1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=B1=E7=9C=A0=E5=84=80=E5=BC=8F?= <854085467@qq.com> Date: Thu, 10 Nov 2022 09:10:18 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B(component):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=20input-number=20=E5=B0=8F=E6=95=B0=E7=B2=BE=E5=BA=A6=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/component/inputNumber/index.vue | 2 +- .../src/component/inputNumber/math.ts | 41 +++++++++++++++---- .../component/src/component/popper/index.vue | 5 ++- .../component/src/component/select/index.vue | 2 +- .../component/src/component/upload/index.vue | 8 +++- .../document/zh-CN/components/inputNumber.md | 3 +- 6 files changed, 46 insertions(+), 15 deletions(-) diff --git a/package/component/src/component/inputNumber/index.vue b/package/component/src/component/inputNumber/index.vue index 5d6d0c36..6279bf67 100644 --- a/package/component/src/component/inputNumber/index.vue +++ b/package/component/src/component/inputNumber/index.vue @@ -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) { diff --git a/package/component/src/component/inputNumber/math.ts b/package/component/src/component/inputNumber/math.ts index 945e2bcb..d2689a27 100644 --- a/package/component/src/component/inputNumber/math.ts +++ b/package/component/src/component/inputNumber/math.ts @@ -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 }; diff --git a/package/component/src/component/popper/index.vue b/package/component/src/component/popper/index.vue index 7a0722e6..c598672f 100644 --- a/package/component/src/component/popper/index.vue +++ b/package/component/src/component/popper/index.vue @@ -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(); }); diff --git a/package/component/src/component/select/index.vue b/package/component/src/component/select/index.vue index 7f1fc555..dc925d04 100644 --- a/package/component/src/component/select/index.vue +++ b/package/component/src/component/select/index.vue @@ -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; } diff --git a/package/component/src/component/upload/index.vue b/package/component/src/component/upload/index.vue index 5f9ad831..320a2dc9 100644 --- a/package/component/src/component/upload/index.vue +++ b/package/component/src/component/upload/index.vue @@ -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")); diff --git a/package/document-component/src/document/zh-CN/components/inputNumber.md b/package/document-component/src/document/zh-CN/components/inputNumber.md index a53a15bf..ca57253c 100644 --- a/package/document-component/src/document/zh-CN/components/inputNumber.md +++ b/package/document-component/src/document/zh-CN/components/inputNumber.md @@ -13,8 +13,7 @@ ::: demo 使用 `lay-input-number` 标签, 创建数字输入框