import { ValidateErrorEntity } from "ant-design-vue/lib/form/interface";
import { Ref, toRaw, UnwrapRef } from "vue";
/**
 * 表单验证
 * @param formRef
 * @param formState
 * @returns
 */
export function validateAction<T>(formRef: Ref<any>, formState: UnwrapRef<T>): Promise<T> {
    return formRef.value
        .validate()
        .then(() => {
            const param = toRaw(formState);
            return param;
        })
        .catch((error: ValidateErrorEntity<T>) => {
            console.error('表单验证错误：', error);
            throw new Error('表单验证错误：')
        });
}