From aaebe4f6061dcc03d725e6eb67cddfc9d4144e8a 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: Tue, 8 Nov 2022 23:09:56 +0800
Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B(component):=20=E4=BF=AE=E5=A4=8D?=
=?UTF-8?q?=20input-number=20=E7=BB=84=E4=BB=B6=E7=BB=8F=E5=BA=A6=E4=B8=A2?=
=?UTF-8?q?=E5=A4=B1?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../src/component/inputNumber/index.vue | 5 +++--
.../src/component/inputNumber/math.ts | 21 +++++++++++++++++++
.../document/zh-CN/components/inputNumber.md | 2 +-
.../src/document/zh-CN/guide/changelog.md | 2 +-
4 files changed, 26 insertions(+), 4 deletions(-)
create mode 100644 package/component/src/component/inputNumber/math.ts
diff --git a/package/component/src/component/inputNumber/index.vue b/package/component/src/component/inputNumber/index.vue
index ebd76955..2e125629 100644
--- a/package/component/src/component/inputNumber/index.vue
+++ b/package/component/src/component/inputNumber/index.vue
@@ -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) {
diff --git a/package/component/src/component/inputNumber/math.ts b/package/component/src/component/inputNumber/math.ts
new file mode 100644
index 00000000..4fbc61bd
--- /dev/null
+++ b/package/component/src/component/inputNumber/math.ts
@@ -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,
+}
\ No newline at end of file
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 5cd72561..a53a15bf 100644
--- a/package/document-component/src/document/zh-CN/components/inputNumber.md
+++ b/package/document-component/src/document/zh-CN/components/inputNumber.md
@@ -14,7 +14,7 @@
{{data1}}
-