From 01d83e21d1d9600a74f28325be4e7e4831f52a76 Mon Sep 17 00:00:00 2001 From: "Ray.Hao" <1490493387@qq.com> Date: Sun, 25 May 2025 07:44:17 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=B7=B7=E5=90=88=E5=B8=83=E5=B1=80?= =?UTF-8?q?=E5=94=AF=E4=B8=80=E5=AD=90=E8=8F=9C=E5=8D=95=E7=9A=84=E7=9B=AE?= =?UTF-8?q?=E5=BD=95=E6=A0=87=E9=A2=98=E4=B8=8D=E6=98=BE=E7=A4=BA=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/layouts/components/Menu/MixTopMenu.vue | 33 ++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src/layouts/components/Menu/MixTopMenu.vue b/src/layouts/components/Menu/MixTopMenu.vue index 21ac34c3..6e18cc05 100644 --- a/src/layouts/components/Menu/MixTopMenu.vue +++ b/src/layouts/components/Menu/MixTopMenu.vue @@ -20,8 +20,8 @@ " @select="handleMenuSelect" > - - + + @@ -52,6 +52,35 @@ const sidebarColorScheme = computed(() => settingsStore.sidebarColorScheme); // 顶部菜单列表 const topMenus = ref([]); +// 处理后的顶部菜单列表 - 智能显示唯一子菜单的标题 +const processedTopMenus = computed(() => { + return topMenus.value.map((route) => { + // 如果路由设置了 alwaysShow=true,或者没有子菜单,直接返回原路由 + if (route.meta?.alwaysShow || !route.children || route.children.length === 0) { + return route; + } + + // 过滤出非隐藏的子菜单 + const visibleChildren = route.children.filter((child) => !child.meta?.hidden); + + // 如果只有一个非隐藏的子菜单,显示子菜单的信息 + if (visibleChildren.length === 1) { + const onlyChild = visibleChildren[0]; + return { + ...route, + meta: { + ...route.meta, + title: onlyChild.meta?.title || route.meta?.title, + icon: onlyChild.meta?.icon || route.meta?.icon, + }, + }; + } + + // 其他情况返回原路由 + return route; + }); +}); + // 获取当前路由路径的顶部菜单路径 const activeTopMenuPath = useRoute().path.split("/").filter(Boolean).length > 1