修复类型字典问题
This commit is contained in:
@ -6,7 +6,7 @@
|
||||
</div>
|
||||
<el-form-item v-if="tenantEnabled" prop="tenantId">
|
||||
<el-select v-model="loginForm.tenantId" filterable :placeholder="proxy.$t('login.selectPlaceholder')"
|
||||
style="width: 100%">
|
||||
style="width: 100%" @change="onTenantChange">
|
||||
<el-option v-for="item in tenantList" :key="item.tenantId" :label="item.companyName"
|
||||
:value="item.tenantId"></el-option>
|
||||
<template #prefix><svg-icon icon-class="company" class="el-input__icon input-icon" /></template>
|
||||
@ -56,7 +56,7 @@ import { HttpStatus } from '@/enums/RespEnum';
|
||||
|
||||
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
|
||||
|
||||
const title = import.meta.env.VITE_APP_TITLE;
|
||||
const title = ref(import.meta.env.VITE_APP_TITLE);
|
||||
const userStore = useUserStore();
|
||||
const router = useRouter();
|
||||
|
||||
@ -102,19 +102,30 @@ const handleLogin = () => {
|
||||
loginRef.value?.validate(async (valid: boolean, fields: any) => {
|
||||
if (valid) {
|
||||
loading.value = true;
|
||||
// 获取选中租户的名称并设置到登录表单中
|
||||
const tenantName = tenantList.value.find(item => item.tenantId === loginForm.value.tenantId)?.companyName;
|
||||
loginForm.value.tenantName = tenantName;
|
||||
|
||||
// 勾选了需要记住密码设置在 localStorage 中设置记住用户名和密码
|
||||
if (loginForm.value.rememberMe) {
|
||||
localStorage.setItem('tenantId', String(loginForm.value.tenantId));
|
||||
localStorage.setItem('tenantName', String(tenantName || ''));
|
||||
localStorage.setItem('username', String(loginForm.value.username));
|
||||
localStorage.setItem('password', String(loginForm.value.password));
|
||||
localStorage.setItem('rememberMe', String(loginForm.value.rememberMe));
|
||||
} else {
|
||||
// 否则移除
|
||||
localStorage.removeItem('tenantId');
|
||||
localStorage.removeItem('tenantName');
|
||||
localStorage.removeItem('username');
|
||||
localStorage.removeItem('password');
|
||||
localStorage.removeItem('rememberMe');
|
||||
}
|
||||
|
||||
// 无论是否记住密码,都保存租户名称用于页面刷新时恢复
|
||||
if (tenantName) {
|
||||
localStorage.setItem('currentTenantName', tenantName);
|
||||
}
|
||||
// 调用action的登录方法
|
||||
const [err] = await to(userStore.login(loginForm.value));
|
||||
if (!err) {
|
||||
@ -170,6 +181,8 @@ const initTenantList = async () => {
|
||||
tenantList.value = data.voList;
|
||||
if (tenantList.value != null && tenantList.value.length !== 0) {
|
||||
loginForm.value.tenantId = tenantList.value[0].tenantId;
|
||||
// 初始化标题为第一个租户的名称
|
||||
onTenantChange(tenantList.value[0].tenantId);
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -189,6 +202,21 @@ const doSocialLogin = (type: string) => {
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* 租户变化时更新标题
|
||||
*/
|
||||
const onTenantChange = (tenantId: string) => {
|
||||
const selectedTenant = tenantList.value.find(item => item.tenantId === tenantId);
|
||||
if (selectedTenant) {
|
||||
title.value = selectedTenant.companyName;
|
||||
// 同时更新页面标题
|
||||
document.title = selectedTenant.companyName;
|
||||
} else {
|
||||
title.value = import.meta.env.VITE_APP_TITLE;
|
||||
document.title = import.meta.env.VITE_APP_TITLE;
|
||||
}
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
getCode();
|
||||
initTenantList();
|
||||
|
||||
Reference in New Issue
Block a user