From c2914d20029796195a6a4b0950c90d79647fda7e Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 22 Mar 2025 09:38:38 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20request=20&&=20login=20&&=20router?= =?UTF-8?q?=E3=80=90e6939e22=E3=80=91=EF=BC=88=E5=A2=9E=E5=8A=A0=20login.v?= =?UTF-8?q?ue=20=E7=9A=84=E7=A7=9F=E6=88=B7=E9=80=89=E6=8B=A9=E3=80=81?= =?UTF-8?q?=E5=BC=80=E5=90=AF=E5=BC=80=E5=85=B3=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/views/_core/authentication/login.vue | 39 ++++++++++++------- .../src/components/select/select.vue | 7 +++- .../src/langs/en-US/authentication.json | 3 +- .../src/langs/zh-CN/authentication.json | 3 +- 4 files changed, 33 insertions(+), 19 deletions(-) diff --git a/apps/web-antd/src/views/_core/authentication/login.vue b/apps/web-antd/src/views/_core/authentication/login.vue index cfd49f570..bdeb9be37 100644 --- a/apps/web-antd/src/views/_core/authentication/login.vue +++ b/apps/web-antd/src/views/_core/authentication/login.vue @@ -13,6 +13,7 @@ import { useAuthStore } from '#/store'; import { useAccessStore } from '@vben/stores'; import { getTenantSimpleList, getTenantByWebsite } from '#/api/core/auth'; +const { tenantEnable } = useAppConfig(import.meta.env, import.meta.env.PROD); defineOptions({ name: 'Login' }); @@ -21,10 +22,11 @@ const accessStore = useAccessStore(); // 租户列表 const tenantList = ref([]); -// 当前选中的租户编号 -const currentTenantId = ref(); -// 获取租户列表,并默认选中 +// 获取 AuthenticationLogin 组件的引用 +const loginRef = ref(); + +/** 获取租户列表,并默认选中 */ const fetchTenantList = async () => { try { // 获取租户列表、域名对应租户 @@ -38,7 +40,6 @@ const fetchTenantList = async () => { tenantId = websiteTenant.id; } // 如果没有从域名获取到租户,尝试从 store 中获取 - debugger; if (!tenantId && accessStore.tenantId) { tenantId = accessStore.tenantId; } @@ -48,8 +49,8 @@ const fetchTenantList = async () => { } // 设置选中的租户编号 - currentTenantId.value = tenantId; accessStore.setTenantId(tenantId); + loginRef.value.getFormApi().setFieldValue('tenantId', tenantId); } catch (error) { console.error('获取租户列表失败:', error); } @@ -69,17 +70,24 @@ const formSchema = computed((): VbenFormSchema[] => { label: item.name, value: item.id, })), - placeholder: $t('authentication.selectTenant'), - // value: currentTenantId.value ?? null, // TODO @芋艿:change 的设置 - onChange: (value: number) => { - // currentTenantId.value = value ?? null; - accessStore.setTenantId(value); - }, + placeholder: $t('authentication.tenantTip'), }, fieldName: 'tenantId', - label: $t('authentication.selectTenant'), - // TODO @芋艿:开关租户的逻辑 - rules: z.number().default(currentTenantId.value), // TODO @芋艿:默认值的设置 + label: $t('authentication.tenant'), + rules: z + .number() + .nullable() + .refine((val) => val != null && val > 0, $t('authentication.tenantTip')) + .default(null), + dependencies: { + triggerFields: ['tenantId'], + if: tenantEnable, + trigger(values) { + if (values.tenantId) { + accessStore.setTenantId(values.tenantId); + } + }, + }, }, { component: 'VbenInput', @@ -96,7 +104,7 @@ const formSchema = computed((): VbenFormSchema[] => { { component: 'VbenInputPassword', componentProps: { - placeholder: $t('authentication.password'), + placeholder: $t('authentication.passwordTip'), }, fieldName: 'password', label: $t('authentication.password'), @@ -111,6 +119,7 @@ const formSchema = computed((): VbenFormSchema[] => {