diff --git a/client/src/components/AmountEditor/amount-edit.ts b/client/src/components/AmountEditor/amount-edit.ts index 6e085d9..24ffda7 100644 --- a/client/src/components/AmountEditor/amount-edit.ts +++ b/client/src/components/AmountEditor/amount-edit.ts @@ -48,9 +48,19 @@ export function insertAmountKey( } const normalizedInsert = normalizeInsert(value, safeCursor, key) - const next = value.slice(0, safeCursor) + normalizedInsert + value.slice(safeCursor) + let next = value.slice(0, safeCursor) + normalizedInsert + value.slice(safeCursor) if (!isValidAmountInput(next, options)) { + // 小数位超出上限时,从右侧挤出一个字符(小数部分左移) + const dotIdx = next.indexOf('.') + if (dotIdx >= 0 && next.length - dotIdx - 1 > MAX_DECIMAL_PLACES) { + next = next.slice(0, -1) + const newCursor = Math.min(safeCursor + normalizedInsert.length, next.length) + if (!isValidAmountInput(next, options)) { + return { value, cursorIndex: safeCursor, accepted: false } + } + return { value: next, cursorIndex: newCursor, accepted: true } + } return { value, cursorIndex: safeCursor, accepted: false } } diff --git a/client/src/pages/add/index.vue b/client/src/pages/add/index.vue index 7c64974..2b5dd0f 100644 --- a/client/src/pages/add/index.vue +++ b/client/src/pages/add/index.vue @@ -195,6 +195,7 @@ onMounted(async () => { // 等待分类列表渲染完成后滚动到选中项 nextTick(() => { setTimeout(() => { scrollToCat.value = 'cat-' + existing.category_id }, 200) + amountEditorRef.value?.focus() }) } else { uni.showToast({ title: '记录不存在', icon: 'none' }) diff --git a/client/src/pages/recurring/index.vue b/client/src/pages/recurring/index.vue index 9c9e10b..9b66678 100644 --- a/client/src/pages/recurring/index.vue +++ b/client/src/pages/recurring/index.vue @@ -153,7 +153,7 @@