refactor(tenant): refine menu scope boundaries and document plan/tenant menu design
This commit is contained in:
@@ -74,6 +74,13 @@
|
||||
<el-table-column label="路由路径" align="left" width="150" prop="routePath" />
|
||||
<el-table-column label="组件路径" align="left" width="250" prop="component" />
|
||||
<el-table-column label="权限标识" align="center" width="200" prop="perm" />
|
||||
<el-table-column v-if="showMenuScope" label="范围" align="center" width="100">
|
||||
<template #default="scope">
|
||||
<el-tag v-if="scope.row.scope === MenuScopeEnum.PLATFORM" type="danger">平台</el-tag>
|
||||
<el-tag v-else type="success">业务</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column label="状态" align="center" width="80">
|
||||
<template #default="scope">
|
||||
<el-tag v-if="scope.row.visible === 1" type="success">显示</el-tag>
|
||||
@@ -262,6 +269,17 @@
|
||||
</div>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item
|
||||
v-if="formData.type !== MenuTypeEnum.BUTTON && showMenuScope"
|
||||
prop="scope"
|
||||
label="菜单范围"
|
||||
>
|
||||
<el-radio-group v-model="formData.scope">
|
||||
<el-radio :value="MenuScopeEnum.PLATFORM">平台菜单</el-radio>
|
||||
<el-radio :value="MenuScopeEnum.TENANT">业务菜单</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item v-if="formData.type !== MenuTypeEnum.BUTTON" prop="visible" label="显示状态">
|
||||
<el-radio-group v-model="formData.visible">
|
||||
<el-radio :value="1">显示</el-radio>
|
||||
@@ -346,7 +364,8 @@ import { DeviceEnum } from "@/enums/settings";
|
||||
|
||||
import MenuAPI from "@/api/system/menu";
|
||||
import type { MenuQueryParams, MenuForm, MenuItem } from "@/types/api";
|
||||
import { MenuTypeEnum } from "@/enums/business";
|
||||
import { MenuScopeEnum, MenuTypeEnum } from "@/enums/business";
|
||||
import { isTenantEnabled } from "@/utils/tenant";
|
||||
|
||||
defineOptions({
|
||||
name: "SysMenu",
|
||||
@@ -367,6 +386,8 @@ const dialog = reactive({
|
||||
const drawerSize = computed(() => (appStore.device === DeviceEnum.DESKTOP ? "600px" : "90%"));
|
||||
// 查询参数
|
||||
const queryParams = reactive<MenuQueryParams>({});
|
||||
// 多租户关闭时,隐藏菜单范围(避免单租户误配置)
|
||||
const showMenuScope = computed(() => isTenantEnabled());
|
||||
// 菜单表格数据
|
||||
const menuTableData = ref<MenuItem[]>([]);
|
||||
// 顶级菜单下拉选项
|
||||
@@ -376,6 +397,7 @@ const initialMenuFormData = ref<MenuForm>({
|
||||
id: undefined,
|
||||
parentId: "0",
|
||||
visible: 1,
|
||||
scope: MenuScopeEnum.TENANT,
|
||||
sort: 1,
|
||||
type: MenuTypeEnum.MENU, // 默认菜单
|
||||
alwaysShow: 0,
|
||||
@@ -549,6 +571,7 @@ function resetForm() {
|
||||
id: undefined,
|
||||
parentId: "0",
|
||||
visible: 1,
|
||||
scope: MenuScopeEnum.TENANT,
|
||||
sort: 1,
|
||||
type: MenuTypeEnum.MENU, // 默认菜单
|
||||
alwaysShow: 0,
|
||||
|
||||
454
src/views/system/tenant-plan/index.vue
Normal file
454
src/views/system/tenant-plan/index.vue
Normal file
@@ -0,0 +1,454 @@
|
||||
<template>
|
||||
<div class="app-container">
|
||||
<!-- 搜索区域 -->
|
||||
<div class="filter-section">
|
||||
<el-form ref="queryFormRef" :model="queryParams" :inline="true">
|
||||
<el-form-item label="关键字" prop="keywords">
|
||||
<el-input
|
||||
v-model="queryParams.keywords"
|
||||
placeholder="套餐名称/套餐编码"
|
||||
clearable
|
||||
@keyup.enter="handleQuery"
|
||||
/>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="状态" prop="status">
|
||||
<el-select v-model="queryParams.status" placeholder="全部" clearable style="width: 120px">
|
||||
<el-option label="启用" :value="1" />
|
||||
<el-option label="停用" :value="0" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item class="search-buttons">
|
||||
<el-button type="primary" icon="search" @click="handleQuery">搜索</el-button>
|
||||
<el-button icon="refresh" @click="handleResetQuery">重置</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</div>
|
||||
|
||||
<el-card shadow="hover" class="table-section">
|
||||
<div class="table-section__toolbar">
|
||||
<div class="table-section__toolbar--actions">
|
||||
<el-button
|
||||
v-hasPerm="['sys:tenant-plan:create']"
|
||||
type="success"
|
||||
icon="plus"
|
||||
@click="handleOpenDialog()"
|
||||
>
|
||||
新增
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<el-table
|
||||
ref="dataTableRef"
|
||||
v-loading="loading"
|
||||
:data="pageData"
|
||||
highlight-current-row
|
||||
border
|
||||
class="table-section__content"
|
||||
>
|
||||
<el-table-column type="index" label="序号" width="60" />
|
||||
<el-table-column label="套餐名称" prop="name" min-width="120" />
|
||||
<el-table-column label="套餐编码" prop="code" width="160" />
|
||||
<el-table-column label="状态" width="100" align="center">
|
||||
<template #default="scope">
|
||||
<el-tag v-if="scope.row.status === 1" type="success">启用</el-tag>
|
||||
<el-tag v-else type="info">停用</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="排序" prop="sort" width="80" align="center" />
|
||||
<el-table-column label="备注" prop="remark" min-width="140" />
|
||||
<el-table-column label="创建时间" prop="createTime" width="180" />
|
||||
<el-table-column fixed="right" label="操作" width="240">
|
||||
<template #default="scope">
|
||||
<el-button
|
||||
v-hasPerm="['sys:tenant-plan:assign']"
|
||||
type="primary"
|
||||
size="small"
|
||||
link
|
||||
icon="menu"
|
||||
@click="handleOpenPlanMenuDialog(scope.row)"
|
||||
>
|
||||
菜单配置
|
||||
</el-button>
|
||||
<el-button
|
||||
v-hasPerm="['sys:tenant-plan:update']"
|
||||
type="primary"
|
||||
size="small"
|
||||
link
|
||||
icon="edit"
|
||||
@click="handleOpenDialog(scope.row.id)"
|
||||
>
|
||||
编辑
|
||||
</el-button>
|
||||
<el-button
|
||||
v-hasPerm="['sys:tenant-plan:delete']"
|
||||
type="danger"
|
||||
size="small"
|
||||
link
|
||||
icon="delete"
|
||||
@click="handleDelete(scope.row.id)"
|
||||
>
|
||||
删除
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<pagination
|
||||
v-if="total > 0"
|
||||
v-model:total="total"
|
||||
v-model:page="queryParams.pageNum"
|
||||
v-model:limit="queryParams.pageSize"
|
||||
@pagination="fetchData"
|
||||
/>
|
||||
</el-card>
|
||||
|
||||
<!-- 租户套餐表单弹窗 -->
|
||||
<el-dialog
|
||||
v-model="dialog.visible"
|
||||
:title="dialog.title"
|
||||
width="520px"
|
||||
@close="handleCloseDialog"
|
||||
>
|
||||
<el-form ref="dataFormRef" :model="formData" :rules="rules" label-width="100px">
|
||||
<el-form-item label="套餐名称" prop="name">
|
||||
<el-input v-model="formData.name" placeholder="请输入套餐名称" />
|
||||
</el-form-item>
|
||||
<el-form-item label="套餐编码" prop="code">
|
||||
<el-input v-model="formData.code" placeholder="请输入套餐编码" />
|
||||
</el-form-item>
|
||||
<el-form-item label="状态" prop="status">
|
||||
<el-radio-group v-model="formData.status">
|
||||
<el-radio :value="1">启用</el-radio>
|
||||
<el-radio :value="0">停用</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
<el-form-item label="排序" prop="sort">
|
||||
<el-input-number
|
||||
v-model="formData.sort"
|
||||
controls-position="right"
|
||||
:min="0"
|
||||
style="width: 120px"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="备注" prop="remark">
|
||||
<el-input v-model="formData.remark" type="textarea" :rows="3" placeholder="可选" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
<el-button type="primary" @click="handleSubmit">确定</el-button>
|
||||
<el-button @click="handleCloseDialog">取消</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
<!-- 方案菜单配置 -->
|
||||
<el-drawer
|
||||
v-model="planMenuDialogVisible"
|
||||
:title="'【' + checkedPlan.name + '】菜单配置'"
|
||||
size="600px"
|
||||
@close="handleClosePlanMenuDialog"
|
||||
>
|
||||
<div class="flex-x-between">
|
||||
<el-input v-model="menuKeywords" clearable class="w-[150px]" placeholder="菜单名称">
|
||||
<template #prefix>
|
||||
<Search />
|
||||
</template>
|
||||
</el-input>
|
||||
|
||||
<div class="flex-center ml-5">
|
||||
<el-button type="primary" size="small" plain @click="toggleMenuTree">
|
||||
<template #icon>
|
||||
<Switch />
|
||||
</template>
|
||||
{{ menuExpanded ? "收缩" : "展开" }}
|
||||
</el-button>
|
||||
<el-checkbox v-model="menuParentChildLinked" class="ml-5" @change="handleMenuLinkChange">
|
||||
父子联动
|
||||
</el-checkbox>
|
||||
|
||||
<el-tooltip placement="bottom">
|
||||
<template #content>
|
||||
如果只需勾选菜单权限,不需要勾选子菜单或者按钮权限,请关闭父子联动
|
||||
</template>
|
||||
<el-icon class="ml-1 color-[--el-color-primary] inline-block cursor-pointer">
|
||||
<QuestionFilled />
|
||||
</el-icon>
|
||||
</el-tooltip>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<el-tree
|
||||
ref="menuTreeRef"
|
||||
node-key="value"
|
||||
show-checkbox
|
||||
:data="menuPermOptions"
|
||||
:filter-node-method="handleMenuFilter"
|
||||
:default-expand-all="true"
|
||||
:check-strictly="!menuParentChildLinked"
|
||||
class="mt-5"
|
||||
>
|
||||
<template #default="{ data }">
|
||||
{{ data.label }}
|
||||
</template>
|
||||
</el-tree>
|
||||
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
<el-button
|
||||
v-hasPerm="['sys:tenant-plan:assign']"
|
||||
type="primary"
|
||||
@click="handlePlanMenuSubmit"
|
||||
>
|
||||
确定
|
||||
</el-button>
|
||||
<el-button @click="planMenuDialogVisible = false">取消</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-drawer>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
defineOptions({
|
||||
name: "TenantPlan",
|
||||
inheritAttrs: false,
|
||||
});
|
||||
|
||||
import { ElMessage, ElMessageBox } from "element-plus";
|
||||
import { useDebounceFn } from "@vueuse/core";
|
||||
|
||||
import MenuAPI from "@/api/system/menu";
|
||||
import TenantPlanAPI from "@/api/system/tenant-plan";
|
||||
import type {
|
||||
TenantPlanForm,
|
||||
TenantPlanItem,
|
||||
TenantPlanQueryParams,
|
||||
OptionItem,
|
||||
} from "@/types/api";
|
||||
import { MenuScopeEnum } from "@/enums/business";
|
||||
|
||||
const queryFormRef = ref();
|
||||
const dataFormRef = ref();
|
||||
const dataTableRef = ref();
|
||||
const menuTreeRef = ref();
|
||||
|
||||
const loading = ref(false);
|
||||
const total = ref(0);
|
||||
|
||||
const queryParams = reactive<TenantPlanQueryParams>({
|
||||
pageNum: 1,
|
||||
pageSize: 10,
|
||||
keywords: "",
|
||||
});
|
||||
|
||||
const pageData = ref<TenantPlanItem[]>([]);
|
||||
const menuPermOptions = ref<OptionItem[]>([]);
|
||||
|
||||
const dialog = reactive({
|
||||
title: "",
|
||||
visible: false,
|
||||
});
|
||||
|
||||
const formData = reactive<TenantPlanForm>({
|
||||
id: undefined,
|
||||
name: "",
|
||||
code: "",
|
||||
status: 1,
|
||||
sort: 1,
|
||||
remark: "",
|
||||
});
|
||||
|
||||
const rules = reactive({
|
||||
name: [{ required: true, message: "请输入套餐名称", trigger: "blur" }],
|
||||
code: [{ required: true, message: "请输入套餐编码", trigger: "blur" }],
|
||||
status: [{ required: true, message: "请选择状态", trigger: "change" }],
|
||||
});
|
||||
|
||||
const planMenuDialogVisible = ref(false);
|
||||
const checkedPlan = ref<{ id?: number; name?: string }>({});
|
||||
const menuKeywords = ref("");
|
||||
const menuExpanded = ref(true);
|
||||
const menuParentChildLinked = ref(true);
|
||||
|
||||
function fetchData() {
|
||||
loading.value = true;
|
||||
TenantPlanAPI.getPage(queryParams)
|
||||
.then((res) => {
|
||||
pageData.value = res.data;
|
||||
total.value = res.page?.total ?? 0;
|
||||
})
|
||||
.finally(() => {
|
||||
loading.value = false;
|
||||
});
|
||||
}
|
||||
|
||||
function handleQuery() {
|
||||
queryParams.pageNum = 1;
|
||||
fetchData();
|
||||
}
|
||||
|
||||
function handleResetQuery() {
|
||||
queryFormRef.value?.resetFields();
|
||||
queryParams.pageNum = 1;
|
||||
fetchData();
|
||||
}
|
||||
|
||||
async function handleOpenDialog(planId?: number) {
|
||||
dialog.visible = true;
|
||||
if (planId) {
|
||||
dialog.title = "修改套餐";
|
||||
const data = await TenantPlanAPI.getFormData(String(planId));
|
||||
Object.assign(formData, data);
|
||||
if (formData.status == null) {
|
||||
formData.status = 1;
|
||||
}
|
||||
if (formData.sort == null) {
|
||||
formData.sort = 1;
|
||||
}
|
||||
} else {
|
||||
dialog.title = "新增套餐";
|
||||
Object.assign(formData, {
|
||||
id: undefined,
|
||||
name: "",
|
||||
code: "",
|
||||
status: 1,
|
||||
sort: 1,
|
||||
remark: "",
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function handleCloseDialog() {
|
||||
dialog.visible = false;
|
||||
dataFormRef.value?.resetFields();
|
||||
dataFormRef.value?.clearValidate();
|
||||
Object.assign(formData, {
|
||||
id: undefined,
|
||||
name: "",
|
||||
code: "",
|
||||
status: 1,
|
||||
sort: 1,
|
||||
remark: "",
|
||||
});
|
||||
}
|
||||
|
||||
const handleSubmit = useDebounceFn(async () => {
|
||||
const valid = await dataFormRef.value?.validate().catch(() => false);
|
||||
if (!valid) return;
|
||||
|
||||
loading.value = true;
|
||||
try {
|
||||
if (formData.id) {
|
||||
await TenantPlanAPI.update(String(formData.id), formData);
|
||||
ElMessage.success("修改成功");
|
||||
} else {
|
||||
await TenantPlanAPI.create(formData);
|
||||
ElMessage.success("新增成功");
|
||||
}
|
||||
handleCloseDialog();
|
||||
handleResetQuery();
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}, 300);
|
||||
|
||||
function handleDelete(planId?: number) {
|
||||
if (!planId) return;
|
||||
ElMessageBox.confirm("确认删除该租户套餐吗?", "警告", {
|
||||
confirmButtonText: "确定",
|
||||
cancelButtonText: "取消",
|
||||
type: "warning",
|
||||
}).then(() => {
|
||||
loading.value = true;
|
||||
TenantPlanAPI.deleteByIds(String(planId))
|
||||
.then(() => {
|
||||
ElMessage.success("删除成功");
|
||||
handleResetQuery();
|
||||
})
|
||||
.finally(() => {
|
||||
loading.value = false;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async function handleOpenPlanMenuDialog(row: TenantPlanItem) {
|
||||
if (!row.id) return;
|
||||
planMenuDialogVisible.value = true;
|
||||
loading.value = true;
|
||||
checkedPlan.value = { id: row.id, name: row.name };
|
||||
|
||||
try {
|
||||
// 套餐菜单仅允许业务菜单
|
||||
const menuOptions = await MenuAPI.getOptions(false, MenuScopeEnum.TENANT);
|
||||
menuPermOptions.value = menuOptions;
|
||||
const menuIds = await TenantPlanAPI.getPlanMenuIds(row.id);
|
||||
await nextTick();
|
||||
menuTreeRef.value?.setCheckedKeys([], false);
|
||||
menuIds.forEach((menuId) => menuTreeRef.value?.setChecked(menuId, true, false));
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function handleClosePlanMenuDialog() {
|
||||
planMenuDialogVisible.value = false;
|
||||
menuKeywords.value = "";
|
||||
menuExpanded.value = true;
|
||||
menuParentChildLinked.value = true;
|
||||
menuTreeRef.value?.setCheckedKeys([], false);
|
||||
}
|
||||
|
||||
function toggleMenuTree() {
|
||||
menuExpanded.value = !menuExpanded.value;
|
||||
if (menuTreeRef.value) {
|
||||
Object.values(menuTreeRef.value.store.nodesMap).forEach((node: any) => {
|
||||
if (menuExpanded.value) {
|
||||
node.expand();
|
||||
} else {
|
||||
node.collapse();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function handleMenuLinkChange(val: boolean) {
|
||||
menuParentChildLinked.value = val;
|
||||
}
|
||||
|
||||
watch(menuKeywords, (val) => {
|
||||
menuTreeRef.value?.filter(val);
|
||||
});
|
||||
|
||||
function handleMenuFilter(value: string, data: { [key: string]: any }) {
|
||||
if (!value) return true;
|
||||
return data.label.includes(value);
|
||||
}
|
||||
|
||||
async function handlePlanMenuSubmit() {
|
||||
const planId = checkedPlan.value.id;
|
||||
if (!planId) return;
|
||||
|
||||
const checkedMenuIds: number[] = menuTreeRef
|
||||
.value!.getCheckedNodes(false, true)
|
||||
.map((node: any) => node.value);
|
||||
|
||||
loading.value = true;
|
||||
try {
|
||||
await TenantPlanAPI.updatePlanMenus(planId, checkedMenuIds);
|
||||
ElMessage.success("菜单配置成功");
|
||||
planMenuDialogVisible.value = false;
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
fetchData();
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss"></style>
|
||||
@@ -57,9 +57,19 @@
|
||||
class="table-section__content"
|
||||
@selection-change="handleSelectionChange"
|
||||
>
|
||||
<el-table-column type="selection" width="55" align="center" />
|
||||
<el-table-column
|
||||
type="selection"
|
||||
width="55"
|
||||
align="center"
|
||||
:selectable="isTenantSelectable"
|
||||
/>
|
||||
<el-table-column label="租户名称" prop="name" min-width="160" />
|
||||
<el-table-column label="租户编码" prop="code" width="140" />
|
||||
<el-table-column label="租户套餐" min-width="140">
|
||||
<template #default="scope">
|
||||
<span>{{ resolvePlanLabel(scope.row.planId) }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="域名" prop="domain" min-width="160" />
|
||||
<el-table-column label="联系人" prop="contactName" width="120" />
|
||||
<el-table-column label="电话" prop="contactPhone" width="140" />
|
||||
@@ -73,11 +83,7 @@
|
||||
inactive-text="禁用"
|
||||
:active-value="1"
|
||||
:inactive-value="0"
|
||||
@change="
|
||||
(val) => {
|
||||
pageData.length > 0 && handleChangeStatus(scope.row.id, Number(val));
|
||||
}
|
||||
"
|
||||
@change="handleStatusChange(scope.row.id, $event)"
|
||||
/>
|
||||
<el-tag v-else :type="scope.row.status === 1 ? 'success' : 'info'">
|
||||
{{ scope.row.status === 1 ? "正常" : "禁用" }}
|
||||
@@ -86,8 +92,19 @@
|
||||
</el-table-column>
|
||||
<el-table-column label="过期时间" prop="expireTime" width="180" />
|
||||
<el-table-column label="创建时间" prop="createTime" width="180" />
|
||||
<el-table-column fixed="right" label="操作" width="180">
|
||||
<el-table-column fixed="right" label="操作" width="260">
|
||||
<template #default="scope">
|
||||
<el-button
|
||||
v-if="!isPlatformTenantId(scope.row.id)"
|
||||
v-hasPerm="['sys:tenant:update']"
|
||||
type="primary"
|
||||
size="small"
|
||||
link
|
||||
icon="menu"
|
||||
@click="handleOpenPlanMenuDialog(scope.row)"
|
||||
>
|
||||
方案菜单
|
||||
</el-button>
|
||||
<el-button
|
||||
v-hasPerm="['sys:tenant:update']"
|
||||
type="primary"
|
||||
@@ -99,6 +116,7 @@
|
||||
编辑
|
||||
</el-button>
|
||||
<el-button
|
||||
v-if="!isPlatformTenantId(scope.row.id)"
|
||||
v-hasPerm="['sys:tenant:delete']"
|
||||
type="danger"
|
||||
size="small"
|
||||
@@ -145,6 +163,17 @@
|
||||
<el-input v-model="formData.domain" placeholder="demo.youlai.tech(可选)" />
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item v-if="!isPlatformTenant" label="租户套餐" prop="planId">
|
||||
<el-select v-model="formData.planId" placeholder="请选择租户套餐" style="width: 100%">
|
||||
<el-option
|
||||
v-for="item in planOptions"
|
||||
:key="item.value"
|
||||
:label="item.label"
|
||||
:value="item.value"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="联系人" prop="contactName">
|
||||
<el-input v-model="formData.contactName" placeholder="可选" />
|
||||
</el-form-item>
|
||||
@@ -198,6 +227,71 @@
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
<!-- 方案菜单配置 -->
|
||||
<el-drawer
|
||||
v-model="planMenuDialogVisible"
|
||||
:title="'【' + checkedPlan.name + '】方案菜单配置'"
|
||||
size="600px"
|
||||
@close="handleClosePlanMenuDialog"
|
||||
>
|
||||
<div class="flex-x-between">
|
||||
<el-input v-model="menuKeywords" clearable class="w-[150px]" placeholder="菜单名称">
|
||||
<template #prefix>
|
||||
<Search />
|
||||
</template>
|
||||
</el-input>
|
||||
|
||||
<div class="flex-center ml-5">
|
||||
<el-button type="primary" size="small" plain @click="toggleMenuTree">
|
||||
<template #icon>
|
||||
<Switch />
|
||||
</template>
|
||||
{{ menuExpanded ? "收缩" : "展开" }}
|
||||
</el-button>
|
||||
<el-checkbox v-model="menuParentChildLinked" class="ml-5" @change="handleMenuLinkChange">
|
||||
父子联动
|
||||
</el-checkbox>
|
||||
|
||||
<el-tooltip placement="bottom">
|
||||
<template #content>
|
||||
如果只需勾选菜单权限,不需要勾选子菜单或者按钮权限,请关闭父子联动
|
||||
</template>
|
||||
<el-icon class="ml-1 color-[--el-color-primary] inline-block cursor-pointer">
|
||||
<QuestionFilled />
|
||||
</el-icon>
|
||||
</el-tooltip>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<el-tree
|
||||
ref="menuTreeRef"
|
||||
node-key="value"
|
||||
show-checkbox
|
||||
:data="menuPermOptions"
|
||||
:filter-node-method="handleMenuFilter"
|
||||
:default-expand-all="true"
|
||||
:check-strictly="!menuParentChildLinked"
|
||||
class="mt-5"
|
||||
>
|
||||
<template #default="{ data }">
|
||||
{{ data.label }}
|
||||
</template>
|
||||
</el-tree>
|
||||
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
<el-button
|
||||
v-hasPerm="['sys:tenant-plan:assign']"
|
||||
type="primary"
|
||||
@click="handlePlanMenuSubmit"
|
||||
>
|
||||
确定
|
||||
</el-button>
|
||||
<el-button @click="planMenuDialogVisible = false">取消</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-drawer>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -212,10 +306,15 @@ import { useDebounceFn } from "@vueuse/core";
|
||||
import { hasPerm } from "@/utils/auth";
|
||||
|
||||
import TenantAPI from "@/api/system/tenant";
|
||||
import TenantPlanAPI from "@/api/system/tenant-plan";
|
||||
import MenuAPI from "@/api/system/menu";
|
||||
import type { TenantCreateForm, TenantForm, TenantQueryParams, TenantItem } from "@/types/api";
|
||||
import { MenuScopeEnum } from "@/enums/business";
|
||||
import { isPlatformTenantId } from "@/utils/tenant";
|
||||
|
||||
const queryFormRef = ref();
|
||||
const dataFormRef = ref();
|
||||
const menuTreeRef = ref();
|
||||
|
||||
const loading = ref(false);
|
||||
const ids = ref<number[]>([]);
|
||||
@@ -229,11 +328,21 @@ const queryParams = reactive<TenantQueryParams>({
|
||||
|
||||
const pageData = ref<TenantItem[]>([]);
|
||||
|
||||
const menuPermOptions = ref<OptionItem[]>([]);
|
||||
|
||||
const dialog = reactive({
|
||||
title: "",
|
||||
visible: false,
|
||||
});
|
||||
|
||||
const planMenuDialogVisible = ref(false);
|
||||
const checkedPlan = ref<{ id?: number; name?: string }>({});
|
||||
const menuKeywords = ref("");
|
||||
const menuExpanded = ref(true);
|
||||
const menuParentChildLinked = ref(true);
|
||||
|
||||
const planOptions = ref<OptionItem[]>([]);
|
||||
|
||||
const formData = reactive<TenantForm & TenantCreateForm>({
|
||||
id: undefined,
|
||||
name: "",
|
||||
@@ -242,24 +351,57 @@ const formData = reactive<TenantForm & TenantCreateForm>({
|
||||
contactName: "",
|
||||
contactPhone: "",
|
||||
contactEmail: "",
|
||||
planId: undefined,
|
||||
remark: "",
|
||||
expireTime: undefined,
|
||||
status: 1,
|
||||
adminUsername: "",
|
||||
});
|
||||
|
||||
const isPlatformTenant = computed(() => isPlatformTenantId(formData.id));
|
||||
|
||||
// 平台租户不允许批量删除
|
||||
const isTenantSelectable = (row: TenantItem) => !isPlatformTenantId(row.id);
|
||||
|
||||
const rules = reactive({
|
||||
name: [{ required: true, message: "请输入租户名称", trigger: "blur" }],
|
||||
code: [{ required: true, message: "请输入租户编码", trigger: "blur" }],
|
||||
planId: [
|
||||
{
|
||||
// 平台租户不绑定套餐
|
||||
validator: (_: unknown, value: number | undefined, callback: (error?: Error) => void) => {
|
||||
if (isPlatformTenant.value) return callback();
|
||||
if (value == null) return callback(new Error("请选择租户套餐"));
|
||||
return callback();
|
||||
},
|
||||
trigger: "change",
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const hasPermChangeStatus = computed(() => hasPerm("sys:tenant:change-status"));
|
||||
|
||||
function handleStatusChange(tenantId: string | number | undefined, val: string | number | boolean) {
|
||||
if (tenantId == null) return;
|
||||
if (pageData.value.length > 0) {
|
||||
handleChangeStatus(String(tenantId), Number(val));
|
||||
}
|
||||
}
|
||||
|
||||
function resolvePlanLabel(planId?: number) {
|
||||
if (planId == null) return "-";
|
||||
const matched = planOptions.value.find((item) => Number(item.value) === planId);
|
||||
return matched?.label || String(planId);
|
||||
}
|
||||
|
||||
function fetchData() {
|
||||
loading.value = true;
|
||||
TenantAPI.getPage(queryParams)
|
||||
.then((res) => {
|
||||
pageData.value = res.data;
|
||||
pageData.value = res.data.map((item) => ({
|
||||
...item,
|
||||
planId: item.planId != null ? Number(item.planId) : undefined,
|
||||
}));
|
||||
total.value = res.page?.total ?? 0;
|
||||
})
|
||||
.finally(() => {
|
||||
@@ -267,6 +409,85 @@ function fetchData() {
|
||||
});
|
||||
}
|
||||
|
||||
async function handleOpenPlanMenuDialog(row: TenantItem) {
|
||||
if (isPlatformTenantId(row.id)) {
|
||||
return;
|
||||
}
|
||||
const planId = row.planId;
|
||||
if (!planId) {
|
||||
ElMessage.warning("请先为租户选择套餐");
|
||||
return;
|
||||
}
|
||||
|
||||
planMenuDialogVisible.value = true;
|
||||
loading.value = true;
|
||||
checkedPlan.value = { id: planId, name: resolvePlanLabel(planId) };
|
||||
|
||||
try {
|
||||
// 套餐菜单只允许配置业务菜单
|
||||
const menuOptions = await MenuAPI.getOptions(false, MenuScopeEnum.TENANT);
|
||||
menuPermOptions.value = menuOptions;
|
||||
const menuIds = await TenantPlanAPI.getPlanMenuIds(planId);
|
||||
await nextTick();
|
||||
menuTreeRef.value?.setCheckedKeys([], false);
|
||||
menuIds.forEach((menuId) => menuTreeRef.value?.setChecked(menuId, true, false));
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function handleClosePlanMenuDialog() {
|
||||
planMenuDialogVisible.value = false;
|
||||
menuKeywords.value = "";
|
||||
menuExpanded.value = true;
|
||||
menuParentChildLinked.value = true;
|
||||
menuTreeRef.value?.setCheckedKeys([], false);
|
||||
}
|
||||
|
||||
function toggleMenuTree() {
|
||||
menuExpanded.value = !menuExpanded.value;
|
||||
if (menuTreeRef.value) {
|
||||
Object.values(menuTreeRef.value.store.nodesMap).forEach((node: any) => {
|
||||
if (menuExpanded.value) {
|
||||
node.expand();
|
||||
} else {
|
||||
node.collapse();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function handleMenuLinkChange(val: boolean) {
|
||||
menuParentChildLinked.value = val;
|
||||
}
|
||||
|
||||
watch(menuKeywords, (val) => {
|
||||
menuTreeRef.value?.filter(val);
|
||||
});
|
||||
|
||||
function handleMenuFilter(value: string, data: { [key: string]: any }) {
|
||||
if (!value) return true;
|
||||
return data.label.includes(value);
|
||||
}
|
||||
|
||||
async function handlePlanMenuSubmit() {
|
||||
const planId = checkedPlan.value.id;
|
||||
if (!planId) return;
|
||||
|
||||
const checkedMenuIds: number[] = menuTreeRef
|
||||
.value!.getCheckedNodes(false, true)
|
||||
.map((node: any) => node.value);
|
||||
|
||||
loading.value = true;
|
||||
try {
|
||||
await TenantPlanAPI.updatePlanMenus(planId, checkedMenuIds);
|
||||
ElMessage.success("方案菜单配置成功");
|
||||
planMenuDialogVisible.value = false;
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function handleQuery() {
|
||||
queryParams.pageNum = 1;
|
||||
fetchData();
|
||||
@@ -289,6 +510,10 @@ async function handleOpenDialog(tenantId?: string) {
|
||||
const data = await TenantAPI.getFormData(tenantId);
|
||||
Object.assign(formData, data);
|
||||
formData.adminUsername = "";
|
||||
formData.planId = formData.planId != null ? Number(formData.planId) : undefined;
|
||||
if (isPlatformTenant.value) {
|
||||
formData.planId = undefined;
|
||||
}
|
||||
} else {
|
||||
dialog.title = "新增租户";
|
||||
Object.assign(formData, {
|
||||
@@ -299,6 +524,7 @@ async function handleOpenDialog(tenantId?: string) {
|
||||
contactName: "",
|
||||
contactPhone: "",
|
||||
contactEmail: "",
|
||||
planId: undefined,
|
||||
remark: "",
|
||||
expireTime: undefined,
|
||||
status: 1,
|
||||
@@ -319,6 +545,7 @@ function handleCloseDialog() {
|
||||
contactName: "",
|
||||
contactPhone: "",
|
||||
contactEmail: "",
|
||||
planId: undefined,
|
||||
remark: "",
|
||||
expireTime: undefined,
|
||||
status: 1,
|
||||
@@ -342,6 +569,7 @@ const handleSubmit = useDebounceFn(async () => {
|
||||
contactName: formData.contactName,
|
||||
contactPhone: formData.contactPhone,
|
||||
contactEmail: formData.contactEmail,
|
||||
planId: formData.planId,
|
||||
remark: formData.remark,
|
||||
expireTime: formData.expireTime,
|
||||
status: formData.status,
|
||||
@@ -356,6 +584,7 @@ const handleSubmit = useDebounceFn(async () => {
|
||||
contactName: formData.contactName,
|
||||
contactPhone: formData.contactPhone,
|
||||
contactEmail: formData.contactEmail,
|
||||
planId: formData.planId,
|
||||
remark: formData.remark,
|
||||
expireTime: formData.expireTime,
|
||||
adminUsername: formData.adminUsername,
|
||||
@@ -413,7 +642,20 @@ async function handleChangeStatus(id: string | undefined, status: number) {
|
||||
|
||||
onMounted(() => {
|
||||
fetchData();
|
||||
fetchPlanOptions();
|
||||
});
|
||||
|
||||
async function fetchPlanOptions() {
|
||||
try {
|
||||
const options = await TenantPlanAPI.getOptions();
|
||||
planOptions.value = options.map((item) => ({
|
||||
...item,
|
||||
value: item.value != null ? Number(item.value) : item.value,
|
||||
}));
|
||||
} catch {
|
||||
planOptions.value = [];
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss"></style>
|
||||
|
||||
@@ -185,17 +185,6 @@
|
||||
<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"
|
||||
@@ -268,7 +257,6 @@ 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";
|
||||
@@ -324,7 +312,6 @@ const dialogState = reactive({
|
||||
// 初始表单数据
|
||||
const initialFormData: UserForm = {
|
||||
status: CommonStatus.ENABLED,
|
||||
tenantScope: undefined,
|
||||
};
|
||||
|
||||
// 表单数据
|
||||
@@ -344,19 +331,6 @@ 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({
|
||||
@@ -471,13 +445,6 @@ 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