mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 08:29:20 +08:00
feat: 优化前端系统菜单和系统权限页UI和交互
This commit is contained in:
@@ -13,7 +13,6 @@ import {
|
|||||||
Flex,
|
Flex,
|
||||||
Input,
|
Input,
|
||||||
message,
|
message,
|
||||||
Pagination,
|
|
||||||
Select,
|
Select,
|
||||||
Space,
|
Space,
|
||||||
Spin,
|
Spin,
|
||||||
@@ -27,10 +26,6 @@ import {
|
|||||||
getCompanyMenuIdsApi,
|
getCompanyMenuIdsApi,
|
||||||
} from '#/api/company/menu/apis';
|
} from '#/api/company/menu/apis';
|
||||||
import { getCompanyPageApi } from '#/api/company';
|
import { getCompanyPageApi } from '#/api/company';
|
||||||
import {
|
|
||||||
SIDEBAR_LIST_SHELL_CLASS,
|
|
||||||
sidebarListRowClass,
|
|
||||||
} from '#/utils/sidebar-list-styles';
|
|
||||||
|
|
||||||
defineOptions({
|
defineOptions({
|
||||||
name: 'CompanyMenuManagePage',
|
name: 'CompanyMenuManagePage',
|
||||||
@@ -56,6 +51,7 @@ const currentCompany = ref<CompanyVO.CompanyInfoVO | null>(null);
|
|||||||
const systemMenuList = ref<any[]>([]);
|
const systemMenuList = ref<any[]>([]);
|
||||||
const companyMenuIds = ref<number[]>([]);
|
const companyMenuIds = ref<number[]>([]);
|
||||||
const selectedMenuIds = ref<number[]>([]);
|
const selectedMenuIds = ref<number[]>([]);
|
||||||
|
const menuExpandedKeys = ref<(number | string)[]>([]);
|
||||||
const menuLoading = ref(false);
|
const menuLoading = ref(false);
|
||||||
|
|
||||||
const selectedCompanyLabel = computed(() => {
|
const selectedCompanyLabel = computed(() => {
|
||||||
@@ -129,6 +125,7 @@ async function loadCompanyMenus() {
|
|||||||
systemMenuList.value = allMenus || [];
|
systemMenuList.value = allMenus || [];
|
||||||
companyMenuIds.value = menuIds || [];
|
companyMenuIds.value = menuIds || [];
|
||||||
selectedMenuIds.value = [...companyMenuIds.value];
|
selectedMenuIds.value = [...companyMenuIds.value];
|
||||||
|
menuExpandedKeys.value = (allMenus || []).map((m: { id: number }) => m.id);
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
message.error(error?.message || '加载菜单失败');
|
message.error(error?.message || '加载菜单失败');
|
||||||
} finally {
|
} finally {
|
||||||
@@ -224,9 +221,17 @@ function handleCompanyPageChange(page: number, pageSize: number) {
|
|||||||
searchCompanies();
|
searchCompanies();
|
||||||
}
|
}
|
||||||
|
|
||||||
function companyRowClass(companyId: number) {
|
const companyTotalPages = computed(() => {
|
||||||
const active = currentCompany.value?.id === companyId;
|
const { total, pageSize } = companyPagination.value;
|
||||||
return sidebarListRowClass(active, 'w-full cursor-pointer text-left');
|
return Math.max(1, Math.ceil(total / pageSize) || 1);
|
||||||
|
});
|
||||||
|
|
||||||
|
function goCompanyPage(page: number) {
|
||||||
|
const next = Math.min(companyTotalPages.value, Math.max(1, page));
|
||||||
|
if (next === companyPagination.value.current) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
handleCompanyPageChange(next, companyPagination.value.pageSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
@@ -258,16 +263,18 @@ onMounted(() => {
|
|||||||
</Space>
|
</Space>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<Flex gap="middle" class="h-full min-h-0">
|
<Flex gap="middle" class="h-full min-h-0 overflow-hidden">
|
||||||
<!-- 左:公司 -->
|
<!-- 左:公司 -->
|
||||||
<Card
|
<Card
|
||||||
class="flex h-full w-[420px] shrink-0 flex-col"
|
class="flex h-full w-[320px] shrink-0 flex-col overflow-hidden"
|
||||||
:body-style="{
|
:body-style="{
|
||||||
height: '100%',
|
height: '100%',
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
flexDirection: 'column',
|
flexDirection: 'column',
|
||||||
gap: '8px',
|
gap: '8px',
|
||||||
minHeight: 0,
|
minHeight: 0,
|
||||||
|
minWidth: 0,
|
||||||
|
overflow: 'hidden',
|
||||||
padding: '12px',
|
padding: '12px',
|
||||||
}"
|
}"
|
||||||
>
|
>
|
||||||
@@ -278,67 +285,101 @@ onMounted(() => {
|
|||||||
</span>
|
</span>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<Flex wrap="wrap" align="center" class="shrink-0 gap-2">
|
<div class="flex min-w-0 shrink-0 flex-col gap-2">
|
||||||
<Input
|
<Input
|
||||||
v-model:value="companySearchForm.name"
|
v-model:value="companySearchForm.name"
|
||||||
placeholder="公司名称"
|
placeholder="公司名称"
|
||||||
allow-clear
|
allow-clear
|
||||||
class="min-w-[140px] flex-1"
|
class="w-full min-w-0"
|
||||||
@press-enter="searchCompanies"
|
@press-enter="searchCompanies"
|
||||||
/>
|
/>
|
||||||
<Select
|
<div class="flex min-w-0 items-center gap-2">
|
||||||
v-model:value="companySearchForm.status"
|
<Select
|
||||||
placeholder="状态"
|
v-model:value="companySearchForm.status"
|
||||||
allow-clear
|
placeholder="状态"
|
||||||
class="w-[88px]"
|
allow-clear
|
||||||
:options="[
|
class="min-w-0 flex-1"
|
||||||
{ label: '启用', value: 1 },
|
:options="[
|
||||||
{ label: '禁用', value: 0 },
|
{ label: '启用', value: 1 },
|
||||||
]"
|
{ label: '禁用', value: 0 },
|
||||||
/>
|
]"
|
||||||
<Button type="primary" size="small" @click="searchCompanies">
|
|
||||||
搜索
|
|
||||||
</Button>
|
|
||||||
<Button size="small" @click="resetCompanySearch">重置</Button>
|
|
||||||
</Flex>
|
|
||||||
|
|
||||||
<Spin :spinning="companyLoading" class="flex min-h-0 flex-1 flex-col">
|
|
||||||
<div :class="SIDEBAR_LIST_SHELL_CLASS">
|
|
||||||
<Empty
|
|
||||||
v-if="!companyLoading && companyList.length === 0"
|
|
||||||
class="py-8"
|
|
||||||
description="暂无公司"
|
|
||||||
/>
|
/>
|
||||||
<div v-else class="space-y-1">
|
<Button type="primary" class="shrink-0" @click="searchCompanies">
|
||||||
<button
|
搜索
|
||||||
v-for="company in companyList"
|
</Button>
|
||||||
:key="company.id"
|
<Button class="shrink-0" @click="resetCompanySearch">重置</Button>
|
||||||
type="button"
|
</div>
|
||||||
:class="companyRowClass(company.id)"
|
</div>
|
||||||
@click="selectCompany(company)"
|
|
||||||
>
|
<div class="flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden">
|
||||||
<span class="block truncate">{{ company.name }}</span>
|
<div class="min-h-0 flex-1 overflow-y-auto">
|
||||||
<span
|
<Spin :spinning="companyLoading">
|
||||||
class="mt-0.5 block truncate text-xs font-normal text-muted-foreground"
|
<Empty
|
||||||
|
v-if="!companyLoading && companyList.length === 0"
|
||||||
|
class="py-8"
|
||||||
|
description="暂无公司"
|
||||||
|
/>
|
||||||
|
<template v-else>
|
||||||
|
<Card
|
||||||
|
v-for="company in companyList"
|
||||||
|
:key="company.id"
|
||||||
|
size="small"
|
||||||
|
:body-style="{ padding: '10px 12px' }"
|
||||||
|
class="mb-2 cursor-pointer !shadow-none last:mb-0 hover:border-primary"
|
||||||
|
:class="
|
||||||
|
currentCompany?.id === company.id
|
||||||
|
? 'border-primary bg-primary/5'
|
||||||
|
: undefined
|
||||||
|
"
|
||||||
|
@click="selectCompany(company)"
|
||||||
>
|
>
|
||||||
{{ company.status === 1 ? '启用' : '禁用' }}
|
<div class="flex items-center justify-between gap-2">
|
||||||
</span>
|
<span class="min-w-0 truncate text-sm font-medium">
|
||||||
</button>
|
{{ company.name }}
|
||||||
</div>
|
</span>
|
||||||
|
<Tag
|
||||||
|
class="m-0 shrink-0"
|
||||||
|
:color="company.status === 1 ? 'green' : 'red'"
|
||||||
|
>
|
||||||
|
{{ company.status === 1 ? '启用' : '禁用' }}
|
||||||
|
</Tag>
|
||||||
|
</div>
|
||||||
|
</Card>
|
||||||
|
</template>
|
||||||
|
</Spin>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Flex justify="center" class="mt-2 shrink-0 pt-1">
|
<div
|
||||||
<Pagination
|
class="mt-2 flex w-full min-w-0 shrink-0 items-center justify-between gap-2"
|
||||||
v-model:current="companyPagination.current"
|
>
|
||||||
v-model:page-size="companyPagination.pageSize"
|
<Button
|
||||||
:total="companyPagination.total"
|
|
||||||
size="small"
|
size="small"
|
||||||
:show-size-changer="true"
|
class="shrink-0"
|
||||||
:show-quick-jumper="true"
|
:disabled="companyPagination.current <= 1 || companyLoading"
|
||||||
@change="handleCompanyPageChange"
|
@click="goCompanyPage(companyPagination.current - 1)"
|
||||||
/>
|
>
|
||||||
</Flex>
|
上一页
|
||||||
</Spin>
|
</Button>
|
||||||
|
<span
|
||||||
|
class="min-w-0 flex-1 truncate text-center text-xs text-muted-foreground"
|
||||||
|
>
|
||||||
|
{{ companyPagination.current }} / {{ companyTotalPages }}
|
||||||
|
<span class="ml-1 opacity-70"
|
||||||
|
>({{ companyPagination.total }})</span
|
||||||
|
>
|
||||||
|
</span>
|
||||||
|
<Button
|
||||||
|
size="small"
|
||||||
|
class="shrink-0"
|
||||||
|
:disabled="
|
||||||
|
companyPagination.current >= companyTotalPages || companyLoading
|
||||||
|
"
|
||||||
|
@click="goCompanyPage(companyPagination.current + 1)"
|
||||||
|
>
|
||||||
|
下一页
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
<!-- 右:菜单分配 -->
|
<!-- 右:菜单分配 -->
|
||||||
@@ -387,19 +428,24 @@ onMounted(() => {
|
|||||||
<Spin :spinning="menuLoading">
|
<Spin :spinning="menuLoading">
|
||||||
<Tree
|
<Tree
|
||||||
v-model:checked-keys="selectedMenuIds"
|
v-model:checked-keys="selectedMenuIds"
|
||||||
|
v-model:expanded-keys="menuExpandedKeys"
|
||||||
:tree-data="menuTreeData"
|
:tree-data="menuTreeData"
|
||||||
checkable
|
checkable
|
||||||
:default-expand-all="true"
|
block-node
|
||||||
class="company-menu-tree"
|
:selectable="false"
|
||||||
@check="handleTreeCheckChange"
|
@check="handleTreeCheckChange"
|
||||||
>
|
>
|
||||||
<template #title="{ title, status }">
|
<template #title="{ title, status }">
|
||||||
<span>
|
<div class="flex min-w-0 items-center gap-2">
|
||||||
{{ title }}
|
<span class="min-w-0 truncate font-medium">{{ title }}</span>
|
||||||
<span v-if="status === 0" class="ml-2 text-xs text-gray-400">
|
<Tag
|
||||||
(已禁用)
|
v-if="status === 0"
|
||||||
</span>
|
color="default"
|
||||||
</span>
|
class="m-0 shrink-0"
|
||||||
|
>
|
||||||
|
已禁用
|
||||||
|
</Tag>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</Tree>
|
</Tree>
|
||||||
</Spin>
|
</Spin>
|
||||||
|
|||||||
-128
@@ -1,128 +0,0 @@
|
|||||||
<script setup lang="ts">
|
|
||||||
import type { PermissionVO } from '#/api/sys/permission/types';
|
|
||||||
|
|
||||||
import { createIconifyIcon } from '@vben/icons';
|
|
||||||
|
|
||||||
import { Checkbox, Tag } from 'ant-design-vue';
|
|
||||||
import type { CheckboxChangeEvent } from 'ant-design-vue/es/checkbox/interface';
|
|
||||||
|
|
||||||
const ChevronDownIcon = createIconifyIcon('lucide:chevron-down');
|
|
||||||
const ChevronRightIcon = createIconifyIcon('lucide:chevron-right');
|
|
||||||
|
|
||||||
defineOptions({ name: 'PermissionTreeNode' });
|
|
||||||
|
|
||||||
const props = defineProps<{
|
|
||||||
node: PermissionVO.PermissionInfoVO;
|
|
||||||
level: number;
|
|
||||||
expandedIds: Set<number>;
|
|
||||||
selectedIds: number[];
|
|
||||||
}>();
|
|
||||||
|
|
||||||
const emit = defineEmits<{
|
|
||||||
toggle: [id: number];
|
|
||||||
check: [id: number, checked: boolean];
|
|
||||||
}>();
|
|
||||||
|
|
||||||
function isChecked(): boolean {
|
|
||||||
if (!props.node.children || props.node.children.length === 0) {
|
|
||||||
return props.selectedIds.includes(props.node.id);
|
|
||||||
}
|
|
||||||
const allIds = getDescendantIds(props.node);
|
|
||||||
return allIds.length > 0 && allIds.every((id) => props.selectedIds.includes(id));
|
|
||||||
}
|
|
||||||
|
|
||||||
function isIndeterminate(): boolean {
|
|
||||||
if (!props.node.children || props.node.children.length === 0) return false;
|
|
||||||
const allIds = getDescendantIds(props.node);
|
|
||||||
const selectedCount = allIds.filter((id) => props.selectedIds.includes(id)).length;
|
|
||||||
return selectedCount > 0 && selectedCount < allIds.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getDescendantIds(node: PermissionVO.PermissionInfoVO): number[] {
|
|
||||||
const result: number[] = [];
|
|
||||||
function collect(n: PermissionVO.PermissionInfoVO) {
|
|
||||||
if (n.children) {
|
|
||||||
for (const child of n.children) {
|
|
||||||
result.push(child.id);
|
|
||||||
collect(child);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (node.children) {
|
|
||||||
for (const child of node.children) {
|
|
||||||
result.push(child.id);
|
|
||||||
collect(child);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
function onCheckboxChange(e: CheckboxChangeEvent) {
|
|
||||||
const checked = e.target.checked;
|
|
||||||
emit('check', props.node.id, checked);
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleToggle(id: number) {
|
|
||||||
emit('toggle', id);
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleCheck(id: number, checked: boolean) {
|
|
||||||
emit('check', id, checked);
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<div class="tree-node">
|
|
||||||
<!-- 节点行 -->
|
|
||||||
<div
|
|
||||||
class="flex items-center gap-2 py-1.5 px-2 rounded cursor-pointer hover:bg-gray-50 transition-colors"
|
|
||||||
:style="{ paddingLeft: (level * 20 + 8) + 'px' }"
|
|
||||||
>
|
|
||||||
<!-- 展开/收起图标(antd 默认图标) -->
|
|
||||||
<span
|
|
||||||
v-if="node.children && node.children.length > 0"
|
|
||||||
class="flex items-center justify-center w-4 h-4 cursor-pointer"
|
|
||||||
@click="emit('toggle', node.id)"
|
|
||||||
>
|
|
||||||
<ChevronDownIcon v-if="expandedIds.has(node.id)" class="text-xs text-gray-400" />
|
|
||||||
<ChevronRightIcon v-else class="text-xs text-gray-400" />
|
|
||||||
</span>
|
|
||||||
<span v-else class="w-4"></span>
|
|
||||||
|
|
||||||
<!-- Checkbox -->
|
|
||||||
<Checkbox
|
|
||||||
:checked="isChecked()"
|
|
||||||
:indeterminate="isIndeterminate()"
|
|
||||||
@change="onCheckboxChange"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<!-- 名称 -->
|
|
||||||
<span
|
|
||||||
class="flex-1 text-sm leading-5"
|
|
||||||
:class="node.type === 'module' ? 'font-semibold text-[var(--text-primary)]' : 'text-[var(--text-secondary)]'"
|
|
||||||
>
|
|
||||||
{{ node.name }}
|
|
||||||
</span>
|
|
||||||
|
|
||||||
<!-- Code -->
|
|
||||||
<span class="text-xs text-gray-400 mr-2">{{ node.code }}</span>
|
|
||||||
|
|
||||||
<!-- 类型标签 -->
|
|
||||||
<Tag v-if="node.type === 'module'" color="purple" class="text-xs">模块</Tag>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- 子节点 -->
|
|
||||||
<template v-if="node.children && node.children.length > 0 && expandedIds.has(node.id)">
|
|
||||||
<TreeNodeContent
|
|
||||||
v-for="child in node.children"
|
|
||||||
:key="child.id"
|
|
||||||
:node="child"
|
|
||||||
:level="level + 1"
|
|
||||||
:expanded-ids="expandedIds"
|
|
||||||
:selected-ids="selectedIds"
|
|
||||||
@toggle="handleToggle"
|
|
||||||
@check="handleCheck"
|
|
||||||
/>
|
|
||||||
</template>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
@@ -14,11 +14,11 @@ import {
|
|||||||
Flex,
|
Flex,
|
||||||
Input,
|
Input,
|
||||||
message,
|
message,
|
||||||
Pagination,
|
|
||||||
Select,
|
Select,
|
||||||
Space,
|
Space,
|
||||||
Spin,
|
Spin,
|
||||||
Tag,
|
Tag,
|
||||||
|
Tree,
|
||||||
} from 'ant-design-vue';
|
} from 'ant-design-vue';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@@ -28,16 +28,18 @@ import {
|
|||||||
import { getCompanyPageApi } from '#/api/company';
|
import { getCompanyPageApi } from '#/api/company';
|
||||||
import { getPermissionTreeApi } from '#/api/sys/permission';
|
import { getPermissionTreeApi } from '#/api/sys/permission';
|
||||||
|
|
||||||
import TreeNodeContent from './components/TreeNodeContent.vue';
|
|
||||||
import {
|
|
||||||
SIDEBAR_LIST_SHELL_CLASS,
|
|
||||||
sidebarListRowClass,
|
|
||||||
} from '#/utils/sidebar-list-styles';
|
|
||||||
|
|
||||||
defineOptions({ name: 'CompanyPermissionManagePage' });
|
defineOptions({ name: 'CompanyPermissionManagePage' });
|
||||||
|
|
||||||
const BuildingIcon = createIconifyIcon('lucide:building-2');
|
const BuildingIcon = createIconifyIcon('lucide:building-2');
|
||||||
|
|
||||||
|
type PermissionTreeNode = {
|
||||||
|
key: number;
|
||||||
|
title: string;
|
||||||
|
code?: string;
|
||||||
|
type?: string;
|
||||||
|
children?: PermissionTreeNode[];
|
||||||
|
};
|
||||||
|
|
||||||
const companySearchForm = ref({
|
const companySearchForm = ref({
|
||||||
name: '',
|
name: '',
|
||||||
status: undefined as number | undefined,
|
status: undefined as number | undefined,
|
||||||
@@ -53,7 +55,7 @@ const permissionTree = ref<PermissionVO.PermissionInfoVO[]>([]);
|
|||||||
const permissionLoading = ref(false);
|
const permissionLoading = ref(false);
|
||||||
const companyPermissionIds = ref<number[]>([]);
|
const companyPermissionIds = ref<number[]>([]);
|
||||||
const selectedPermissionIds = ref<number[]>([]);
|
const selectedPermissionIds = ref<number[]>([]);
|
||||||
const expandedIds = ref<Set<number>>(new Set());
|
const expandedKeys = ref<number[]>([]);
|
||||||
|
|
||||||
const selectedCompanyLabel = computed(() => {
|
const selectedCompanyLabel = computed(() => {
|
||||||
if (!currentCompany.value) {
|
if (!currentCompany.value) {
|
||||||
@@ -62,11 +64,26 @@ const selectedCompanyLabel = computed(() => {
|
|||||||
return currentCompany.value.name;
|
return currentCompany.value.name;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const permissionTreeData = computed(() =>
|
||||||
|
mapPermissionToTreeData(permissionTree.value),
|
||||||
|
);
|
||||||
|
|
||||||
|
const selectedLeafCount = computed(() => {
|
||||||
|
const selected = new Set(selectedPermissionIds.value);
|
||||||
|
return getAllLeafIds(permissionTree.value).filter((id) => selected.has(id))
|
||||||
|
.length;
|
||||||
|
});
|
||||||
|
|
||||||
const stats = computed(() => ({
|
const stats = computed(() => ({
|
||||||
total: countLeafPermissions(permissionTree.value),
|
total: countLeafPermissions(permissionTree.value),
|
||||||
company: companyPermissionIds.value.length,
|
company: companyPermissionIds.value.length,
|
||||||
selected: selectedPermissionIds.value.length,
|
selected: selectedLeafCount.value,
|
||||||
changed: !sameArray(selectedPermissionIds.value, companyPermissionIds.value),
|
changed: !sameArray(
|
||||||
|
getAllLeafIds(permissionTree.value).filter((id) =>
|
||||||
|
selectedPermissionIds.value.includes(id),
|
||||||
|
),
|
||||||
|
companyPermissionIds.value,
|
||||||
|
),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
function sameArray(a: number[], b: number[]): boolean {
|
function sameArray(a: number[], b: number[]): boolean {
|
||||||
@@ -75,6 +92,32 @@ function sameArray(a: number[], b: number[]): boolean {
|
|||||||
return b.every((id) => sa.has(id));
|
return b.every((id) => sa.has(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function mapPermissionToTreeData(
|
||||||
|
nodes: PermissionVO.PermissionInfoVO[],
|
||||||
|
): PermissionTreeNode[] {
|
||||||
|
return nodes.map((node) => ({
|
||||||
|
key: node.id,
|
||||||
|
title: node.name,
|
||||||
|
code: node.code,
|
||||||
|
type: node.type,
|
||||||
|
children:
|
||||||
|
node.children && node.children.length > 0
|
||||||
|
? mapPermissionToTreeData(node.children)
|
||||||
|
: undefined,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
function collectExpandableKeys(nodes: PermissionVO.PermissionInfoVO[]): number[] {
|
||||||
|
const keys: number[] = [];
|
||||||
|
for (const node of nodes) {
|
||||||
|
if (node.children && node.children.length > 0) {
|
||||||
|
keys.push(node.id);
|
||||||
|
keys.push(...collectExpandableKeys(node.children));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return keys;
|
||||||
|
}
|
||||||
|
|
||||||
async function searchCompanies() {
|
async function searchCompanies() {
|
||||||
companyLoading.value = true;
|
companyLoading.value = true;
|
||||||
try {
|
try {
|
||||||
@@ -118,20 +161,26 @@ async function loadPermissionTree() {
|
|||||||
try {
|
try {
|
||||||
const result = await getPermissionTreeApi();
|
const result = await getPermissionTreeApi();
|
||||||
permissionTree.value = result || [];
|
permissionTree.value = result || [];
|
||||||
expandedIds.value = new Set(
|
expandedKeys.value = collectExpandableKeys(result || []);
|
||||||
result?.map((n: PermissionVO.PermissionInfoVO) => n.id) || [],
|
|
||||||
);
|
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
message.error(error?.message || '获取权限树失败');
|
message.error(error?.message || '获取权限树失败');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleTreeCheckChange(
|
||||||
|
checked:
|
||||||
|
| (number | string)[]
|
||||||
|
| { checked: (number | string)[]; halfChecked: (number | string)[] },
|
||||||
|
) {
|
||||||
|
const checkedKeys = Array.isArray(checked) ? checked : checked.checked;
|
||||||
|
selectedPermissionIds.value = checkedKeys.map((k) => Number(k));
|
||||||
|
}
|
||||||
|
|
||||||
async function handleSave() {
|
async function handleSave() {
|
||||||
if (!currentCompany.value?.id) return;
|
if (!currentCompany.value?.id) return;
|
||||||
const leafIds = selectedPermissionIds.value.filter((id) => {
|
const leafIds = getAllLeafIds(permissionTree.value).filter((id) =>
|
||||||
const node = findNode(permissionTree.value, id);
|
selectedPermissionIds.value.includes(id),
|
||||||
return node && (!node.children || node.children.length === 0);
|
);
|
||||||
});
|
|
||||||
try {
|
try {
|
||||||
await batchUpdateCompanyPermissionsApi(currentCompany.value.id, leafIds);
|
await batchUpdateCompanyPermissionsApi(currentCompany.value.id, leafIds);
|
||||||
message.success('权限配置保存成功');
|
message.success('权限配置保存成功');
|
||||||
@@ -154,6 +203,19 @@ function handleCompanyPageChange(page: number, pageSize: number) {
|
|||||||
searchCompanies();
|
searchCompanies();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const companyTotalPages = computed(() => {
|
||||||
|
const { total, pageSize } = companyPagination.value;
|
||||||
|
return Math.max(1, Math.ceil(total / pageSize) || 1);
|
||||||
|
});
|
||||||
|
|
||||||
|
function goCompanyPage(page: number) {
|
||||||
|
const next = Math.min(companyTotalPages.value, Math.max(1, page));
|
||||||
|
if (next === companyPagination.value.current) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
handleCompanyPageChange(next, companyPagination.value.pageSize);
|
||||||
|
}
|
||||||
|
|
||||||
function countLeafPermissions(nodes: PermissionVO.PermissionInfoVO[]): number {
|
function countLeafPermissions(nodes: PermissionVO.PermissionInfoVO[]): number {
|
||||||
let count = 0;
|
let count = 0;
|
||||||
for (const node of nodes) {
|
for (const node of nodes) {
|
||||||
@@ -183,87 +245,6 @@ function selectNone() {
|
|||||||
selectedPermissionIds.value = [];
|
selectedPermissionIds.value = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
function onCheck(permissionId: number, checked: boolean) {
|
|
||||||
if (checked) {
|
|
||||||
const toAdd = new Set<number>([permissionId]);
|
|
||||||
getParentChain(permissionTree.value, permissionId).forEach((id) =>
|
|
||||||
toAdd.add(id),
|
|
||||||
);
|
|
||||||
getDescendantIds(permissionId).forEach((id) => toAdd.add(id));
|
|
||||||
const newSet = new Set(selectedPermissionIds.value);
|
|
||||||
toAdd.forEach((id) => newSet.add(id));
|
|
||||||
selectedPermissionIds.value = Array.from(newSet);
|
|
||||||
} else {
|
|
||||||
const toRemove = new Set<number>([
|
|
||||||
permissionId,
|
|
||||||
...getDescendantIds(permissionId),
|
|
||||||
]);
|
|
||||||
selectedPermissionIds.value = selectedPermissionIds.value.filter(
|
|
||||||
(id) => !toRemove.has(id),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function getParentChain(
|
|
||||||
nodes: PermissionVO.PermissionInfoVO[],
|
|
||||||
targetId: number,
|
|
||||||
path: number[] = [],
|
|
||||||
): number[] {
|
|
||||||
for (const node of nodes) {
|
|
||||||
if (node.id === targetId) return [...path, node.id];
|
|
||||||
if (node.children) {
|
|
||||||
const found = getParentChain(node.children, targetId, [...path, node.id]);
|
|
||||||
if (found.length > 0) return found;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
function getDescendantIds(permissionId: number): number[] {
|
|
||||||
const node = findNode(permissionTree.value, permissionId);
|
|
||||||
if (!node || !node.children) return [];
|
|
||||||
const result: number[] = [];
|
|
||||||
function collect(n: PermissionVO.PermissionInfoVO) {
|
|
||||||
if (n.children) {
|
|
||||||
for (const child of n.children) {
|
|
||||||
result.push(child.id);
|
|
||||||
collect(child);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (const child of node.children) {
|
|
||||||
result.push(child.id);
|
|
||||||
collect(child);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
function findNode(
|
|
||||||
nodes: PermissionVO.PermissionInfoVO[],
|
|
||||||
id: number,
|
|
||||||
): PermissionVO.PermissionInfoVO | null {
|
|
||||||
for (const node of nodes) {
|
|
||||||
if (node.id === id) return node;
|
|
||||||
if (node.children) {
|
|
||||||
const found = findNode(node.children, id);
|
|
||||||
if (found) return found;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
function toggleExpand(nodeId: number) {
|
|
||||||
const newSet = new Set(expandedIds.value);
|
|
||||||
if (newSet.has(nodeId)) newSet.delete(nodeId);
|
|
||||||
else newSet.add(nodeId);
|
|
||||||
expandedIds.value = newSet;
|
|
||||||
}
|
|
||||||
|
|
||||||
function companyRowClass(companyId: number) {
|
|
||||||
const active = currentCompany.value?.id === companyId;
|
|
||||||
return sidebarListRowClass(active, 'w-full cursor-pointer text-left');
|
|
||||||
}
|
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
searchCompanies();
|
searchCompanies();
|
||||||
loadPermissionTree();
|
loadPermissionTree();
|
||||||
@@ -294,16 +275,18 @@ onMounted(() => {
|
|||||||
</Space>
|
</Space>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<Flex gap="middle" class="h-full min-h-0">
|
<Flex gap="middle" class="h-full min-h-0 overflow-hidden">
|
||||||
<!-- 左:公司 -->
|
<!-- 左:公司 -->
|
||||||
<Card
|
<Card
|
||||||
class="flex h-full w-[420px] shrink-0 flex-col"
|
class="flex h-full w-[320px] shrink-0 flex-col overflow-hidden"
|
||||||
:body-style="{
|
:body-style="{
|
||||||
height: '100%',
|
height: '100%',
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
flexDirection: 'column',
|
flexDirection: 'column',
|
||||||
gap: '8px',
|
gap: '8px',
|
||||||
minHeight: 0,
|
minHeight: 0,
|
||||||
|
minWidth: 0,
|
||||||
|
overflow: 'hidden',
|
||||||
padding: '12px',
|
padding: '12px',
|
||||||
}"
|
}"
|
||||||
>
|
>
|
||||||
@@ -314,67 +297,101 @@ onMounted(() => {
|
|||||||
</span>
|
</span>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<Flex wrap="wrap" align="center" class="shrink-0 gap-2">
|
<div class="flex min-w-0 shrink-0 flex-col gap-2">
|
||||||
<Input
|
<Input
|
||||||
v-model:value="companySearchForm.name"
|
v-model:value="companySearchForm.name"
|
||||||
placeholder="公司名称"
|
placeholder="公司名称"
|
||||||
allow-clear
|
allow-clear
|
||||||
class="min-w-[140px] flex-1"
|
class="w-full min-w-0"
|
||||||
@press-enter="searchCompanies"
|
@press-enter="searchCompanies"
|
||||||
/>
|
/>
|
||||||
<Select
|
<div class="flex min-w-0 items-center gap-2">
|
||||||
v-model:value="companySearchForm.status"
|
<Select
|
||||||
placeholder="状态"
|
v-model:value="companySearchForm.status"
|
||||||
allow-clear
|
placeholder="状态"
|
||||||
class="w-[88px]"
|
allow-clear
|
||||||
:options="[
|
class="min-w-0 flex-1"
|
||||||
{ label: '启用', value: 1 },
|
:options="[
|
||||||
{ label: '禁用', value: 0 },
|
{ label: '启用', value: 1 },
|
||||||
]"
|
{ label: '禁用', value: 0 },
|
||||||
/>
|
]"
|
||||||
<Button type="primary" size="small" @click="searchCompanies">
|
|
||||||
搜索
|
|
||||||
</Button>
|
|
||||||
<Button size="small" @click="resetCompanySearch">重置</Button>
|
|
||||||
</Flex>
|
|
||||||
|
|
||||||
<Spin :spinning="companyLoading" class="flex min-h-0 flex-1 flex-col">
|
|
||||||
<div :class="SIDEBAR_LIST_SHELL_CLASS">
|
|
||||||
<Empty
|
|
||||||
v-if="!companyLoading && companyList.length === 0"
|
|
||||||
class="py-8"
|
|
||||||
description="暂无公司"
|
|
||||||
/>
|
/>
|
||||||
<div v-else class="space-y-1">
|
<Button type="primary" class="shrink-0" @click="searchCompanies">
|
||||||
<button
|
搜索
|
||||||
v-for="company in companyList"
|
</Button>
|
||||||
:key="company.id"
|
<Button class="shrink-0" @click="resetCompanySearch">重置</Button>
|
||||||
type="button"
|
</div>
|
||||||
:class="companyRowClass(company.id)"
|
</div>
|
||||||
@click="selectCompany(company)"
|
|
||||||
>
|
<div class="flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden">
|
||||||
<span class="block truncate">{{ company.name }}</span>
|
<div class="min-h-0 flex-1 overflow-y-auto">
|
||||||
<span
|
<Spin :spinning="companyLoading">
|
||||||
class="mt-0.5 block truncate text-xs font-normal text-muted-foreground"
|
<Empty
|
||||||
|
v-if="!companyLoading && companyList.length === 0"
|
||||||
|
class="py-8"
|
||||||
|
description="暂无公司"
|
||||||
|
/>
|
||||||
|
<template v-else>
|
||||||
|
<Card
|
||||||
|
v-for="company in companyList"
|
||||||
|
:key="company.id"
|
||||||
|
size="small"
|
||||||
|
:body-style="{ padding: '10px 12px' }"
|
||||||
|
class="mb-2 cursor-pointer !shadow-none last:mb-0 hover:border-primary"
|
||||||
|
:class="
|
||||||
|
currentCompany?.id === company.id
|
||||||
|
? 'border-primary bg-primary/5'
|
||||||
|
: undefined
|
||||||
|
"
|
||||||
|
@click="selectCompany(company)"
|
||||||
>
|
>
|
||||||
{{ company.status === 1 ? '启用' : '禁用' }}
|
<div class="flex items-center justify-between gap-2">
|
||||||
</span>
|
<span class="min-w-0 truncate text-sm font-medium">
|
||||||
</button>
|
{{ company.name }}
|
||||||
</div>
|
</span>
|
||||||
|
<Tag
|
||||||
|
class="m-0 shrink-0"
|
||||||
|
:color="company.status === 1 ? 'green' : 'red'"
|
||||||
|
>
|
||||||
|
{{ company.status === 1 ? '启用' : '禁用' }}
|
||||||
|
</Tag>
|
||||||
|
</div>
|
||||||
|
</Card>
|
||||||
|
</template>
|
||||||
|
</Spin>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Flex justify="center" class="mt-2 shrink-0 pt-1">
|
<div
|
||||||
<Pagination
|
class="mt-2 flex w-full min-w-0 shrink-0 items-center justify-between gap-2"
|
||||||
v-model:current="companyPagination.current"
|
>
|
||||||
v-model:page-size="companyPagination.pageSize"
|
<Button
|
||||||
:total="companyPagination.total"
|
|
||||||
size="small"
|
size="small"
|
||||||
:show-size-changer="true"
|
class="shrink-0"
|
||||||
:show-quick-jumper="true"
|
:disabled="companyPagination.current <= 1 || companyLoading"
|
||||||
@change="handleCompanyPageChange"
|
@click="goCompanyPage(companyPagination.current - 1)"
|
||||||
/>
|
>
|
||||||
</Flex>
|
上一页
|
||||||
</Spin>
|
</Button>
|
||||||
|
<span
|
||||||
|
class="min-w-0 flex-1 truncate text-center text-xs text-muted-foreground"
|
||||||
|
>
|
||||||
|
{{ companyPagination.current }} / {{ companyTotalPages }}
|
||||||
|
<span class="ml-1 opacity-70"
|
||||||
|
>({{ companyPagination.total }})</span
|
||||||
|
>
|
||||||
|
</span>
|
||||||
|
<Button
|
||||||
|
size="small"
|
||||||
|
class="shrink-0"
|
||||||
|
:disabled="
|
||||||
|
companyPagination.current >= companyTotalPages || companyLoading
|
||||||
|
"
|
||||||
|
@click="goCompanyPage(companyPagination.current + 1)"
|
||||||
|
>
|
||||||
|
下一页
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
<!-- 右:权限分配 -->
|
<!-- 右:权限分配 -->
|
||||||
@@ -407,7 +424,9 @@ onMounted(() => {
|
|||||||
全部叶子权限 {{ stats.total }} · 已配置
|
全部叶子权限 {{ stats.total }} · 已配置
|
||||||
<strong class="text-green-600">{{ stats.company }}</strong> · 当前选择
|
<strong class="text-green-600">{{ stats.company }}</strong> · 当前选择
|
||||||
<strong class="text-blue-600">{{ stats.selected }}</strong>
|
<strong class="text-blue-600">{{ stats.selected }}</strong>
|
||||||
<span v-if="stats.changed" class="text-orange-500">(有未保存更改)</span>
|
<span v-if="stats.changed" class="text-orange-500"
|
||||||
|
>(有未保存更改)</span
|
||||||
|
>
|
||||||
</span>
|
</span>
|
||||||
</template>
|
</template>
|
||||||
</div>
|
</div>
|
||||||
@@ -421,18 +440,35 @@ onMounted(() => {
|
|||||||
|
|
||||||
<div v-else class="min-h-0 flex-1 overflow-y-auto px-4 py-3 sm:px-5">
|
<div v-else class="min-h-0 flex-1 overflow-y-auto px-4 py-3 sm:px-5">
|
||||||
<Spin :spinning="permissionLoading">
|
<Spin :spinning="permissionLoading">
|
||||||
<div v-if="permissionTree.length > 0" class="py-2">
|
<Tree
|
||||||
<template v-for="node in permissionTree" :key="node.id">
|
v-if="permissionTreeData.length > 0"
|
||||||
<TreeNodeContent
|
v-model:checked-keys="selectedPermissionIds"
|
||||||
:node="node"
|
v-model:expanded-keys="expandedKeys"
|
||||||
:level="0"
|
:tree-data="permissionTreeData"
|
||||||
:expanded-ids="expandedIds"
|
checkable
|
||||||
:selected-ids="selectedPermissionIds"
|
block-node
|
||||||
@toggle="toggleExpand"
|
:selectable="false"
|
||||||
@check="onCheck"
|
@check="handleTreeCheckChange"
|
||||||
/>
|
>
|
||||||
|
<template #title="{ title, code, type }">
|
||||||
|
<div class="flex min-w-0 items-center gap-2">
|
||||||
|
<span class="min-w-0 truncate font-medium">{{ title }}</span>
|
||||||
|
<span
|
||||||
|
v-if="code"
|
||||||
|
class="shrink-0 text-xs text-muted-foreground"
|
||||||
|
>
|
||||||
|
{{ code }}
|
||||||
|
</span>
|
||||||
|
<Tag
|
||||||
|
v-if="type === 'module'"
|
||||||
|
color="purple"
|
||||||
|
class="m-0 shrink-0"
|
||||||
|
>
|
||||||
|
模块
|
||||||
|
</Tag>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</div>
|
</Tree>
|
||||||
<Empty
|
<Empty
|
||||||
v-else-if="!permissionLoading"
|
v-else-if="!permissionLoading"
|
||||||
class="py-8"
|
class="py-8"
|
||||||
|
|||||||
Reference in New Issue
Block a user