From 3dbfb971373c1ae0bf0bca0b055f493a9ad106d3 Mon Sep 17 00:00:00 2001 From: Asoka Date: Fri, 6 Jun 2025 13:13:07 +0800 Subject: [PATCH] =?UTF-8?q?feat=20=E5=9B=9B=E7=BA=A7=E8=B7=AF=E7=94=B1?= =?UTF-8?q?=E5=88=B7=E6=96=B0=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/layout/navMenu/horizontal.vue | 235 +++++++++++++++++++++++++++--- src/layout/navMenu/subItem.vue | 15 +- src/layout/navMenu/vertical.vue | 44 +++++- 3 files changed, 270 insertions(+), 24 deletions(-) diff --git a/src/layout/navMenu/horizontal.vue b/src/layout/navMenu/horizontal.vue index 0bebd5e..2a031a2 100644 --- a/src/layout/navMenu/horizontal.vue +++ b/src/layout/navMenu/horizontal.vue @@ -51,13 +51,12 @@ diff --git a/src/layout/navMenu/vertical.vue b/src/layout/navMenu/vertical.vue index 3be152e..fd0fc31 100644 --- a/src/layout/navMenu/vertical.vue +++ b/src/layout/navMenu/vertical.vue @@ -81,7 +81,13 @@ watch( // 订阅水平菜单发送的菜单数据 mittBus.on('setSendColumnsChildren', (res) => { + console.log('📨 [Vertical Menu] 接收到水平菜单数据:', { + event: 'setSendColumnsChildren', + data: res, + childrenLength: res.children?.length || 0 + }) localMenuList.value = res.children || [] + console.log('📨 [Vertical Menu] 更新本地菜单列表:', localMenuList.value?.length) }) // 获取父级菜单数据 @@ -93,9 +99,27 @@ const getThemeConfig = computed(() => { // 菜单高亮(详情时,父级高亮) const setParentHighlight = (currentRoute: RouteToFrom) => { const { path, meta } = currentRoute + console.log('🔍 [Vertical Menu] setParentHighlight - 路由信息:', { + path, + meta, + isDynamic: meta?.isDynamic, + isDynamicPath: meta?.isDynamicPath, + isHide: meta?.isHide + }) + const pathSplit = meta?.isDynamic ? meta.isDynamicPath!.split('/') : path!.split('/') - if (pathSplit.length >= 4 && meta?.isHide) return pathSplit.splice(0, 3).join('/') - else return path + console.log('🔍 [Vertical Menu] setParentHighlight - 路径分割:', pathSplit) + + let highlightPath = '' + if (pathSplit.length >= 4 && meta?.isHide) { + highlightPath = pathSplit.splice(0, 3).join('/') + console.log('🔍 [Vertical Menu] setParentHighlight - 隐藏路由高亮父级:', highlightPath) + } else { + highlightPath = path! + console.log('🔍 [Vertical Menu] setParentHighlight - 常规路由高亮:', highlightPath) + } + + return highlightPath } // 打开外部链接 const onALinkClick = (val: RouteItem) => { @@ -103,12 +127,28 @@ const onALinkClick = (val: RouteItem) => { } // 页面加载时 onMounted(() => { + console.log('🚀 [Vertical Menu] onMounted - 初始化菜单:', { + currentRoute: route.path, + menuLists: menuLists.value?.length + }) state.defaultActive = setParentHighlight(route) + console.log('🚀 [Vertical Menu] onMounted - 设置默认激活菜单:', state.defaultActive) }) // 路由更新时 onBeforeRouteUpdate((to) => { + console.log('🔄 [Vertical Menu] onBeforeRouteUpdate - 路由更新:', { + from: route.path, + to: to.path, + meta: to.meta + }) state.defaultActive = setParentHighlight(to) + console.log('🔄 [Vertical Menu] onBeforeRouteUpdate - 更新默认激活菜单:', state.defaultActive) + const clientWidth = document.body.clientWidth + console.log('🔄 [Vertical Menu] onBeforeRouteUpdate - 屏幕宽度检查:', { + clientWidth, + needCollapse: clientWidth < 1000 + }) if (clientWidth < 1000) themeConfig.value.isCollapse = false }) // 设置菜单的收起/展开