From 321e19a3a57f44ae5e2ff25ee6b1ff03450588e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E4=BC=A0=E9=BE=99?= Date: Mon, 25 Apr 2022 09:51:02 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8DisHidden=E8=B7=AF?= =?UTF-8?q?=E7=94=B1=E6=9C=AA=E6=AD=A3=E7=A1=AE=E5=88=A4=E6=96=AD=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/layout/components/sidebar/SideMenu.vue | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/layout/components/sidebar/SideMenu.vue b/src/layout/components/sidebar/SideMenu.vue index 9b938fe..6989199 100644 --- a/src/layout/components/sidebar/SideMenu.vue +++ b/src/layout/components/sidebar/SideMenu.vue @@ -49,13 +49,13 @@ function getMenuItem(route, basePath = '') { icon: route.meta?.icon ? renderIcon(route.meta?.icon, { size: 16 }) : renderIcon(IconCircle, { size: 8 }), } - if (!route.children || !route.children.length) { - return menuItem - } + const visibleChildren = route.children ? route.children.filter((item) => item.name && !item.isHidden) : [] - if (route.children && route.children.length === 1) { + if (!visibleChildren.length) return menuItem + + if (visibleChildren.length === 1) { // 单个子路由处理 - const singleRoute = route.children[0] + const singleRoute = visibleChildren[0] menuItem = { label: singleRoute.meta?.title || singleRoute.name, key: singleRoute.name, @@ -64,11 +64,15 @@ function getMenuItem(route, basePath = '') { ? renderIcon(singleRoute.meta?.icon, { size: 16 }) : renderIcon(IconCircle, { size: 8 }), } - if (singleRoute.children && singleRoute.children.length) { - menuItem.children = singleRoute.children.map((item) => getMenuItem(item, menuItem.path)) + const visibleItems = singleRoute.children ? singleRoute.children.filter((item) => item.name && !item.isHidden) : [] + + if (visibleItems.length === 1) { + menuItem = getMenuItem(visibleItems[0], menuItem.path) + } else { + menuItem.children = visibleItems.map((item) => getMenuItem(item, menuItem.path)) } } else { - menuItem.children = route.children.map((item) => getMenuItem(item, menuItem.path)) + menuItem.children = visibleChildren.map((item) => getMenuItem(item, menuItem.path)) } return menuItem