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; }, },