From 3f3821e02f4efd8c5209de35a7ab841704d2d2ef Mon Sep 17 00:00:00 2001 From: Formula <84565335+Formulaaa@users.noreply.github.com> Date: Tue, 24 Oct 2023 18:37:23 +0800 Subject: [PATCH] =?UTF-8?q?fix(inputnumber):=20=E4=BF=AE=E5=A4=8D=E8=B6=85?= =?UTF-8?q?=E8=BF=87=20min,=20max=20=E8=8C=83=E5=9B=B4=E9=97=AE=E9=A2=98(#?= =?UTF-8?q?2606)=20(#2607)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/packages/__VUE/inputnumber/index.taro.vue | 12 +++++++----- src/packages/__VUE/inputnumber/index.vue | 12 +++++++----- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/packages/__VUE/inputnumber/index.taro.vue b/src/packages/__VUE/inputnumber/index.taro.vue index 64a8153e8a..271ce667cc 100644 --- a/src/packages/__VUE/inputnumber/index.taro.vue +++ b/src/packages/__VUE/inputnumber/index.taro.vue @@ -102,7 +102,7 @@ export default create({ const emitChange = (value: string | number, event: Event) => { let output_value: number | string = fixedDecimalPlaces(value); emit('update:modelValue', output_value, event); - emit('change', output_value, event); + if (Number(props.modelValue) !== Number(output_value)) emit('change', output_value, event); }; const addAllow = (value = Number(props.modelValue)): boolean => { return value < Number(props.max) && !props.disabled; @@ -112,19 +112,21 @@ export default create({ }; const reduce = (event: Event) => { emit('reduce', event); - if (reduceAllow()) { - let output_value = Number(props.modelValue) - Number(props.step); + let output_value = Number(props.modelValue) - Number(props.step); + if (reduceAllow() && output_value >= Number(props.min)) { emitChange(output_value, event); } else { + emitChange(Number(props.min), event); emit('overlimit', event, 'reduce'); } }; const add = (event: Event) => { emit('add', event); - if (addAllow()) { - let output_value = Number(props.modelValue) + Number(props.step); + let output_value = Number(props.modelValue) + Number(props.step); + if (addAllow() && output_value <= Number(props.max)) { emitChange(output_value, event); } else { + emitChange(Number(props.max), event); emit('overlimit', event, 'add'); } }; diff --git a/src/packages/__VUE/inputnumber/index.vue b/src/packages/__VUE/inputnumber/index.vue index 818de01545..f058c336fa 100644 --- a/src/packages/__VUE/inputnumber/index.vue +++ b/src/packages/__VUE/inputnumber/index.vue @@ -97,7 +97,7 @@ export default create({ const emitChange = (value: string | number, event: Event) => { let output_value: number | string = fixedDecimalPlaces(value); emit('update:modelValue', output_value, event); - emit('change', output_value, event); + if (Number(props.modelValue) !== Number(output_value)) emit('change', output_value, event); }; const addAllow = (value = Number(props.modelValue)): boolean => { return value < Number(props.max) && !props.disabled; @@ -107,19 +107,21 @@ export default create({ }; const reduce = (event: Event) => { emit('reduce', event); - if (reduceAllow()) { - let output_value = Number(props.modelValue) - Number(props.step); + let output_value = Number(props.modelValue) - Number(props.step); + if (reduceAllow() && output_value >= Number(props.min)) { emitChange(output_value, event); } else { + emitChange(Number(props.min), event); emit('overlimit', event, 'reduce'); } }; const add = (event: Event) => { emit('add', event); - if (addAllow()) { - let output_value = Number(props.modelValue) + Number(props.step); + let output_value = Number(props.modelValue) + Number(props.step); + if (addAllow() && output_value <= Number(props.max)) { emitChange(output_value, event); } else { + emitChange(Number(props.max), event); emit('overlimit', event, 'add'); } };