Browse Source

update: role增加校验

xyh 2 năm trước cách đây
mục cha
commit
2fc7f5946b

+ 7 - 1
packages/app/src/pages/role/table/modal/Info.tsx

@@ -14,7 +14,13 @@ const ModalInfo: FC<Props> = function({id}) {
   return (
     <>
       <LDModalInput name="roleName" control={control} label="角色名称" />
-      <LDModalArea name="roleNote" control={control} label="角色备注" height={160} />
+      <LDModalArea
+        name="roleNote"
+        control={control}
+        label="角色备注"
+        height={160}
+        required={false}
+      />
     </>
   );
 };

+ 8 - 0
packages/app/src/pages/role/table/modal/hooks.ts

@@ -1,8 +1,10 @@
 import {addRole, editRole, getRoleInfo} from '@apis';
+import {zodResolver} from '@hookform/resolvers/zod';
 import {usePutData, useQueryDataInfo} from '@hooks';
 import {AddRoleParams} from '@models';
 import {useEffect} from 'react';
 import {useForm, useFormContext} from 'react-hook-form';
+import {object, string} from 'zod';
 
 export type FormState = {
   roleName: string,
@@ -19,6 +21,12 @@ export function useFormState(
       roleName: '',
       roleNote: '',
     },
+    resolver: zodResolver(
+      object({
+        roleName: string({required_error: '请输入角色名称', invalid_type_error: '亲输入角色名称'})
+          .min(1, '请输入角色名称'),
+      }).passthrough(),
+    ),
   });
 
   const {handleSubmit, clearErrors} = formContext;