feat: 用户添加租户身份标识用于控制是否可切换租户
This commit is contained in:
@@ -72,6 +72,7 @@ import { useRoute, useRouter } from "vue-router";
|
||||
import { defaults } from "@/settings";
|
||||
import { DeviceEnum, SidebarColor, ThemeMode, LayoutMode } from "@/enums/settings";
|
||||
import { useAppStore, useSettingsStore, useUserStore } from "@/store";
|
||||
import { hasPerm } from "@/utils/auth";
|
||||
|
||||
// 导入子组件
|
||||
import CommandPalette from "@/components/CommandPalette/index.vue";
|
||||
@@ -98,9 +99,11 @@ const isPlatformUser = computed(() => {
|
||||
return (userStore.userInfo?.tenantScope || "").toUpperCase() === "PLATFORM";
|
||||
});
|
||||
|
||||
const canSwitchTenant = computed(() => hasPerm("sys:tenant:switch", "button"));
|
||||
|
||||
// 是否显示租户选择(仅平台用户可显式切换租户)
|
||||
const showTenantSelect = computed(() => {
|
||||
if (!isPlatformUser.value) {
|
||||
if (!isPlatformUser.value || !canSwitchTenant.value) {
|
||||
return false;
|
||||
}
|
||||
if (tenantStore.tenantList.length <= 1) {
|
||||
|
||||
@@ -66,6 +66,8 @@ export interface UserForm {
|
||||
id?: string;
|
||||
/** 用户头像 */
|
||||
avatar?: string;
|
||||
/** 租户身份标识(PLATFORM/TENANT) */
|
||||
tenantScope?: string;
|
||||
/** 部门ID */
|
||||
deptId?: string;
|
||||
/** 用户邮箱 */
|
||||
|
||||
@@ -100,7 +100,7 @@
|
||||
>
|
||||
<el-table-column type="selection" width="50" align="center" />
|
||||
<el-table-column label="用户名" prop="username" />
|
||||
<el-table-column label="昵称" width="150" align="center" prop="nickname" />
|
||||
<el-table-column label="昵称" width="200" align="center" prop="nickname" />
|
||||
<el-table-column label="性别" width="100" align="center">
|
||||
<template #default="scope">
|
||||
<DictTag v-model="scope.row.gender" code="gender" />
|
||||
@@ -185,6 +185,17 @@
|
||||
<el-input v-model="formData.nickname" placeholder="请输入用户昵称" />
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item v-if="canManageTenantScope" label="租户身份" prop="tenantScope">
|
||||
<el-select v-model="formData.tenantScope" placeholder="请选择租户身份">
|
||||
<el-option
|
||||
v-for="item in tenantScopeOptions"
|
||||
:key="item.value"
|
||||
:label="item.label"
|
||||
:value="item.value"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="所属部门" prop="deptId">
|
||||
<el-tree-select
|
||||
v-model="formData.deptId"
|
||||
@@ -257,6 +268,7 @@ import type { UserForm, UserQueryParams, UserItem } from "@/types/api";
|
||||
|
||||
// ==================== 3.5 工具函数 ====================
|
||||
import { downloadFile, VALIDATORS } from "@/utils";
|
||||
import { hasPerm } from "@/utils/auth";
|
||||
// ==================== 4. API 服务 ====================
|
||||
import UserAPI from "@/api/system/user";
|
||||
import DeptAPI from "@/api/system/dept";
|
||||
@@ -312,6 +324,7 @@ const dialogState = reactive({
|
||||
// 初始表单数据
|
||||
const initialFormData: UserForm = {
|
||||
status: CommonStatus.ENABLED,
|
||||
tenantScope: undefined,
|
||||
};
|
||||
|
||||
// 表单数据
|
||||
@@ -331,6 +344,19 @@ const importDialogVisible = ref(false);
|
||||
*/
|
||||
const drawerSize = computed(() => (appStore.device === DeviceEnum.DESKTOP ? "600px" : "90%"));
|
||||
|
||||
const isPlatformUser = computed(() => {
|
||||
return (userStore.userInfo?.tenantScope || "").toUpperCase() === "PLATFORM";
|
||||
});
|
||||
|
||||
const canManageTenantScope = computed(
|
||||
() => isPlatformUser.value && hasPerm("sys:tenant:switch", "button")
|
||||
);
|
||||
|
||||
const tenantScopeOptions = [
|
||||
{ label: "平台", value: "PLATFORM" },
|
||||
{ label: "租户", value: "TENANT" },
|
||||
];
|
||||
|
||||
// ==================== 表单验证规则 ====================
|
||||
|
||||
const rules = reactive({
|
||||
@@ -445,6 +471,13 @@ async function handleOpenDialog(id?: string): Promise<void> {
|
||||
dialogState.title = "新增用户";
|
||||
dialogState.mode = DialogMode.CREATE;
|
||||
}
|
||||
|
||||
// 仅平台用户可设置租户身份;无权限时避免提交该字段
|
||||
if (canManageTenantScope.value) {
|
||||
formData.tenantScope = formData.tenantScope || "TENANT";
|
||||
} else {
|
||||
formData.tenantScope = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user