diff --git a/src/views/system/menu/index.vue b/src/views/system/menu/index.vue
index 99e1f9d7652edf957876616040482e27887997fd..11c5ea7f1c24b4ec1be43607b5b77fc8cd6d0448 100644
--- a/src/views/system/menu/index.vue
+++ b/src/views/system/menu/index.vue
@@ -28,7 +28,9 @@
新增
- 级联删除
+ 级联删除
@@ -388,12 +390,16 @@ const getList = async () => {
}
tempMap[parentId].push(menu);
}
+ // 创建一个当前所有 menuId 的 Set,用于查找父菜单是否存在于当前数据中
+ const menuIdSet = new Set();
// 设置有没有子菜单
for (const menu of res.data) {
menu['hasChildren'] = tempMap[menu.menuId]?.length > 0;
+ menuIdSet.add(menu.menuId);
}
menuChildrenListMap.value = tempMap;
- menuList.value = tempMap[0] || [];
+ // 找出所有父ID不在当前菜单ID集合中的菜单项,作为新的顶层菜单
+ menuList.value = res.data.filter((menu) => !menuIdSet.has(menu.parentId));
// 根据新数据重新加载子菜单数据
refreshAllExpandMenuData();
loading.value = false;