输入逻辑优化

This commit is contained in:
2026-04-16 14:40:57 +08:00
parent 70dacc1652
commit bd0b41550d
10 changed files with 57 additions and 20 deletions

View File

@@ -98,6 +98,7 @@
val1: '',
bagCode: '',
num: null,
// dataList: [{qty:'33.666'}, {qty: '12.34'}],
dataList: [],
disabled: false
};
@@ -127,8 +128,12 @@
if (e.qty < 0) {
e.qty = 0
} else {
e.qty = e.qty.replace(/[^0-9]/g, '')
e.qty = e.qty.replace(/^0+/, '') || '0'
e.qty = String(e.qty ?? '').replace(/[^0-9.]/g, '') // 仅保留数字和点
.replace(/^\./, '0.') // 以点开头补零
.replace(/\.+/g, '.') // 多个点合并为一个
.replace(/^0+(\d)/, '$1') // 去掉整数部分前导零(保留一位)
.replace(/(\.\d{3})\d*/, '$1'); // 小数最多三位
e.qty = e.qty === '' || e.qty === '.' ? '0' : e.qty; // 处理空或仅点的情况
if (e.qty > e.initialQty) {
e.qty = e.initialQty
}