validateAction.ts 644 B

12345678910111213141516171819202122
  1. import { ValidateErrorEntity } from "ant-design-vue/lib/form/interface";
  2. import { Ref, toRaw, UnwrapRef } from "vue";
  3. /**
  4. * 表单验证
  5. * @param formRef
  6. * @param formState
  7. * @returns
  8. */
  9. export function validateAction<T>(formRef: Ref<any>, formState: UnwrapRef<T>): Promise<T> {
  10. return formRef.value
  11. .validate()
  12. .then(() => {
  13. const param = toRaw(formState);
  14. console.log('请求参数:', param);
  15. return param
  16. })
  17. .catch((error: ValidateErrorEntity<T>) => {
  18. console.error('表单验证错误:', error);
  19. Promise.reject(error)
  20. });
  21. }