From 5033dc9e431a8c8e5d5fde1fde178e2bf4e909f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E5=BF=A0=E6=9E=97?= <170083662@qq.com> Date: Tue, 25 Aug 2026 19:23:33 +0800 Subject: [PATCH] =?UTF-8?q?feat(sidebar):=20=E5=A2=9E=E5=8A=A0=E5=AD=90?= =?UTF-8?q?=E8=B7=AF=E7=94=B1=E5=9B=9E=E9=80=80=E9=AB=98=E4=BA=AE=E7=88=B6?= =?UTF-8?q?=E8=8F=9C=E5=8D=95=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加 menuPaths 集合收录全站菜单路径 - 在 activeMenu 中判断子路由路径是否存在于菜单路径集合 - 对不在集合中的子路由,匹配最长前缀父菜单路径进行高亮回退 - 实现子路由(如 /vehicle/customer-archive/form)对父菜单自动高亮回退功能 - 提升侧边栏菜单选中状态的准确性和用户体验 --- src/page/index/sidebar/index.vue | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/page/index/sidebar/index.vue b/src/page/index/sidebar/index.vue index e98ce1f..ef2f0e7 100644 --- a/src/page/index/sidebar/index.vue +++ b/src/page/index/sidebar/index.vue @@ -44,6 +44,19 @@ export default { collect(this.menu); return indexes; }, + // 全站菜单路径集合,用于子路由(如 /vehicle/customer-archive/form)回退高亮父菜单 + menuPaths() { + const props = website.menu; + const set = new Set(); + const collect = list => { + (list || []).forEach(item => { + if (item[props.path]) set.add(item[props.path]); + collect(item[props.children]); + }); + }; + collect(this.menu); + return set; + }, activeMenu() { const route = this.$route; const { meta, path } = route; @@ -55,6 +68,15 @@ export default { if (fullPath !== path && this.menuIndexes.has(fullPath)) { return fullPath; } + // 子路由(如 /vehicle/customer-archive/form)自动回退高亮最长前缀匹配的父菜单 + if (!this.menuPaths.has(path)) { + const matched = [...this.menuPaths] + .filter(p => path.startsWith(p + '/')) + .sort((a, b) => b.length - a.length); + if (matched.length) { + return matched[0]; + } + } return path; }, },