diff --git a/src/views/system/menu/index.vue b/src/views/system/menu/index.vue index 5b50eb18a8f23c2ebab36da3a36cfd141e3580cc..907fef55a3c15079a97abdd70fc4182317cc65f4 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; }; /** 查询菜单下拉树结构 */