提交 | 用户 | 时间
|
314507
|
1 |
import { Ref } from 'vue' |
H |
2 |
|
|
3 |
export enum LoginStateEnum { |
|
4 |
LOGIN, |
|
5 |
REGISTER, |
|
6 |
RESET_PASSWORD, |
|
7 |
MOBILE, |
|
8 |
QR_CODE, |
|
9 |
SSO |
|
10 |
} |
|
11 |
|
|
12 |
const currentState = ref(LoginStateEnum.LOGIN) |
|
13 |
|
|
14 |
export function useLoginState() { |
|
15 |
function setLoginState(state: LoginStateEnum) { |
|
16 |
currentState.value = state |
|
17 |
} |
|
18 |
const getLoginState = computed(() => currentState.value) |
|
19 |
|
|
20 |
function handleBackLogin() { |
|
21 |
setLoginState(LoginStateEnum.LOGIN) |
|
22 |
} |
|
23 |
|
|
24 |
return { |
|
25 |
setLoginState, |
|
26 |
getLoginState, |
|
27 |
handleBackLogin |
|
28 |
} |
|
29 |
} |
|
30 |
|
|
31 |
export function useFormValid<T extends Object = any>(formRef: Ref<any>) { |
|
32 |
async function validForm() { |
|
33 |
const form = unref(formRef) |
|
34 |
if (!form) return |
|
35 |
const data = await form.validate() |
|
36 |
return data as T |
|
37 |
} |
|
38 |
|
|
39 |
return { |
|
40 |
validForm |
|
41 |
} |
|
42 |
} |