提交 | 用户 | 时间
|
820397
|
1 |
<template> |
H |
2 |
<Form |
|
3 |
v-show="getShow" |
|
4 |
:rules="rules" |
|
5 |
:schema="schema" |
|
6 |
class="dark:(border-1 border-[var(--el-border-color)] border-solid)" |
|
7 |
hide-required-asterisk |
|
8 |
label-position="top" |
|
9 |
size="large" |
|
10 |
@register="register" |
|
11 |
> |
|
12 |
<template #title> |
|
13 |
<LoginFormTitle style="width: 100%" /> |
|
14 |
</template> |
|
15 |
|
|
16 |
<template #code="form"> |
|
17 |
<div class="w-[100%] flex"> |
|
18 |
<el-input v-model="form['code']" :placeholder="t('login.codePlaceholder')" /> |
|
19 |
</div> |
|
20 |
</template> |
|
21 |
|
|
22 |
<template #register> |
|
23 |
<div class="w-[100%]"> |
|
24 |
<XButton |
|
25 |
:loading="loading" |
|
26 |
:title="t('login.register')" |
|
27 |
class="w-[100%]" |
|
28 |
type="primary" |
|
29 |
@click="loginRegister()" |
|
30 |
/> |
|
31 |
</div> |
|
32 |
<div class="mt-15px w-[100%]"> |
|
33 |
<XButton :title="t('login.hasUser')" class="w-[100%]" @click="handleBackLogin()" /> |
|
34 |
</div> |
|
35 |
</template> |
|
36 |
</Form> |
|
37 |
</template> |
|
38 |
<script lang="ts" setup> |
|
39 |
import type { FormRules } from 'element-plus' |
|
40 |
|
|
41 |
import { useForm } from '@/hooks/web/useForm' |
|
42 |
import { useValidator } from '@/hooks/web/useValidator' |
|
43 |
import LoginFormTitle from './LoginFormTitle.vue' |
|
44 |
import { LoginStateEnum, useLoginState } from './useLogin' |
|
45 |
import { FormSchema } from '@/types/form' |
|
46 |
|
|
47 |
defineOptions({ name: 'RegisterForm' }) |
|
48 |
|
|
49 |
const { t } = useI18n() |
|
50 |
const { required } = useValidator() |
|
51 |
const { register, elFormRef } = useForm() |
|
52 |
const { handleBackLogin, getLoginState } = useLoginState() |
|
53 |
const getShow = computed(() => unref(getLoginState) === LoginStateEnum.REGISTER) |
|
54 |
|
|
55 |
const schema = reactive<FormSchema[]>([ |
|
56 |
{ |
|
57 |
field: 'title', |
|
58 |
colProps: { |
|
59 |
span: 24 |
|
60 |
} |
|
61 |
}, |
|
62 |
{ |
|
63 |
field: 'username', |
|
64 |
label: t('login.username'), |
|
65 |
value: '', |
|
66 |
component: 'Input', |
|
67 |
colProps: { |
|
68 |
span: 24 |
|
69 |
}, |
|
70 |
componentProps: { |
|
71 |
placeholder: t('login.usernamePlaceholder') |
|
72 |
} |
|
73 |
}, |
|
74 |
{ |
|
75 |
field: 'password', |
|
76 |
label: t('login.password'), |
|
77 |
value: '', |
|
78 |
component: 'InputPassword', |
|
79 |
colProps: { |
|
80 |
span: 24 |
|
81 |
}, |
|
82 |
componentProps: { |
|
83 |
style: { |
|
84 |
width: '100%' |
|
85 |
}, |
|
86 |
strength: true, |
|
87 |
placeholder: t('login.passwordPlaceholder') |
|
88 |
} |
|
89 |
}, |
|
90 |
{ |
|
91 |
field: 'check_password', |
|
92 |
label: t('login.checkPassword'), |
|
93 |
value: '', |
|
94 |
component: 'InputPassword', |
|
95 |
colProps: { |
|
96 |
span: 24 |
|
97 |
}, |
|
98 |
componentProps: { |
|
99 |
style: { |
|
100 |
width: '100%' |
|
101 |
}, |
|
102 |
strength: true, |
|
103 |
placeholder: t('login.passwordPlaceholder') |
|
104 |
} |
|
105 |
}, |
|
106 |
{ |
|
107 |
field: 'code', |
|
108 |
label: t('login.code'), |
|
109 |
colProps: { |
|
110 |
span: 24 |
|
111 |
} |
|
112 |
}, |
|
113 |
{ |
|
114 |
field: 'register', |
|
115 |
colProps: { |
|
116 |
span: 24 |
|
117 |
} |
|
118 |
} |
|
119 |
]) |
|
120 |
|
|
121 |
const rules: FormRules = { |
|
122 |
username: [required()], |
|
123 |
password: [required()], |
|
124 |
check_password: [required()], |
|
125 |
code: [required()] |
|
126 |
} |
|
127 |
|
|
128 |
const loading = ref(false) |
|
129 |
|
|
130 |
const loginRegister = async () => { |
|
131 |
const formRef = unref(elFormRef) |
|
132 |
formRef?.validate(async (valid) => { |
|
133 |
if (valid) { |
|
134 |
try { |
|
135 |
loading.value = true |
|
136 |
} finally { |
|
137 |
loading.value = false |
|
138 |
} |
|
139 |
} |
|
140 |
}) |
|
141 |
} |
|
142 |
</script> |