|  | @@ -1,76 +1,76 @@
 | 
	
		
			
				|  |  | -import { RuleObject } from 'ant-design-vue/lib/form/interface'
 | 
	
		
			
				|  |  | -import { ref, computed, unref, Ref } from 'vue'
 | 
	
		
			
				|  |  | -import { useI18n } from '/@/hooks/web/useI18n'
 | 
	
		
			
				|  |  | +import { RuleObject } from 'ant-design-vue/lib/form/interface';
 | 
	
		
			
				|  |  | +import { ref, computed, unref, Ref } from 'vue';
 | 
	
		
			
				|  |  | +import { useI18n } from '/@/hooks/web/useI18n';
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  export enum LoginStateEnum {
 | 
	
		
			
				|  |  |    LOGIN,
 | 
	
		
			
				|  |  |    REGISTER,
 | 
	
		
			
				|  |  |    RESET_PASSWORD,
 | 
	
		
			
				|  |  |    MOBILE,
 | 
	
		
			
				|  |  | -  QR_CODE
 | 
	
		
			
				|  |  | +  QR_CODE,
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -const currentState = ref(LoginStateEnum.LOGIN)
 | 
	
		
			
				|  |  | +const currentState = ref(LoginStateEnum.LOGIN);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  export function useLoginState() {
 | 
	
		
			
				|  |  |    function setLoginState(state: LoginStateEnum) {
 | 
	
		
			
				|  |  | -    currentState.value = state
 | 
	
		
			
				|  |  | +    currentState.value = state;
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -  const getLoginState = computed(() => currentState.value)
 | 
	
		
			
				|  |  | +  const getLoginState = computed(() => currentState.value);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |    function handleBackLogin() {
 | 
	
		
			
				|  |  | -    setLoginState(LoginStateEnum.LOGIN)
 | 
	
		
			
				|  |  | +    setLoginState(LoginStateEnum.LOGIN);
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -  return { setLoginState, getLoginState, handleBackLogin }
 | 
	
		
			
				|  |  | +  return { setLoginState, getLoginState, handleBackLogin };
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  export function useFormValid<T extends Object = any>(formRef: Ref<any>) {
 | 
	
		
			
				|  |  |    async function validForm() {
 | 
	
		
			
				|  |  | -    const form = unref(formRef)
 | 
	
		
			
				|  |  | -    if (!form) return
 | 
	
		
			
				|  |  | -    const data = await form.validate()
 | 
	
		
			
				|  |  | -    return data as T
 | 
	
		
			
				|  |  | +    const form = unref(formRef);
 | 
	
		
			
				|  |  | +    if (!form) return;
 | 
	
		
			
				|  |  | +    const data = await form.validate();
 | 
	
		
			
				|  |  | +    return data as T;
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -  return { validForm }
 | 
	
		
			
				|  |  | +  return { validForm };
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  export function useFormRules(formData?: Recordable) {
 | 
	
		
			
				|  |  | -  const { t } = useI18n()
 | 
	
		
			
				|  |  | +  const { t } = useI18n();
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -  const getAccountFormRule = computed(() => createRule(t('sys.login.accountPlaceholder')))
 | 
	
		
			
				|  |  | -  const getPasswordFormRule = computed(() => createRule(t('sys.login.passwordPlaceholder')))
 | 
	
		
			
				|  |  | -  const getSmsFormRule = computed(() => createRule(t('sys.login.smsPlaceholder')))
 | 
	
		
			
				|  |  | -  const getMobileFormRule = computed(() => createRule(t('sys.login.mobilePlaceholder')))
 | 
	
		
			
				|  |  | +  const getAccountFormRule = computed(() => createRule(t('sys.login.accountPlaceholder')));
 | 
	
		
			
				|  |  | +  const getPasswordFormRule = computed(() => createRule(t('sys.login.passwordPlaceholder')));
 | 
	
		
			
				|  |  | +  const getSmsFormRule = computed(() => createRule(t('sys.login.smsPlaceholder')));
 | 
	
		
			
				|  |  | +  const getMobileFormRule = computed(() => createRule(t('sys.login.mobilePlaceholder')));
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |    const validatePolicy = async (_: RuleObject, value: boolean) => {
 | 
	
		
			
				|  |  | -    return !value ? Promise.reject(t('sys.login.policyPlaceholder')) : Promise.resolve()
 | 
	
		
			
				|  |  | -  }
 | 
	
		
			
				|  |  | +    return !value ? Promise.reject(t('sys.login.policyPlaceholder')) : Promise.resolve();
 | 
	
		
			
				|  |  | +  };
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |    const validateConfirmPassword = (password: string) => {
 | 
	
		
			
				|  |  |      return async (_: RuleObject, value: string) => {
 | 
	
		
			
				|  |  |        if (!value) {
 | 
	
		
			
				|  |  | -        return Promise.reject(t('sys.login.passwordPlaceholder'))
 | 
	
		
			
				|  |  | +        return Promise.reject(t('sys.login.passwordPlaceholder'));
 | 
	
		
			
				|  |  |        }
 | 
	
		
			
				|  |  |        if (value !== password) {
 | 
	
		
			
				|  |  | -        return Promise.reject(t('sys.login.diffPwd'))
 | 
	
		
			
				|  |  | +        return Promise.reject(t('sys.login.diffPwd'));
 | 
	
		
			
				|  |  |        }
 | 
	
		
			
				|  |  | -      return Promise.resolve()
 | 
	
		
			
				|  |  | -    }
 | 
	
		
			
				|  |  | -  }
 | 
	
		
			
				|  |  | +      return Promise.resolve();
 | 
	
		
			
				|  |  | +    };
 | 
	
		
			
				|  |  | +  };
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |    const getFormRules = computed(() => {
 | 
	
		
			
				|  |  | -    const accountFormRule = unref(getAccountFormRule)
 | 
	
		
			
				|  |  | -    const passwordFormRule = unref(getPasswordFormRule)
 | 
	
		
			
				|  |  | -    const smsFormRule = unref(getSmsFormRule)
 | 
	
		
			
				|  |  | -    const mobileFormRule = unref(getMobileFormRule)
 | 
	
		
			
				|  |  | +    const accountFormRule = unref(getAccountFormRule);
 | 
	
		
			
				|  |  | +    const passwordFormRule = unref(getPasswordFormRule);
 | 
	
		
			
				|  |  | +    const smsFormRule = unref(getSmsFormRule);
 | 
	
		
			
				|  |  | +    const mobileFormRule = unref(getMobileFormRule);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      const mobileRule = {
 | 
	
		
			
				|  |  |        sms: smsFormRule,
 | 
	
		
			
				|  |  | -      mobile: mobileFormRule
 | 
	
		
			
				|  |  | -    }
 | 
	
		
			
				|  |  | +      mobile: mobileFormRule,
 | 
	
		
			
				|  |  | +    };
 | 
	
		
			
				|  |  |      switch (unref(currentState)) {
 | 
	
		
			
				|  |  |        // register form rules
 | 
	
		
			
				|  |  |        case LoginStateEnum.REGISTER:
 | 
	
	
		
			
				|  | @@ -78,32 +78,32 @@ export function useFormRules(formData?: Recordable) {
 | 
	
		
			
				|  |  |            account: accountFormRule,
 | 
	
		
			
				|  |  |            password: passwordFormRule,
 | 
	
		
			
				|  |  |            confirmPassword: [
 | 
	
		
			
				|  |  | -            { validator: validateConfirmPassword(formData?.password), trigger: 'change' }
 | 
	
		
			
				|  |  | +            { validator: validateConfirmPassword(formData?.password), trigger: 'change' },
 | 
	
		
			
				|  |  |            ],
 | 
	
		
			
				|  |  |            policy: [{ validator: validatePolicy, trigger: 'change' }],
 | 
	
		
			
				|  |  | -          ...mobileRule
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | +          ...mobileRule,
 | 
	
		
			
				|  |  | +        };
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |        // reset password form rules
 | 
	
		
			
				|  |  |        case LoginStateEnum.RESET_PASSWORD:
 | 
	
		
			
				|  |  |          return {
 | 
	
		
			
				|  |  |            account: accountFormRule,
 | 
	
		
			
				|  |  | -          ...mobileRule
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | +          ...mobileRule,
 | 
	
		
			
				|  |  | +        };
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |        // mobile form rules
 | 
	
		
			
				|  |  |        case LoginStateEnum.MOBILE:
 | 
	
		
			
				|  |  | -        return mobileRule
 | 
	
		
			
				|  |  | +        return mobileRule;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |        // login form rules
 | 
	
		
			
				|  |  |        default:
 | 
	
		
			
				|  |  |          return {
 | 
	
		
			
				|  |  |            account: accountFormRule,
 | 
	
		
			
				|  |  | -          password: passwordFormRule
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | +          password: passwordFormRule,
 | 
	
		
			
				|  |  | +        };
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  | -  })
 | 
	
		
			
				|  |  | -  return { getFormRules }
 | 
	
		
			
				|  |  | +  });
 | 
	
		
			
				|  |  | +  return { getFormRules };
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  function createRule(message: string) {
 | 
	
	
		
			
				|  | @@ -111,7 +111,7 @@ function createRule(message: string) {
 | 
	
		
			
				|  |  |      {
 | 
	
		
			
				|  |  |        required: true,
 | 
	
		
			
				|  |  |        message,
 | 
	
		
			
				|  |  | -      trigger: 'change'
 | 
	
		
			
				|  |  | -    }
 | 
	
		
			
				|  |  | -  ]
 | 
	
		
			
				|  |  | +      trigger: 'change',
 | 
	
		
			
				|  |  | +    },
 | 
	
		
			
				|  |  | +  ];
 | 
	
		
			
				|  |  |  }
 |