From 37c22e4f42969b19d35153f962fbc8f828635ef1 Mon Sep 17 00:00:00 2001 From: dap <15891557205@163.com> Date: Sun, 6 Oct 2024 09:35:53 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=A0=A1=E9=AA=8C=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/web-antd/src/views/system/user/data.tsx | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/apps/web-antd/src/views/system/user/data.tsx b/apps/web-antd/src/views/system/user/data.tsx index 5251f14d..f1911255 100644 --- a/apps/web-antd/src/views/system/user/data.tsx +++ b/apps/web-antd/src/views/system/user/data.tsx @@ -128,15 +128,21 @@ export const drawerSchema: FormSchemaGetter = () => [ rules: z .string() .regex(/^1[3-9]\d{9}$/, '请输入正确的手机号码') - .optional(), + .optional() + .or(z.literal('')), }, { component: 'Input', fieldName: 'email', defaultValue: undefined, label: '邮箱', - // TODO: 这里非必填未生效 - rules: z.string().email('请输入正确的邮箱').optional(), + /** + * z.literal 是 Zod 中的一种类型,用于定义一个特定的字面量值。 + * 它可以用于确保输入的值与指定的字面量完全匹配。 + * 例如,你可以使用 z.literal 来确保某个字段的值只能是特定的字符串、数字、布尔值等。 + * 即空字符串也可通过校验 + */ + rules: z.string().email('请输入正确的邮箱').optional().or(z.literal('')), }, { component: 'RadioGroup',