fix: 输入校验统一字符串防御(数字输入不再引发 trim 类型崩溃)

This commit is contained in:
root
2026-10-16 15:06:21 +08:00
parent dba22765a6
commit aaf8ea602c
8 changed files with 43 additions and 39 deletions
@@ -57,8 +57,9 @@ function computedCategory() {
}
function save() {
const v = Number(fAmount.value)
if (!fAmount.value.trim() || !isFinite(v) || v <= 0) {
const amountText = String(fAmount.value ?? '').trim()
const v = Number(amountText)
if (!amountText || !isFinite(v) || v <= 0) {
fError.value = '请填写大于 0 的金额'
return
}
@@ -72,7 +73,7 @@ function save() {
category: computedCategory(),
amount: Math.round(v * 100),
date: fDate.value,
note: fNote.value.trim(),
note: String(fNote.value ?? '').trim(),
reimbursable,
reimbursed: reimbursable && fReimbursed.value ? 1 : 0
})