fix:键盘输入bug

This commit is contained in:
houjunxiang
2025-12-04 10:15:32 +08:00
parent 182fd11399
commit 4d1e709be9

View File

@@ -81,8 +81,22 @@ const jianshao = () => {
}
const changeNums = (item, index) => {
if (item.text === '.') {
if (nums.value.indexOf('.') !== -1 || nums.value.length === 0) {
const inputChar = item.text
// 处理负号 '-'
if (inputChar === '-') {
// 只允许在输入为空时输入负号(即只能作为第一个字符)
if (nums.value === '') {
nums.value = '-'
}
return // 无论是否成功,都不继续处理
}
if (inputChar === '.') {
// 不能以 '.' 开头(除非已有负号)
if (nums.value === '' || nums.value === '-') {
return false
}
// 已存在小数点则不允许再输入
if (nums.value.indexOf('.') !== -1) {
return false
}
}
@@ -96,7 +110,7 @@ const changeNums = (item, index) => {
}
}
nums.value += item.text
nums.value += inputChar
}
const getListItemStyle = index => {