From 720c822bb3a63cd7c0c970d60756f58c63f811b3 Mon Sep 17 00:00:00 2001 From: lau <1807121535@qq.com> Date: Sun, 22 Jun 2025 21:25:05 +0800 Subject: [PATCH] =?UTF-8?q?update:=20=E4=BC=98=E5=8C=96=E8=8F=9C=E5=8D=95?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E6=B8=B2=E6=9F=93=E6=96=B9=E5=BC=8F=E9=81=BF?= =?UTF-8?q?=E5=85=8D=E9=95=BF=E6=97=B6=E9=97=B4=E5=8D=A1=E4=BD=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/system/menu/index.vue | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/src/views/system/menu/index.vue b/src/views/system/menu/index.vue index 67d3c19..273757f 100644 --- a/src/views/system/menu/index.vue +++ b/src/views/system/menu/index.vue @@ -45,6 +45,8 @@ border :tree-props="{ children: 'children', hasChildren: 'hasChildren' }" :default-expand-all="isExpandAll" + lazy + :load="getChildrenList" > @@ -299,6 +301,7 @@ const { proxy } = getCurrentInstance() as ComponentInternalInstance; const { sys_show_hide, sys_normal_disable } = toRefs(proxy?.useDict('sys_show_hide', 'sys_normal_disable')); const menuList = ref([]); +const menuChildrenListMap = ref({}); const loading = ref(true); const showSearch = ref(true); const menuOptions = ref([]); @@ -340,14 +343,34 @@ const data = reactive>({ const menuTableRef = ref(); const { queryParams, form, rules } = toRefs>(data); + +/** 获取子菜单列表 */ +const getChildrenList = async (row: any, treeNode: unknown, resolve: (data: any[]) => void) => { + loading.value = true; + resolve(menuChildrenListMap.value[row.menuId] || []); + loading.value = false; +}; + /** 查询菜单列表 */ const getList = async () => { loading.value = true; const res = await listMenu(queryParams.value); - const data = proxy?.handleTree(res.data, 'menuId'); - if (data) { - menuList.value = data; + + const tempMap = {}; + // 存储 父菜单:子菜单列表 + for (const menu of res.data) { + const parentId = menu.parentId; + if (!tempMap[parentId]) { + tempMap[parentId] = []; + } + tempMap[parentId].push(menu); } + // 设置有没有子菜单 + for (const menu of res.data) { + menu['hasChildren'] = tempMap[menu.menuId]?.length > 0; + } + menuChildrenListMap.value = tempMap; + menuList.value = tempMap[0] || []; loading.value = false; }; /** 查询菜单下拉树结构 */