From 8afe7c3931565029fec28f20d427027b69ada26f Mon Sep 17 00:00:00 2001 From: lau <1807121535@qq.com> Date: Tue, 24 Jun 2025 09:25:13 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E8=8F=9C=E5=8D=95?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=E6=87=92=E5=8A=A0=E8=BD=BD=E5=90=8E=EF=BC=8C?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=95=B0=E6=8D=AE=E6=B2=A1=E6=9C=89=E5=88=B7?= =?UTF-8?q?=E6=96=B0=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/system/menu/index.vue | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/views/system/menu/index.vue b/src/views/system/menu/index.vue index 5b50eb18..907fef55 100644 --- a/src/views/system/menu/index.vue +++ b/src/views/system/menu/index.vue @@ -302,6 +302,7 @@ const { sys_show_hide, sys_normal_disable } = toRefs(proxy?.useDict('sys_sh const menuList = ref([]); const menuChildrenListMap = ref({}); +const menuExpandMap = ref({}); const loading = ref(true); const showSearch = ref(true); const menuOptions = ref([]); @@ -346,7 +347,35 @@ const { queryParams, form, rules } = toRefs>(data) /** 获取子菜单列表 */ const getChildrenList = async (row: any, treeNode: unknown, resolve: (data: any[]) => void) => { - resolve(menuChildrenListMap.value[row.menuId] || []); + menuExpandMap.value[row.menuId] = { row, treeNode, resolve }; + const children = menuChildrenListMap.value[row.menuId] || []; + // 菜单的子菜单清空后关闭展开 + if (children.length == 0) { + // fix: 处理当菜单只有一个子菜单并被删除,需要将父菜单的展开状态关闭 + menuTableRef.value?.updateKeyChildren(row.menuId, children); + } + resolve(children); +}; + +/** 刷新展开的菜单数据 */ +const refreshLoadTree = (parentId: string | number) => { + if (menuExpandMap.value[parentId]) { + const { row, treeNode, resolve } = menuExpandMap.value[parentId]; + if (row) { + getChildrenList(row, treeNode, resolve); + if (row.parentId) { + const grandpaMenu = menuExpandMap.value[row.parentId]; + getChildrenList(grandpaMenu.row, grandpaMenu.treeNode, grandpaMenu.resolve); + } + } + } +}; + +/** 重新加载所有已展开的菜单的数据 */ +const refreshAllExpandMenuData = () => { + for (const menuId in menuExpandMap.value) { + refreshLoadTree(menuId); + } }; /** 查询菜单列表 */ @@ -369,6 +398,8 @@ const getList = async () => { } menuChildrenListMap.value = tempMap; menuList.value = tempMap[0] || []; + // 根据新数据重新加载子菜单数据 + refreshAllExpandMenuData(); loading.value = false; }; /** 查询菜单下拉树结构 */ -- Gitee