refactor: 菜单管理 改为节点懒加载(去除展开全部功能) 关闭虚拟滚动(可自行开启)

This commit is contained in:
dap 2025-09-10 11:47:19 +08:00
parent 7c65fec38f
commit 4fc3ba568f
3 changed files with 53 additions and 13 deletions

View File

@ -24,6 +24,7 @@
- 流程相关样式更新 - 流程相关样式更新
- 请假申请 表单更改为drawer方式 替换新页面打开 - 请假申请 表单更改为drawer方式 替换新页面打开
- API加密 迁移到@vben/utils下 - API加密 迁移到@vben/utils下
- 菜单管理 改为节点懒加载(去除展开全部功能) 关闭虚拟滚动(可自行开启)
**OTHERS** **OTHERS**

View File

@ -62,6 +62,8 @@ export const columns: VxeGridProps['columns'] = [
field: 'menuName', field: 'menuName',
treeNode: true, treeNode: true,
width: 200, width: 200,
// 层级更明显显示
align: 'left',
slots: { slots: {
// 需要i18n支持 否则返回原始值 // 需要i18n支持 否则返回原始值
default: ({ row }) => $t(row.menuName), default: ({ row }) => $t(row.menuName),

View File

@ -9,7 +9,12 @@ import { computed, ref } from 'vue';
import { useAccess } from '@vben/access'; import { useAccess } from '@vben/access';
import { Fallback, Page, useVbenDrawer } from '@vben/common-ui'; import { Fallback, Page, useVbenDrawer } from '@vben/common-ui';
import { $t } from '@vben/locales'; import { $t } from '@vben/locales';
import { eachTree, getVxePopupContainer, treeToList } from '@vben/utils'; import {
eachTree,
getVxePopupContainer,
listToTree,
treeToList,
} from '@vben/utils';
import { Popconfirm, Space, Switch, Tooltip } from 'ant-design-vue'; import { Popconfirm, Space, Switch, Tooltip } from 'ant-design-vue';
@ -47,29 +52,47 @@ const gridOptions: VxeGridProps = {
const resp = await menuList({ const resp = await menuList({
...formValues, ...formValues,
}); });
return { rows: resp }; //
const treeData = listToTree(resp, { id: 'menuId', pid: 'parentId' });
// hasChildren
eachTree(treeData, (item) => {
item.hasChildren = !!(item.children && item.children.length > 0);
});
console.log(treeData);
return { rows: treeData };
}, },
}, },
}, },
rowConfig: { rowConfig: {
keyField: 'menuId', keyField: 'menuId',
//
isCurrent: true,
}, },
/** /**
* 开启虚拟滚动 * 开启虚拟滚动
* 数据量小可以选择关闭 * 数据量小可以选择关闭
* 如果遇到样式问题(空白错位 滚动等)可以选择关闭虚拟滚动 * 如果遇到样式问题(空白错位 滚动等)可以选择关闭虚拟滚动
*
* 由于已经重构为懒加载 不需要虚拟滚动(如果你觉得卡顿 依旧可以选择开启)
*/ */
scrollY: { // scrollY: {
enabled: true, // enabled: true,
gt: 0, // gt: 0,
}, // },
treeConfig: { treeConfig: {
parentField: 'parentId', parentField: 'parentId',
rowField: 'menuId', rowField: 'menuId',
// tree vxe // 使hasChild
transform: true, transform: false,
// //
reserve: true, reserve: true,
//
hasChildField: 'hasChildren',
//
lazy: true,
// children
loadMethod: ({ row }) => row.children ?? [],
}, },
id: 'system-menu-index', id: 'system-menu-index',
}; };
@ -173,25 +196,29 @@ const isAdmin = computed(() => {
<template> <template>
<Page v-if="isAdmin" :auto-content-height="true"> <Page v-if="isAdmin" :auto-content-height="true">
<BasicTable table-title="菜单列表" table-title-help="双击展开/收起子菜单"> <BasicTable
id="system-menu-table"
table-title="菜单列表"
table-title-help="双击展开/收起子菜单"
:style="{ '--vxe-ui-table-row-current-background-color': '#1677ff' }"
>
<template #toolbar-tools> <template #toolbar-tools>
<Space> <Space>
<Tooltip title="删除菜单以及子菜单"> <Tooltip title="删除菜单以及子菜单">
<div <div
v-access:role="['superadmin']" v-access:role="['superadmin']"
v-access:code="['system:menu:remove']" v-access:code="['system:menu:remove']"
class="flex items-center" class="mr-2 flex items-center"
> >
<span class="mr-2 text-sm text-[#666666]">级联删除</span> <span class="mr-2 text-sm text-[#666666]">级联删除</span>
<Switch v-model:checked="cascadingDeletion" /> <Switch v-model:checked="cascadingDeletion" />
</div> </div>
</Tooltip> </Tooltip>
<a-button @click="setExpandOrCollapse(false)"> <a-button @click="setExpandOrCollapse(false)">
{{ $t('pages.common.collapse') }} {{ $t('pages.common.collapse') }}
</a-button> </a-button>
<a-button @click="setExpandOrCollapse(true)">
{{ $t('pages.common.expand') }}
</a-button>
<a-button <a-button
type="primary" type="primary"
v-access:code="['system:menu:add']" v-access:code="['system:menu:add']"
@ -243,3 +270,13 @@ const isAdmin = computed(() => {
</Page> </Page>
<Fallback v-else description="您没有菜单管理的访问权限" status="403" /> <Fallback v-else description="您没有菜单管理的访问权限" status="403" />
</template> </template>
<style lang="scss">
#system-menu-table > .vxe-grid {
--vxe-ui-table-row-current-background-color: hsl(var(--primary-100));
html.dark & {
--vxe-ui-table-row-current-background-color: hsl(var(--primary-800));
}
}
</style>