mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
fix(DatetimePicker): infinite loop when use formatted text is unnumeric (#4485)
This commit is contained in:
parent
2038d135bc
commit
31ceba6c38
@ -129,14 +129,18 @@ export default createComponent({
|
|||||||
},
|
},
|
||||||
|
|
||||||
onChange(picker) {
|
onChange(picker) {
|
||||||
const values = picker.getValues();
|
const indexes = picker.getIndexes();
|
||||||
const year = getTrueValue(values[0]);
|
const getValue = index => getTrueValue(this.originColumns[index].values[indexes[index]]);
|
||||||
const month = getTrueValue(values[1]);
|
|
||||||
|
const year = getValue(0);
|
||||||
|
const month = getValue(1);
|
||||||
const maxDate = getMonthEndDay(year, month);
|
const maxDate = getMonthEndDay(year, month);
|
||||||
|
|
||||||
let date = getTrueValue(values[2]);
|
let date;
|
||||||
if (this.type === 'year-month') {
|
if (this.type === 'year-month') {
|
||||||
date = 1;
|
date = 1;
|
||||||
|
} else {
|
||||||
|
date = getValue(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
date = date > maxDate ? maxDate : date;
|
date = date > maxDate ? maxDate : date;
|
||||||
@ -145,8 +149,8 @@ export default createComponent({
|
|||||||
let minute = 0;
|
let minute = 0;
|
||||||
|
|
||||||
if (this.type === 'datetime') {
|
if (this.type === 'datetime') {
|
||||||
hour = getTrueValue(values[3]);
|
hour = getValue(3);
|
||||||
minute = getTrueValue(values[4]);
|
minute = getValue(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
const value = new Date(year, month - 1, date, hour, minute);
|
const value = new Date(year, month - 1, date, hour, minute);
|
||||||
|
@ -17,7 +17,11 @@ export function getTrueValue(value: string | undefined): number | undefined {
|
|||||||
}
|
}
|
||||||
|
|
||||||
while (isNaN(parseInt(value, 10))) {
|
while (isNaN(parseInt(value, 10))) {
|
||||||
value = value.slice(1);
|
if (value.length > 1) {
|
||||||
|
value = value.slice(1);
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return parseInt(value, 10);
|
return parseInt(value, 10);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user