新增余额明细页面,修复页面useId不更新的问题
This commit is contained in:
@@ -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)
|
||||
}}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user