hooks.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import {validateErrorTip} from '@utils';
  2. import {toTypedSchema} from '@vee-validate/zod';
  3. import {useForm} from 'vee-validate';
  4. import {Ref} from 'vue';
  5. import {object, string} from 'zod';
  6. type FormState = {
  7. enterprise: string;
  8. phone: string;
  9. idCardImage: string;
  10. licenseImage: string;
  11. };
  12. export function useFormState(isSuccess: Ref<boolean>) {
  13. const {handleSubmit, handleReset} = useForm<FormState>({
  14. initialValues: {
  15. enterprise: '',
  16. phone: '',
  17. idCardImage: '',
  18. licenseImage: '',
  19. },
  20. validationSchema: toTypedSchema(object({
  21. enterprise: string(validateErrorTip('register.errors.enterprise'))
  22. .min(1, 'register.errors.enterprise'),
  23. phone: string(validateErrorTip('register.errors.phone'))
  24. .min(1, 'register.errors.phone'),
  25. idCardImage: string(validateErrorTip('register.errors.idcard'))
  26. .min(1, 'register.errors.idcard'),
  27. licenseImage: string(validateErrorTip('register.errors.licenseImage'))
  28. .min(1, 'register.errors.licenseImage'),
  29. })),
  30. });
  31. const onSubmit = handleSubmit(function(value) {
  32. isSuccess.value = true;
  33. });
  34. return {onSubmit, handleReset};
  35. }