mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 07:09:20 +08:00
feat: 新增超级管理目录及公司菜单/权限管理独立页面
- 数据库:新增超级管理目录(sys_menu ID=40),将原超管专属菜单移入其下 - 新增公司菜单管理页面(公司菜单管理):左右分栏,公司列表+菜单树勾选 - 新增公司权限管理页面(公司权限管理):左右分栏,公司列表+权限码勾选 - 路由:/organization/company-menu-manage 和 /organization/company-permission-manage - 公司菜单管理/公司权限管理分配给职位1
This commit is contained in:
@@ -59,6 +59,26 @@ const routes: RouteRecordRaw[] = [
|
|||||||
title: '职位权限分配',
|
title: '职位权限分配',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: 'CompanyMenuAssign',
|
||||||
|
path: '/organization/company-menu-manage',
|
||||||
|
component: () =>
|
||||||
|
import('#/views/organization/company-menu-manage/index.vue'),
|
||||||
|
meta: {
|
||||||
|
icon: 'lucide:layoutDashboard',
|
||||||
|
title: '公司菜单管理',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'CompanyPermissionAssign',
|
||||||
|
path: '/organization/company-permission-manage',
|
||||||
|
component: () =>
|
||||||
|
import('#/views/organization/company-permission-manage/index.vue'),
|
||||||
|
meta: {
|
||||||
|
icon: 'lucide:shield-check',
|
||||||
|
title: '公司权限管理',
|
||||||
|
},
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -0,0 +1,385 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import type { CompanyVO } from '#/api/organization/company/types';
|
||||||
|
|
||||||
|
import { computed, onMounted, ref } from 'vue';
|
||||||
|
|
||||||
|
import { Page } from '@vben/common-ui';
|
||||||
|
|
||||||
|
import {
|
||||||
|
Button,
|
||||||
|
Card,
|
||||||
|
Checkbox,
|
||||||
|
Flex,
|
||||||
|
Input,
|
||||||
|
message,
|
||||||
|
Pagination,
|
||||||
|
Select,
|
||||||
|
Spin,
|
||||||
|
Tag,
|
||||||
|
Tree,
|
||||||
|
} from 'ant-design-vue';
|
||||||
|
|
||||||
|
import {
|
||||||
|
batchUpdateCompanyMenusApi,
|
||||||
|
getAllMenusApi,
|
||||||
|
getCompanyMenuIdsApi,
|
||||||
|
} from '#/api/organization/company-menu/apis';
|
||||||
|
import { getCompanyPageApi } from '#/api/organization/company';
|
||||||
|
|
||||||
|
defineOptions({
|
||||||
|
name: 'CompanyMenuManagePage',
|
||||||
|
});
|
||||||
|
|
||||||
|
// 搜索表单
|
||||||
|
const searchForm = ref({
|
||||||
|
name: '',
|
||||||
|
status: undefined as number | undefined,
|
||||||
|
});
|
||||||
|
|
||||||
|
// 公司列表
|
||||||
|
const companyList = ref<CompanyVO.CompanyInfoVO[]>([]);
|
||||||
|
const companyLoading = ref(false);
|
||||||
|
const companyPagination = ref({
|
||||||
|
current: 1,
|
||||||
|
pageSize: 10,
|
||||||
|
total: 0,
|
||||||
|
});
|
||||||
|
|
||||||
|
// 当前选中的公司
|
||||||
|
const currentCompany = ref<null | CompanyVO.CompanyInfoVO>(null);
|
||||||
|
|
||||||
|
// 所有菜单列表(扁平)
|
||||||
|
const systemMenuList = ref<any[]>([]);
|
||||||
|
|
||||||
|
// 当前公司的菜单ID列表
|
||||||
|
const companyMenuIds = ref<number[]>([]);
|
||||||
|
const selectedMenuIds = ref<number[]>([]);
|
||||||
|
|
||||||
|
// 菜单加载状态
|
||||||
|
const menuLoading = ref(false);
|
||||||
|
|
||||||
|
// 树形数据
|
||||||
|
const menuTreeData = computed(() => {
|
||||||
|
const list = systemMenuList.value;
|
||||||
|
const map = new Map<number, any>();
|
||||||
|
const roots: any[] = [];
|
||||||
|
|
||||||
|
list.forEach((menu) => {
|
||||||
|
map.set(menu.id, { ...menu, key: menu.id, title: menu.title, children: [] });
|
||||||
|
});
|
||||||
|
|
||||||
|
list.forEach((menu) => {
|
||||||
|
const node = map.get(menu.id)!;
|
||||||
|
if (menu.parentId && map.has(menu.parentId)) {
|
||||||
|
map.get(menu.parentId)!.children.push(node);
|
||||||
|
} else {
|
||||||
|
roots.push(node);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return roots;
|
||||||
|
});
|
||||||
|
|
||||||
|
// 统计
|
||||||
|
const stats = computed(() => ({
|
||||||
|
total: systemMenuList.value.filter((m) => m.type === 'menu').length,
|
||||||
|
company: companyMenuIds.value.length,
|
||||||
|
selected: selectedMenuIds.value.length,
|
||||||
|
changed: selectedMenuIds.value.length !== companyMenuIds.value.length,
|
||||||
|
}));
|
||||||
|
|
||||||
|
// 搜索公司列表
|
||||||
|
async function searchCompanies() {
|
||||||
|
companyLoading.value = true;
|
||||||
|
try {
|
||||||
|
const result = await getCompanyPageApi({
|
||||||
|
page: companyPagination.value.current,
|
||||||
|
pageSize: companyPagination.value.pageSize,
|
||||||
|
filters: {
|
||||||
|
name: searchForm.value.name || undefined,
|
||||||
|
status: searchForm.value.status,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
companyList.value = result.records;
|
||||||
|
companyPagination.value.total = result.total;
|
||||||
|
} catch (error: any) {
|
||||||
|
message.error(error?.message || '获取公司列表失败');
|
||||||
|
} finally {
|
||||||
|
companyLoading.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 选择公司
|
||||||
|
async function selectCompany(company: CompanyVO.CompanyInfoVO) {
|
||||||
|
currentCompany.value = company;
|
||||||
|
await loadCompanyMenus();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 加载当前公司的菜单
|
||||||
|
async function loadCompanyMenus() {
|
||||||
|
if (!currentCompany.value?.id) return;
|
||||||
|
menuLoading.value = true;
|
||||||
|
try {
|
||||||
|
const [allMenus, menuIds] = await Promise.all([
|
||||||
|
getAllMenusApi(),
|
||||||
|
getCompanyMenuIdsApi(currentCompany.value.id),
|
||||||
|
]);
|
||||||
|
systemMenuList.value = allMenus || [];
|
||||||
|
companyMenuIds.value = menuIds || [];
|
||||||
|
selectedMenuIds.value = [...companyMenuIds.value];
|
||||||
|
} catch (error: any) {
|
||||||
|
message.error(error?.message || '加载菜单失败');
|
||||||
|
} finally {
|
||||||
|
menuLoading.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tree勾选变化
|
||||||
|
function handleTreeCheckChange(checkedKeys: any) {
|
||||||
|
// 对比新旧值,找出被取消勾选的节点
|
||||||
|
const oldKeys = new Set(selectedMenuIds.value);
|
||||||
|
const newKeys = new Set(Array.isArray(checkedKeys) ? checkedKeys : checkedKeys);
|
||||||
|
|
||||||
|
const removedKeys = [...oldKeys].filter((k) => !newKeys.has(k));
|
||||||
|
const addedKeys = [...newKeys].filter((k) => !oldKeys.has(k));
|
||||||
|
|
||||||
|
// 如果是取消勾选,移除子节点
|
||||||
|
if (removedKeys.length > 0) {
|
||||||
|
const parentToChildren = new Map<number, number[]>();
|
||||||
|
for (const menu of systemMenuList.value) {
|
||||||
|
if (menu.parentId) {
|
||||||
|
const children = parentToChildren.get(menu.parentId) || [];
|
||||||
|
children.push(menu.id);
|
||||||
|
parentToChildren.set(menu.parentId, children);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function removeDescendants(nodeId: number) {
|
||||||
|
const children = parentToChildren.get(nodeId) || [];
|
||||||
|
for (const childId of children) {
|
||||||
|
newKeys.delete(childId);
|
||||||
|
removeDescendants(childId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const removedId of removedKeys) {
|
||||||
|
removeDescendants(removedId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果是新增勾选,自动勾选所有祖先节点
|
||||||
|
if (addedKeys.length > 0) {
|
||||||
|
const menuMap = new Map<number, any>();
|
||||||
|
for (const menu of systemMenuList.value) {
|
||||||
|
menuMap.set(menu.id, menu);
|
||||||
|
}
|
||||||
|
|
||||||
|
function addAncestors(menuId: number) {
|
||||||
|
const menu = menuMap.get(menuId);
|
||||||
|
if (menu?.parentId && menu.parentId > 0) {
|
||||||
|
newKeys.add(menu.parentId);
|
||||||
|
addAncestors(menu.parentId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const addedId of addedKeys) {
|
||||||
|
addAncestors(addedId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
selectedMenuIds.value = [...newKeys];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 全选/取消全选
|
||||||
|
function selectAll() {
|
||||||
|
selectedMenuIds.value = systemMenuList.value
|
||||||
|
.filter((m) => m.type === 'menu')
|
||||||
|
.map((m) => m.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
function selectNone() {
|
||||||
|
selectedMenuIds.value = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 保存
|
||||||
|
async function handleSave() {
|
||||||
|
if (!currentCompany.value?.id) return;
|
||||||
|
try {
|
||||||
|
await batchUpdateCompanyMenusApi(currentCompany.value.id, selectedMenuIds.value);
|
||||||
|
message.success('菜单配置保存成功');
|
||||||
|
companyMenuIds.value = [...selectedMenuIds.value];
|
||||||
|
} catch (error: any) {
|
||||||
|
message.error(error?.message || '保存失败');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 重置搜索
|
||||||
|
function resetSearch() {
|
||||||
|
searchForm.value = { name: '', status: undefined };
|
||||||
|
companyPagination.value.current = 1;
|
||||||
|
searchCompanies();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 分页
|
||||||
|
function handlePageChange(page: number, pageSize: number) {
|
||||||
|
companyPagination.value.current = page;
|
||||||
|
companyPagination.value.pageSize = pageSize;
|
||||||
|
searchCompanies();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 初始化
|
||||||
|
onMounted(() => {
|
||||||
|
searchCompanies();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Page :auto-content-height="true">
|
||||||
|
<Flex gap="middle" class="h-full">
|
||||||
|
<!-- 左栏:公司列表 -->
|
||||||
|
<Card
|
||||||
|
title="公司列表"
|
||||||
|
class="flex h-full max-w-[400px] flex-col"
|
||||||
|
:body-style="{
|
||||||
|
height: '100%',
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
gap: '10px',
|
||||||
|
}"
|
||||||
|
>
|
||||||
|
<!-- 搜索区域 -->
|
||||||
|
<Flex class="flex-wrap gap-2">
|
||||||
|
<Input
|
||||||
|
v-model:value="searchForm.name"
|
||||||
|
placeholder="请输入公司名称"
|
||||||
|
allow-clear
|
||||||
|
style="width: 180px; margin-right: 8px"
|
||||||
|
/>
|
||||||
|
<Select
|
||||||
|
v-model:value="searchForm.status"
|
||||||
|
placeholder="状态"
|
||||||
|
allow-clear
|
||||||
|
style="width: 100px; margin-right: 8px"
|
||||||
|
>
|
||||||
|
<Select.Option :value="1">启用</Select.Option>
|
||||||
|
<Select.Option :value="0">禁用</Select.Option>
|
||||||
|
</Select>
|
||||||
|
<Button type="primary" @click="searchCompanies">搜索</Button>
|
||||||
|
<Button @click="resetSearch">重置</Button>
|
||||||
|
</Flex>
|
||||||
|
|
||||||
|
<!-- 公司列表 -->
|
||||||
|
<Flex vertical class="flex-1 overflow-y-auto">
|
||||||
|
<Spin :spinning="companyLoading">
|
||||||
|
<Card
|
||||||
|
v-for="company in companyList"
|
||||||
|
:key="company.id"
|
||||||
|
hoverable
|
||||||
|
size="small"
|
||||||
|
:body-style="{ padding: '10px 12px' }"
|
||||||
|
class="mb-2 cursor-pointer transition-all duration-200"
|
||||||
|
:class="[
|
||||||
|
currentCompany?.id === company.id &&
|
||||||
|
'ring-primary shadow ring-1',
|
||||||
|
]"
|
||||||
|
@click="selectCompany(company)"
|
||||||
|
>
|
||||||
|
<div class="flex items-start justify-between gap-2">
|
||||||
|
<div class="min-w-0">
|
||||||
|
<div class="mb-1 flex items-center gap-2">
|
||||||
|
<span
|
||||||
|
class="inline-block h-2 w-2 rounded-full"
|
||||||
|
:class="company.status === 1 ? 'bg-green-500' : 'bg-red-500'"
|
||||||
|
></span>
|
||||||
|
<span class="truncate text-sm font-semibold">{{ company.name }}</span>
|
||||||
|
</div>
|
||||||
|
<div class="text-xs text-gray-400">ID: {{ company.id }}</div>
|
||||||
|
</div>
|
||||||
|
<Tag :color="company.status === 1 ? 'green' : 'red'">
|
||||||
|
{{ company.status === 1 ? '启用' : '禁用' }}
|
||||||
|
</Tag>
|
||||||
|
</div>
|
||||||
|
</Card>
|
||||||
|
</Spin>
|
||||||
|
|
||||||
|
<Flex justify="center" class="mt-2">
|
||||||
|
<Pagination
|
||||||
|
v-model:current="companyPagination.current"
|
||||||
|
v-model:page-size="companyPagination.pageSize"
|
||||||
|
:total="companyPagination.total"
|
||||||
|
:show-size-changer="true"
|
||||||
|
:show-quick-jumper="true"
|
||||||
|
@change="handlePageChange"
|
||||||
|
/>
|
||||||
|
</Flex>
|
||||||
|
</Flex>
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
<!-- 右栏:公司菜单分配 -->
|
||||||
|
<Card
|
||||||
|
title="公司菜单分配"
|
||||||
|
class="flex h-full flex-1 flex-col"
|
||||||
|
:body-style="{ height: '100%' }"
|
||||||
|
>
|
||||||
|
<template v-if="currentCompany">
|
||||||
|
<!-- 头部 -->
|
||||||
|
<div class="mb-4 rounded bg-gray-50 p-4">
|
||||||
|
<div class="mb-3 flex items-center justify-between gap-2">
|
||||||
|
<div class="flex items-center gap-2">
|
||||||
|
<span class="text-base font-semibold">{{ currentCompany.name }}</span>
|
||||||
|
<Tag :color="currentCompany.status === 1 ? 'green' : 'red'">
|
||||||
|
{{ currentCompany.status === 1 ? '启用' : '禁用' }}
|
||||||
|
</Tag>
|
||||||
|
</div>
|
||||||
|
<div class="flex items-center gap-2">
|
||||||
|
<Button @click="selectNone">取消全选</Button>
|
||||||
|
<Button type="primary" @click="selectAll">一键全选</Button>
|
||||||
|
<Button
|
||||||
|
type="primary"
|
||||||
|
:disabled="!stats.changed"
|
||||||
|
@click="handleSave"
|
||||||
|
>
|
||||||
|
保存配置
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="flex gap-6 text-xs text-gray-500">
|
||||||
|
<span>系统菜单:<strong>{{ stats.total }}</strong></span>
|
||||||
|
<span>已配置:<strong class="text-green-600">{{ stats.company }}</strong></span>
|
||||||
|
<span>当前选择:<strong class="text-blue-600">{{ stats.selected }}</strong></span>
|
||||||
|
<span v-if="stats.changed" class="text-orange-500">(有未保存的更改)</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 菜单树 -->
|
||||||
|
<div class="flex-1 overflow-y-auto">
|
||||||
|
<Spin :spinning="menuLoading">
|
||||||
|
<Tree
|
||||||
|
v-model:checked-keys="selectedMenuIds"
|
||||||
|
:tree-data="menuTreeData"
|
||||||
|
checkable
|
||||||
|
:default-expand-all="true"
|
||||||
|
class="company-menu-tree"
|
||||||
|
@check="handleTreeCheckChange"
|
||||||
|
>
|
||||||
|
<template #title="{ title, status }">
|
||||||
|
<span>
|
||||||
|
{{ title }}
|
||||||
|
<span v-if="status === 0" class="ml-2 text-xs text-gray-400">(已禁用)</span>
|
||||||
|
</span>
|
||||||
|
</template>
|
||||||
|
</Tree>
|
||||||
|
</Spin>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<div v-else class="flex h-full flex-1 items-center justify-center text-gray-400">
|
||||||
|
<div class="text-center">
|
||||||
|
<div class="mb-2 text-5xl">👈</div>
|
||||||
|
<div>请先选择一家公司</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Card>
|
||||||
|
</Flex>
|
||||||
|
</Page>
|
||||||
|
</template>
|
||||||
+357
@@ -0,0 +1,357 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import type { CompanyVO } from '#/api/organization/company/types';
|
||||||
|
|
||||||
|
import { computed, onMounted, ref } from 'vue';
|
||||||
|
|
||||||
|
import { Page } from '@vben/common-ui';
|
||||||
|
|
||||||
|
import {
|
||||||
|
Button,
|
||||||
|
Card,
|
||||||
|
Checkbox,
|
||||||
|
Flex,
|
||||||
|
Input,
|
||||||
|
message,
|
||||||
|
Pagination,
|
||||||
|
Select,
|
||||||
|
Spin,
|
||||||
|
Tag,
|
||||||
|
} from 'ant-design-vue';
|
||||||
|
|
||||||
|
import {
|
||||||
|
batchUpdateCompanyPermissionsApi,
|
||||||
|
getCompanyPermissionIdsApi,
|
||||||
|
} from '#/api/organization/company-permission/apis';
|
||||||
|
import { getCompanyPageApi } from '#/api/organization/company';
|
||||||
|
import { getAllPermissionsApi } from '#/api/system/permission';
|
||||||
|
|
||||||
|
defineOptions({
|
||||||
|
name: 'CompanyPermissionManagePage',
|
||||||
|
});
|
||||||
|
|
||||||
|
// 搜索表单
|
||||||
|
const searchForm = ref({
|
||||||
|
name: '',
|
||||||
|
status: undefined as number | undefined,
|
||||||
|
});
|
||||||
|
|
||||||
|
// 公司列表
|
||||||
|
const companyList = ref<CompanyVO.CompanyInfoVO[]>([]);
|
||||||
|
const companyLoading = ref(false);
|
||||||
|
const companyPagination = ref({
|
||||||
|
current: 1,
|
||||||
|
pageSize: 10,
|
||||||
|
total: 0,
|
||||||
|
});
|
||||||
|
|
||||||
|
// 当前选中的公司
|
||||||
|
const currentCompany = ref<null | CompanyVO.CompanyInfoVO>(null);
|
||||||
|
|
||||||
|
// 所有权限列表
|
||||||
|
const allPermissions = ref<any[]>([]);
|
||||||
|
|
||||||
|
// 当前公司的权限ID列表
|
||||||
|
const companyPermissionIds = ref<number[]>([]);
|
||||||
|
const selectedPermissionIds = ref<number[]>([]);
|
||||||
|
|
||||||
|
// 权限加载状态
|
||||||
|
const permissionLoading = ref(false);
|
||||||
|
|
||||||
|
// 统计
|
||||||
|
const stats = computed(() => ({
|
||||||
|
total: allPermissions.value.length,
|
||||||
|
company: companyPermissionIds.value.length,
|
||||||
|
selected: selectedPermissionIds.value.length,
|
||||||
|
changed: selectedPermissionIds.value.length !== companyPermissionIds.value.length,
|
||||||
|
}));
|
||||||
|
|
||||||
|
// 按类型分组
|
||||||
|
const groupedPermissions = computed(() => {
|
||||||
|
const groups: Record<string, any[]> = {};
|
||||||
|
for (const perm of allPermissions.value) {
|
||||||
|
const type = perm.type || 'other';
|
||||||
|
if (!groups[type]) groups[type] = [];
|
||||||
|
groups[type].push(perm);
|
||||||
|
}
|
||||||
|
return groups;
|
||||||
|
});
|
||||||
|
|
||||||
|
const typeLabelMap: Record<string, string> = {
|
||||||
|
api: '接口权限',
|
||||||
|
button: '按钮权限',
|
||||||
|
data: '数据权限',
|
||||||
|
};
|
||||||
|
|
||||||
|
// 搜索公司列表
|
||||||
|
async function searchCompanies() {
|
||||||
|
companyLoading.value = true;
|
||||||
|
try {
|
||||||
|
const result = await getCompanyPageApi({
|
||||||
|
page: companyPagination.value.current,
|
||||||
|
pageSize: companyPagination.value.pageSize,
|
||||||
|
filters: {
|
||||||
|
name: searchForm.value.name || undefined,
|
||||||
|
status: searchForm.value.status,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
companyList.value = result.records;
|
||||||
|
companyPagination.value.total = result.total;
|
||||||
|
} catch (error: any) {
|
||||||
|
message.error(error?.message || '获取公司列表失败');
|
||||||
|
} finally {
|
||||||
|
companyLoading.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 选择公司
|
||||||
|
async function selectCompany(company: CompanyVO.CompanyInfoVO) {
|
||||||
|
currentCompany.value = company;
|
||||||
|
await loadCompanyPermissions();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 加载当前公司的权限
|
||||||
|
async function loadCompanyPermissions() {
|
||||||
|
if (!currentCompany.value?.id) return;
|
||||||
|
permissionLoading.value = true;
|
||||||
|
try {
|
||||||
|
const [perms, permIds] = await Promise.all([
|
||||||
|
getAllPermissionsApi(),
|
||||||
|
getCompanyPermissionIdsApi(currentCompany.value.id),
|
||||||
|
]);
|
||||||
|
const permArray = Array.isArray(perms) ? perms : (perms?.data || []);
|
||||||
|
allPermissions.value = permArray.filter((p: any) => p.status === 1);
|
||||||
|
companyPermissionIds.value = permIds || [];
|
||||||
|
selectedPermissionIds.value = [...companyPermissionIds.value];
|
||||||
|
} catch (error: any) {
|
||||||
|
message.error(error?.message || '加载权限失败');
|
||||||
|
} finally {
|
||||||
|
permissionLoading.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 切换单个权限
|
||||||
|
function togglePermission(permissionId: number, checked: boolean) {
|
||||||
|
if (checked) {
|
||||||
|
selectedPermissionIds.value.push(permissionId);
|
||||||
|
} else {
|
||||||
|
selectedPermissionIds.value = selectedPermissionIds.value.filter(
|
||||||
|
(id) => id !== permissionId,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 全选/取消全选
|
||||||
|
function selectAll() {
|
||||||
|
selectedPermissionIds.value = allPermissions.value.map((p) => p.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
function selectNone() {
|
||||||
|
selectedPermissionIds.value = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 保存
|
||||||
|
async function handleSave() {
|
||||||
|
if (!currentCompany.value?.id) return;
|
||||||
|
try {
|
||||||
|
await batchUpdateCompanyPermissionsApi(
|
||||||
|
currentCompany.value.id,
|
||||||
|
selectedPermissionIds.value,
|
||||||
|
);
|
||||||
|
message.success('权限配置保存成功');
|
||||||
|
companyPermissionIds.value = [...selectedPermissionIds.value];
|
||||||
|
} catch (error: any) {
|
||||||
|
message.error(error?.message || '保存失败');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 重置搜索
|
||||||
|
function resetSearch() {
|
||||||
|
searchForm.value = { name: '', status: undefined };
|
||||||
|
companyPagination.value.current = 1;
|
||||||
|
searchCompanies();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 分页
|
||||||
|
function handlePageChange(page: number, pageSize: number) {
|
||||||
|
companyPagination.value.current = page;
|
||||||
|
companyPagination.value.pageSize = pageSize;
|
||||||
|
searchCompanies();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 初始化
|
||||||
|
onMounted(() => {
|
||||||
|
searchCompanies();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Page :auto-content-height="true">
|
||||||
|
<Flex gap="middle" class="h-full">
|
||||||
|
<!-- 左栏:公司列表 -->
|
||||||
|
<Card
|
||||||
|
title="公司列表"
|
||||||
|
class="flex h-full max-w-[400px] flex-col"
|
||||||
|
:body-style="{
|
||||||
|
height: '100%',
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
gap: '10px',
|
||||||
|
}"
|
||||||
|
>
|
||||||
|
<!-- 搜索区域 -->
|
||||||
|
<Flex class="flex-wrap gap-2">
|
||||||
|
<Input
|
||||||
|
v-model:value="searchForm.name"
|
||||||
|
placeholder="请输入公司名称"
|
||||||
|
allow-clear
|
||||||
|
style="width: 180px; margin-right: 8px"
|
||||||
|
/>
|
||||||
|
<Select
|
||||||
|
v-model:value="searchForm.status"
|
||||||
|
placeholder="状态"
|
||||||
|
allow-clear
|
||||||
|
style="width: 100px; margin-right: 8px"
|
||||||
|
>
|
||||||
|
<Select.Option :value="1">启用</Select.Option>
|
||||||
|
<Select.Option :value="0">禁用</Select.Option>
|
||||||
|
</Select>
|
||||||
|
<Button type="primary" @click="searchCompanies">搜索</Button>
|
||||||
|
<Button @click="resetSearch">重置</Button>
|
||||||
|
</Flex>
|
||||||
|
|
||||||
|
<!-- 公司列表 -->
|
||||||
|
<Flex vertical class="flex-1 overflow-y-auto">
|
||||||
|
<Spin :spinning="companyLoading">
|
||||||
|
<Card
|
||||||
|
v-for="company in companyList"
|
||||||
|
:key="company.id"
|
||||||
|
hoverable
|
||||||
|
size="small"
|
||||||
|
:body-style="{ padding: '10px 12px' }"
|
||||||
|
class="mb-2 cursor-pointer transition-all duration-200"
|
||||||
|
:class="[
|
||||||
|
currentCompany?.id === company.id &&
|
||||||
|
'ring-primary shadow ring-1',
|
||||||
|
]"
|
||||||
|
@click="selectCompany(company)"
|
||||||
|
>
|
||||||
|
<div class="flex items-start justify-between gap-2">
|
||||||
|
<div class="min-w-0">
|
||||||
|
<div class="mb-1 flex items-center gap-2">
|
||||||
|
<span
|
||||||
|
class="inline-block h-2 w-2 rounded-full"
|
||||||
|
:class="company.status === 1 ? 'bg-green-500' : 'bg-red-500'"
|
||||||
|
></span>
|
||||||
|
<span class="truncate text-sm font-semibold">{{ company.name }}</span>
|
||||||
|
</div>
|
||||||
|
<div class="text-xs text-gray-400">ID: {{ company.id }}</div>
|
||||||
|
</div>
|
||||||
|
<Tag :color="company.status === 1 ? 'green' : 'red'">
|
||||||
|
{{ company.status === 1 ? '启用' : '禁用' }}
|
||||||
|
</Tag>
|
||||||
|
</div>
|
||||||
|
</Card>
|
||||||
|
</Spin>
|
||||||
|
|
||||||
|
<Flex justify="center" class="mt-2">
|
||||||
|
<Pagination
|
||||||
|
v-model:current="companyPagination.current"
|
||||||
|
v-model:page-size="companyPagination.pageSize"
|
||||||
|
:total="companyPagination.total"
|
||||||
|
:show-size-changer="true"
|
||||||
|
:show-quick-jumper="true"
|
||||||
|
@change="handlePageChange"
|
||||||
|
/>
|
||||||
|
</Flex>
|
||||||
|
</Flex>
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
<!-- 右栏:公司权限分配 -->
|
||||||
|
<Card
|
||||||
|
title="公司权限分配"
|
||||||
|
class="flex h-full flex-1 flex-col"
|
||||||
|
:body-style="{ height: '100%' }"
|
||||||
|
>
|
||||||
|
<template v-if="currentCompany">
|
||||||
|
<!-- 头部 -->
|
||||||
|
<div class="mb-4 rounded bg-gray-50 p-4">
|
||||||
|
<div class="mb-3 flex items-center justify-between gap-2">
|
||||||
|
<div class="flex items-center gap-2">
|
||||||
|
<span class="text-base font-semibold">{{ currentCompany.name }}</span>
|
||||||
|
<Tag :color="currentCompany.status === 1 ? 'green' : 'red'">
|
||||||
|
{{ currentCompany.status === 1 ? '启用' : '禁用' }}
|
||||||
|
</Tag>
|
||||||
|
</div>
|
||||||
|
<div class="flex items-center gap-2">
|
||||||
|
<Button @click="selectNone">取消全选</Button>
|
||||||
|
<Button type="primary" @click="selectAll">一键全选</Button>
|
||||||
|
<Button
|
||||||
|
type="primary"
|
||||||
|
:disabled="!stats.changed"
|
||||||
|
@click="handleSave"
|
||||||
|
>
|
||||||
|
保存配置
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="flex gap-6 text-xs text-gray-500">
|
||||||
|
<span>全部权限:<strong>{{ stats.total }}</strong></span>
|
||||||
|
<span>已配置:<strong class="text-green-600">{{ stats.company }}</strong></span>
|
||||||
|
<span>当前选择:<strong class="text-blue-600">{{ stats.selected }}</strong></span>
|
||||||
|
<span v-if="stats.changed" class="text-orange-500">(有未保存的更改)</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 权限列表 -->
|
||||||
|
<div class="flex-1 overflow-y-auto">
|
||||||
|
<Spin :spinning="permissionLoading">
|
||||||
|
<div class="space-y-4">
|
||||||
|
<div
|
||||||
|
v-for="(perms, type) in groupedPermissions"
|
||||||
|
:key="type"
|
||||||
|
class="rounded border p-3"
|
||||||
|
>
|
||||||
|
<div class="mb-3 text-sm font-semibold">
|
||||||
|
{{ typeLabelMap[type] || type }}
|
||||||
|
<Tag class="ml-2" color="blue">{{ perms.length }}</Tag>
|
||||||
|
</div>
|
||||||
|
<div class="grid grid-cols-2 gap-2 lg:grid-cols-3">
|
||||||
|
<div
|
||||||
|
v-for="perm in perms"
|
||||||
|
:key="perm.id"
|
||||||
|
class="flex items-center gap-2 rounded bg-white p-2 dark:bg-neutral-900"
|
||||||
|
>
|
||||||
|
<Checkbox
|
||||||
|
:checked="selectedPermissionIds.includes(perm.id)"
|
||||||
|
@change="(e: any) => togglePermission(perm.id, e.target.checked)"
|
||||||
|
>
|
||||||
|
<div class="min-w-0">
|
||||||
|
<div class="truncate text-sm">{{ perm.name }}</div>
|
||||||
|
<div class="truncate text-xs text-gray-400">{{ perm.code }}</div>
|
||||||
|
</div>
|
||||||
|
</Checkbox>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
v-if="allPermissions.length === 0 && !permissionLoading"
|
||||||
|
class="py-8 text-center text-gray-400"
|
||||||
|
>
|
||||||
|
暂无可分配的权限
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Spin>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<div v-else class="flex h-full flex-1 items-center justify-center text-gray-400">
|
||||||
|
<div class="text-center">
|
||||||
|
<div class="mb-2 text-5xl">👈</div>
|
||||||
|
<div>请先选择一家公司</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Card>
|
||||||
|
</Flex>
|
||||||
|
</Page>
|
||||||
|
</template>
|
||||||
Reference in New Issue
Block a user