fix: 金额编辑器小数位溢出挤位 + 编辑页自动聚焦 + 周期账单移除冗余聚焦

This commit is contained in:
2026-06-09 16:54:13 +08:00
parent 6b26951b1b
commit f586f9e117
3 changed files with 13 additions and 4 deletions

View File

@@ -48,9 +48,19 @@ export function insertAmountKey(
} }
const normalizedInsert = normalizeInsert(value, safeCursor, key) 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)) { 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 } return { value, cursorIndex: safeCursor, accepted: false }
} }

View File

@@ -195,6 +195,7 @@ onMounted(async () => {
// 等待分类列表渲染完成后滚动到选中项 // 等待分类列表渲染完成后滚动到选中项
nextTick(() => { nextTick(() => {
setTimeout(() => { scrollToCat.value = 'cat-' + existing.category_id }, 200) setTimeout(() => { scrollToCat.value = 'cat-' + existing.category_id }, 200)
amountEditorRef.value?.focus()
}) })
} else { } else {
uni.showToast({ title: '记录不存在', icon: 'none' }) uni.showToast({ title: '记录不存在', icon: 'none' })

View File

@@ -153,7 +153,7 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ref, computed, onMounted, nextTick } from 'vue' import { ref, computed, onMounted } from 'vue'
import { waitForReady } from '@/utils/app-ready' import { waitForReady } from '@/utils/app-ready'
import { statusBarHeight, capsuleRight } from '@/utils/system' import { statusBarHeight, capsuleRight } from '@/utils/system'
import { formatAmount } from '@/utils/format' import { formatAmount } from '@/utils/format'
@@ -233,7 +233,6 @@ function openAddModal() {
if (cats.length > 0) form.value.category_id = cats[0].id if (cats.length > 0) form.value.category_id = cats[0].id
amountStr.value = '' amountStr.value = ''
showModal.value = true showModal.value = true
nextTick(() => amountEditorRef.value?.focus())
} }
function openEditModal(item: RecurringTemplate) { function openEditModal(item: RecurringTemplate) {
@@ -248,7 +247,6 @@ function openEditModal(item: RecurringTemplate) {
} }
amountStr.value = (item.amount / 100).toString() amountStr.value = (item.amount / 100).toString()
showModal.value = true showModal.value = true
nextTick(() => amountEditorRef.value?.focus())
} }
async function toggleActive(item: RecurringTemplate) { async function toggleActive(item: RecurringTemplate) {