123456789101112131415161718192021222324252627282930313233343536373839 |
- import {validateErrorTip} from '@utils';
- import {toTypedSchema} from '@vee-validate/zod';
- import {useForm} from 'vee-validate';
- import {Ref} from 'vue';
- import {object, string} from 'zod';
- type FormState = {
- enterprise: string;
- phone: string;
- idCardImage: string;
- licenseImage: string;
- };
- export function useFormState(isSuccess: Ref<boolean>) {
- const {handleSubmit, handleReset} = useForm<FormState>({
- initialValues: {
- enterprise: '',
- phone: '',
- idCardImage: '',
- licenseImage: '',
- },
- validationSchema: toTypedSchema(object({
- enterprise: string(validateErrorTip('register.errors.enterprise'))
- .min(1, 'register.errors.enterprise'),
- phone: string(validateErrorTip('register.errors.phone'))
- .min(1, 'register.errors.phone'),
- idCardImage: string(validateErrorTip('register.errors.idcard'))
- .min(1, 'register.errors.idcard'),
- licenseImage: string(validateErrorTip('register.errors.licenseImage'))
- .min(1, 'register.errors.licenseImage'),
- })),
- });
- const onSubmit = handleSubmit(function(value) {
- isSuccess.value = true;
- });
- return {onSubmit, handleReset};
- }
|