优化组件页面代码
This commit is contained in:
@@ -35,9 +35,12 @@ import type { ProductDiscount } from "@/models/product_discount"
|
||||
// 表单验证规则
|
||||
const addUserSchema = z
|
||||
.object({
|
||||
username: z.string().min(1, "账号不能为空"),
|
||||
password: z.string().min(6, "密码至少6位"),
|
||||
confirmPassword: z.string().min(1, "请确认密码"),
|
||||
username: z.string().optional(),
|
||||
password: z
|
||||
.string()
|
||||
.optional()
|
||||
.refine(val => !val || val.length >= 6, { message: "密码至少6位" }),
|
||||
confirmPassword: z.string().optional(),
|
||||
phone: z.string().regex(/^1[3-9]\d{9}$/, "请输入正确的手机号格式"),
|
||||
email: z
|
||||
.string()
|
||||
@@ -53,10 +56,18 @@ const addUserSchema = z
|
||||
contact_qq: z.string().optional(),
|
||||
contact_wechat: z.string().optional(),
|
||||
})
|
||||
.refine(data => data.password === data.confirmPassword, {
|
||||
message: "两次输入的密码不一致",
|
||||
path: ["confirmPassword"],
|
||||
})
|
||||
.refine(
|
||||
data => {
|
||||
if (data.password) {
|
||||
return data.password === data.confirmPassword
|
||||
}
|
||||
return true
|
||||
},
|
||||
{
|
||||
message: "两次输入的密码不一致",
|
||||
path: ["confirmPassword"],
|
||||
},
|
||||
)
|
||||
|
||||
export type AddUserFormValues = z.infer<typeof addUserSchema>
|
||||
|
||||
@@ -147,9 +158,9 @@ export function AddUserDialog({
|
||||
|
||||
const onSubmit = handleSubmit(async data => {
|
||||
const payload = {
|
||||
username: data.username,
|
||||
password: data?.password,
|
||||
phone: data.phone,
|
||||
username: data?.username,
|
||||
password: data?.password,
|
||||
email: data?.email || "",
|
||||
name: data?.name,
|
||||
admin_id: data.admin_id ? Number(data.admin_id) : undefined,
|
||||
@@ -228,7 +239,10 @@ export function AddUserDialog({
|
||||
control={control}
|
||||
render={({ field, fieldState }) => (
|
||||
<Field data-invalid={fieldState.invalid}>
|
||||
<FieldLabel>用户密码</FieldLabel>
|
||||
<FieldLabel>
|
||||
用户密码
|
||||
<span className="text-gray-400 text-xs">(选填)</span>
|
||||
</FieldLabel>
|
||||
<Input
|
||||
{...field}
|
||||
type="password"
|
||||
|
||||
Reference in New Issue
Block a user