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) { const {handleSubmit, handleReset} = useForm({ 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}; }