fix:处理inputRange设置大数页面卡顿问题 (#8651)

This commit is contained in:
yujinghan 2023-11-07 19:10:41 +08:00 committed by GitHub
parent f9ef049796
commit e7f23c9859
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -383,11 +383,16 @@ export class Range extends React.Component<RangeItemProps, any> {
getStepValue(value: number, step: number) {
const surplus = value % step;
let result = 0;
let closeNum = Math.floor(value - (value % step));
// 余数 >= 步长一半 -> 向上取
// 余数 < 步长一半 -> 向下取
const _value = surplus >= step / 2 ? value : safeSub(value, step);
while (result <= _value) {
result = safeAdd(result, step);
if (step < 1 || result === 0 || result === closeNum) {
result = safeAdd(result, step);
} else {
result = closeNum;
}
}
return result;
}