This commit is contained in:
aihe 2024-12-13 01:13:49 +08:00
parent 0132881ab9
commit f20d60f69f

View File

@ -125,15 +125,23 @@
},
formatter(val) {
let newVal = val
if((this.type == 'number' || this._digit || this._maxNum) && (typeof val == 'string' && val)) {
newVal = Number(val) // 需要格式化输入框的格式
// 判断是否输入了数字
if(!isNaN(newVal)) {
if(this._digit) {
let reg = new RegExp(`^\\d*(\\.?\\d{0,${this._digit}})`, 'g')
newVal = val.match(reg)[0]
}
if(typeof this._maxNum != 'undefined') {
if(val > this._maxNum) {
if(newVal > Number(this._maxNum)) {
newVal = this._maxNum
}
}
} else {
newVal = ''
}
}
return newVal
}
}