|
1 | 1 | <script setup lang="ts">
|
| 2 | +import { computed, reactive } from 'vue'; |
2 | 3 | import { $t } from '@/locales';
|
3 | 4 | import { useRouterPush } from '@/hooks/common/router';
|
| 5 | +import { useFormRules, useNaiveForm } from '@/hooks/common/form'; |
| 6 | +import { useCaptcha } from '@/hooks/business/captcha'; |
4 | 7 |
|
5 | 8 | defineOptions({
|
6 | 9 | name: 'CodeLogin'
|
7 | 10 | });
|
8 | 11 |
|
9 | 12 | const { toggleLoginModule } = useRouterPush();
|
| 13 | +const { formRef, validate } = useNaiveForm(); |
| 14 | +const { label, isCounting, loading, getCaptcha } = useCaptcha(); |
| 15 | +
|
| 16 | +interface FormModel { |
| 17 | + phone: string; |
| 18 | + code: string; |
| 19 | + password: string; |
| 20 | + confirmPassword: string; |
| 21 | +} |
| 22 | +
|
| 23 | +const model: FormModel = reactive({ |
| 24 | + phone: '', |
| 25 | + code: '', |
| 26 | + password: '', |
| 27 | + confirmPassword: '' |
| 28 | +}); |
| 29 | +
|
| 30 | +const rules = computed<Record<keyof FormModel, App.Global.FormRule[]>>(() => { |
| 31 | + const { formRules, createConfirmPwdRule } = useFormRules(); |
| 32 | +
|
| 33 | + return { |
| 34 | + phone: formRules.phone, |
| 35 | + code: formRules.code, |
| 36 | + password: formRules.pwd, |
| 37 | + confirmPassword: createConfirmPwdRule(model.password) |
| 38 | + }; |
| 39 | +}); |
| 40 | +
|
| 41 | +async function handleSubmit() { |
| 42 | + await validate(); |
| 43 | + // request to register |
| 44 | + window.$message?.success($t('page.login.common.validateSuccess')); |
| 45 | +} |
10 | 46 | </script>
|
11 | 47 |
|
12 | 48 | <template>
|
13 |
| - <NForm size="large" :show-label="false"> |
14 |
| - <NFormItem> |
15 |
| - <NInput :placeholder="$t('page.login.common.phonePlaceholder')" /> |
| 49 | + <NForm ref="formRef" :model="model" :rules="rules" size="large" :show-label="false"> |
| 50 | + <NFormItem path="phone"> |
| 51 | + <NInput v-model:value="model.phone" :placeholder="$t('page.login.common.phonePlaceholder')" /> |
| 52 | + </NFormItem> |
| 53 | + <NFormItem path="code"> |
| 54 | + <div class="w-full flex-y-center gap-16px"> |
| 55 | + <NInput v-model:value="model.code" :placeholder="$t('page.login.common.codePlaceholder')" /> |
| 56 | + <NButton size="large" :disabled="isCounting" :loading="loading" @click="getCaptcha(model.phone)"> |
| 57 | + {{ label }} |
| 58 | + </NButton> |
| 59 | + </div> |
| 60 | + </NFormItem> |
| 61 | + <NFormItem path="password"> |
| 62 | + <NInput |
| 63 | + v-model:value="model.password" |
| 64 | + type="password" |
| 65 | + show-password-on="click" |
| 66 | + :placeholder="$t('page.login.common.passwordPlaceholder')" |
| 67 | + /> |
16 | 68 | </NFormItem>
|
17 |
| - <NFormItem> |
18 |
| - <NInput :placeholder="$t('page.login.common.codePlaceholder')" /> |
| 69 | + <NFormItem path="confirmPassword"> |
| 70 | + <NInput |
| 71 | + v-model:value="model.confirmPassword" |
| 72 | + type="password" |
| 73 | + show-password-on="click" |
| 74 | + :placeholder="$t('page.login.common.confirmPasswordPlaceholder')" |
| 75 | + /> |
19 | 76 | </NFormItem>
|
20 | 77 | <NSpace vertical :size="18" class="w-full">
|
21 |
| - <NButton type="primary" size="large" round block> |
| 78 | + <NButton type="primary" size="large" round block @click="handleSubmit"> |
22 | 79 | {{ $t('common.confirm') }}
|
23 | 80 | </NButton>
|
24 | 81 | <NButton size="large" round block @click="toggleLoginModule('pwd-login')">
|
|
0 commit comments