mirror of
https://gitee.com/vant-contrib/vant-weapp.git
synced 2025-04-06 03:58:05 +08:00
fix(Stepper): can't work when step is decimal (#2142)
This commit is contained in:
parent
f7379bb6b4
commit
a01f966dea
@ -5,6 +5,12 @@ import { addUnit, isDef } from '../common/utils';
|
|||||||
const LONG_PRESS_START_TIME = 600;
|
const LONG_PRESS_START_TIME = 600;
|
||||||
const LONG_PRESS_INTERVAL = 200;
|
const LONG_PRESS_INTERVAL = 200;
|
||||||
|
|
||||||
|
// add num and avoid float number
|
||||||
|
function add(num1: number, num2: number): number {
|
||||||
|
const cardinal = 10 ** 10;
|
||||||
|
return Math.round((num1 + num2) * cardinal) / cardinal;
|
||||||
|
}
|
||||||
|
|
||||||
VantComponent({
|
VantComponent({
|
||||||
field: true,
|
field: true,
|
||||||
|
|
||||||
@ -18,7 +24,10 @@ VantComponent({
|
|||||||
buttonSize: null,
|
buttonSize: null,
|
||||||
asyncChange: Boolean,
|
asyncChange: Boolean,
|
||||||
disableInput: Boolean,
|
disableInput: Boolean,
|
||||||
decimalLength: Number,
|
decimalLength: {
|
||||||
|
type: Number,
|
||||||
|
value: null
|
||||||
|
},
|
||||||
min: {
|
min: {
|
||||||
type: null,
|
type: null,
|
||||||
value: 1
|
value: 1
|
||||||
@ -128,12 +137,7 @@ VantComponent({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const diff = type === 'minus' ? -this.data.step : +this.data.step;
|
const diff = type === 'minus' ? -this.data.step : +this.data.step;
|
||||||
|
const value = add(+this.data.value, diff);
|
||||||
let value = +this.data.value + diff;
|
|
||||||
|
|
||||||
if (!isDef(this.data.decimalLength)) {
|
|
||||||
value = Math.round(value * 100) / 100;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.triggerInput(this.range(value));
|
this.triggerInput(this.range(value));
|
||||||
this.$emit(type);
|
this.$emit(type);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user