Commit a4a5a44009a5c8738e29560989f6eb1d51dfde84

Authored by luocong2016
Committed by GitHub
1 parent c5b39f2c

feat<useLogin>: original Form.validate (#2535)

src/views/sys/login/useLogin.ts
1 -import type { ValidationRule } from 'ant-design-vue/lib/form/Form';  
2 -import type { RuleObject } from 'ant-design-vue/lib/form/interface'; 1 +import type { ValidationRule, FormInstance } from 'ant-design-vue/lib/form/Form';
  2 +import type { RuleObject, NamePath } from 'ant-design-vue/lib/form/interface';
3 import { ref, computed, unref, Ref } from 'vue'; 3 import { ref, computed, unref, Ref } from 'vue';
4 import { useI18n } from '/@/hooks/web/useI18n'; 4 import { useI18n } from '/@/hooks/web/useI18n';
5 5
@@ -27,7 +27,12 @@ export function useLoginState() { @@ -27,7 +27,12 @@ export function useLoginState() {
27 return { setLoginState, getLoginState, handleBackLogin }; 27 return { setLoginState, getLoginState, handleBackLogin };
28 } 28 }
29 29
30 -export function useFormValid<T extends Object = any>(formRef: Ref<any>) { 30 +export function useFormValid<T extends Object = any>(formRef: Ref<FormInstance>) {
  31 + const validate = computed(() => {
  32 + const form = unref(formRef);
  33 + return form?.validate ?? ((_nameList?: NamePath) => Promise.resolve());
  34 + });
  35 +
31 async function validForm() { 36 async function validForm() {
32 const form = unref(formRef); 37 const form = unref(formRef);
33 if (!form) return; 38 if (!form) return;
@@ -35,7 +40,7 @@ export function useFormValid&lt;T extends Object = any&gt;(formRef: Ref&lt;any&gt;) { @@ -35,7 +40,7 @@ export function useFormValid&lt;T extends Object = any&gt;(formRef: Ref&lt;any&gt;) {
35 return data as T; 40 return data as T;
36 } 41 }
37 42
38 - return { validForm }; 43 + return { validate, validForm };
39 } 44 }
40 45
41 export function useFormRules(formData?: Recordable) { 46 export function useFormRules(formData?: Recordable) {