feat: 添加切换租户功能,支持平台用户获取新 token,并优化租户选择逻辑

This commit is contained in:
Ray.Hao
2026-01-12 08:03:28 +08:00
parent a24bb92ba8
commit 9ac4d3da02
5 changed files with 50 additions and 17 deletions

View File

@@ -109,7 +109,11 @@
</div>
<template #footer>
<el-button @click="tenantDialogVisible = false">取消</el-button>
<el-button type="primary" :disabled="!selectedTenantId" @click="handleTenantSelected">
<el-button
type="primary"
:disabled="selectedTenantId == null"
@click="handleTenantSelected"
>
继续
</el-button>
</template>
@@ -268,7 +272,7 @@ async function handleLoginSubmit() {
// 需要选择租户
tenantStore.setTenantList(error.data);
selectedTenantId.value = error.data[0]?.id || null;
if (selectedTenantId.value) {
if (selectedTenantId.value != null) {
tenantStore.currentTenantId = selectedTenantId.value;
tenantStore.currentTenant =
error.data.find((t: any) => t.id === selectedTenantId.value) || null;
@@ -292,7 +296,7 @@ async function handleLoginSubmit() {
* 租户选择确认后的处理
*/
async function handleTenantSelected() {
if (!selectedTenantId.value) {
if (selectedTenantId.value == null) {
ElMessage.warning("请选择租户");
return;
}

View File

@@ -59,7 +59,7 @@
{{ `v${appConfig.version}` }}
</el-tag>
<el-tag v-if="tenantEnabled" type="success" size="small" effect="light" round>
多租<EFBFBD>?
多租
</el-tag>
</div>
</div>

View File

@@ -137,7 +137,7 @@
<el-input
v-model="formData.code"
placeholder="请输入租户编码"
:disabled="!!formData.id"
:disabled="formData.id != null && String(formData.id) !== ''"
/>
</el-form-item>
@@ -167,11 +167,19 @@
/>
</el-form-item>
<el-form-item v-if="!formData.id" label="管理员账号" prop="adminUsername">
<el-form-item
v-if="formData.id == null || String(formData.id) === ''"
label="管理员账号"
prop="adminUsername"
>
<el-input v-model="formData.adminUsername" placeholder="为空则系统生成" />
</el-form-item>
<el-form-item v-if="formData.id" label="状态" prop="status">
<el-form-item
v-if="formData.id != null && String(formData.id) !== ''"
label="状态"
prop="status"
>
<el-radio-group v-model="formData.status">
<el-radio :value="1">正常</el-radio>
<el-radio :value="0">禁用</el-radio>
@@ -276,7 +284,7 @@ function handleSelectionChange(selection: any) {
async function handleOpenDialog(tenantId?: string) {
dialog.visible = true;
if (tenantId) {
if (tenantId != null && tenantId !== "") {
dialog.title = "修改租户";
const data = await TenantAPI.getFormData(tenantId);
Object.assign(formData, data);
@@ -325,7 +333,7 @@ const handleSubmit = useDebounceFn(async () => {
loading.value = true;
try {
const tenantId = formData.id;
if (tenantId) {
if (tenantId != null && String(tenantId) !== "") {
const payload: TenantForm = {
id: formData.id,
name: formData.name,
@@ -359,14 +367,14 @@ const handleSubmit = useDebounceFn(async () => {
handleCloseDialog();
handleResetQuery();
} catch {
ElMessage.error(formData.id ? "修改失败" : "新增失败");
ElMessage.error(formData.id != null && String(formData.id) !== "" ? "修改失败" : "新增失败");
} finally {
loading.value = false;
}
}, 300);
function handleDelete(tenantId?: string) {
const tenantIds = tenantId ? tenantId : ids.value.join(",");
const tenantIds = tenantId != null && tenantId !== "" ? tenantId : ids.value.join(",");
if (!tenantIds) {
ElMessage.warning("请勾选删除项");
return;
@@ -393,7 +401,7 @@ function handleDelete(tenantId?: string) {
}
async function handleChangeStatus(id: string | undefined, status: number) {
if (!id) return;
if (id == null || id === "") return;
try {
await TenantAPI.updateStatus(String(id), status);
ElMessage.success("状态更新成功");