新增余额明细页面,修复页面useId不更新的问题

This commit is contained in:
Eamon
2026-04-11 14:57:45 +08:00
parent 790180a847
commit ed95f0520d
23 changed files with 780 additions and 215 deletions

View File

@@ -22,9 +22,9 @@ import type { User } from "@/models/user"
const Schema = z.object({
deduction: z
.string()
.min(1, "请输入额")
.min(1, "请输入扣款金额")
.refine(val => !Number.isNaN(Number(val)), "请输入有效的数字")
.refine(val => Number(val) >= 0, "额不能为负数"),
.refine(val => Number(val) >= 0, "额不能为负数"),
})
type FormValues = z.infer<typeof Schema>
@@ -95,7 +95,7 @@ export function DeductionDialog({
<DialogHeader>
<DialogTitle></DialogTitle>
<DialogDescription>
{currentUser?.name || currentUser?.username}
{currentUser?.name || currentUser?.username}
</DialogDescription>
</DialogHeader>
@@ -104,30 +104,20 @@ export function DeductionDialog({
<Field data-invalid={!!errors.deduction}>
<FieldLabel></FieldLabel>
<Input
type="number"
step="0.01"
min="0"
type="text"
placeholder="请输入扣款金额"
{...register("deduction", {
setValueAs: value => {
if (!value) return ""
const num = Number(value)
if (Number.isNaN(num)) return value
return num.toFixed(2)
},
})}
{...register("deduction")}
onInput={(e: React.ChangeEvent<HTMLInputElement>) => {
let value = e.target.value
if (value.startsWith("-")) {
value = value.replace("-", "")
value = value.replace(/[^\d.]/g, "")
const dotCount = (value.match(/\./g) || []).length
if (dotCount > 1) {
value = value.slice(0, value.lastIndexOf("."))
}
if (value.includes(".")) {
const parts = value.split(".")
if (parts[1] && parts[1].length > 2) {
value = `${parts[0]}.${parts[1].slice(0, 2)}`
}
const [int, dec] = value.split(".")
value = `${int}.${dec.slice(0, 2)}`
}
setValue("deduction", value)
}}
/>