|
1 | 1 | <script lang="ts" setup>
|
2 |
| -import { AuthenticationLogin } from '@vben/common-ui'; |
| 2 | +import type { VbenFormSchema } from '@vben/common-ui'; |
| 3 | +import type { BasicOption } from '@vben/types'; |
| 4 | +
|
| 5 | +import { computed } from 'vue'; |
| 6 | +
|
| 7 | +import { AuthenticationLogin, z } from '@vben/common-ui'; |
| 8 | +import { $t } from '@vben/locales'; |
3 | 9 |
|
4 | 10 | import { useAuthStore } from '#/store';
|
5 | 11 |
|
6 | 12 | defineOptions({ name: 'Login' });
|
7 | 13 |
|
8 | 14 | const authStore = useAuthStore();
|
| 15 | +
|
| 16 | +const MOCK_USER_OPTIONS: BasicOption[] = [ |
| 17 | + { |
| 18 | + label: '超级管理员', |
| 19 | + value: 'vben', |
| 20 | + }, |
| 21 | + { |
| 22 | + label: '管理员', |
| 23 | + value: 'admin', |
| 24 | + }, |
| 25 | + { |
| 26 | + label: '用户', |
| 27 | + value: 'jack', |
| 28 | + }, |
| 29 | +]; |
| 30 | +
|
| 31 | +const formSchema = computed((): VbenFormSchema[] => { |
| 32 | + return [ |
| 33 | + { |
| 34 | + component: 'VbenSelect', |
| 35 | + componentProps: { |
| 36 | + options: MOCK_USER_OPTIONS, |
| 37 | + placeholder: $t('authentication.selectAccount'), |
| 38 | + }, |
| 39 | + fieldName: 'selectAccount', |
| 40 | + label: $t('authentication.selectAccount'), |
| 41 | + rules: z |
| 42 | + .string() |
| 43 | + .min(1, { message: $t('authentication.selectAccount') }) |
| 44 | + .optional() |
| 45 | + .default('vben'), |
| 46 | + }, |
| 47 | + { |
| 48 | + component: 'VbenInput', |
| 49 | + componentProps: { |
| 50 | + placeholder: $t('authentication.usernameTip'), |
| 51 | + }, |
| 52 | + dependencies: { |
| 53 | + trigger(values, form) { |
| 54 | + if (values.selectAccount) { |
| 55 | + const findUser = MOCK_USER_OPTIONS.find( |
| 56 | + (item) => item.value === values.selectAccount, |
| 57 | + ); |
| 58 | + if (findUser) { |
| 59 | + form.setValues({ |
| 60 | + password: '123456', |
| 61 | + username: findUser.value, |
| 62 | + }); |
| 63 | + } |
| 64 | + } |
| 65 | + }, |
| 66 | + triggerFields: ['selectAccount'], |
| 67 | + }, |
| 68 | + fieldName: 'username', |
| 69 | + label: $t('authentication.username'), |
| 70 | + rules: z.string().min(1, { message: $t('authentication.usernameTip') }), |
| 71 | + }, |
| 72 | + { |
| 73 | + component: 'VbenInputPassword', |
| 74 | + componentProps: { |
| 75 | + placeholder: $t('authentication.password'), |
| 76 | + }, |
| 77 | + fieldName: 'password', |
| 78 | + label: $t('authentication.password'), |
| 79 | + rules: z.string().min(1, { message: $t('authentication.passwordTip') }), |
| 80 | + }, |
| 81 | + ]; |
| 82 | +}); |
9 | 83 | </script>
|
10 | 84 |
|
11 | 85 | <template>
|
12 | 86 | <AuthenticationLogin
|
| 87 | + :form-schema="formSchema" |
13 | 88 | :loading="authStore.loginLoading"
|
14 |
| - password-placeholder="123456" |
15 |
| - username-placeholder="vben" |
16 | 89 | @submit="authStore.authLogin"
|
17 | 90 | />
|
18 | 91 | </template>
|
0 commit comments