|
|
@@ -11,7 +11,7 @@
|
|
|
<logo v-if="showLogo" :collapse="isCollapse" />
|
|
|
<el-scrollbar :class="settings.sideTheme" wrap-class="scrollbar-wrapper">
|
|
|
<el-menu
|
|
|
- :default-openeds="['/myTask']"
|
|
|
+ :default-openeds="getDefaultOpeneds"
|
|
|
:default-active="activeMenu"
|
|
|
:collapse="isCollapse"
|
|
|
:background-color="
|
|
|
@@ -76,6 +76,25 @@ export default {
|
|
|
isCollapse() {
|
|
|
return !this.sidebar.opened;
|
|
|
},
|
|
|
+ // 新增:动态判断默认展开的菜单
|
|
|
+ getDefaultOpeneds() {
|
|
|
+ if(!this.$route.path.startsWith('/index')){
|
|
|
+ const currentPath = this.$route.path;
|
|
|
+ // 否则,解析当前路径的所有父级菜单并展开
|
|
|
+ const parentPaths = [];
|
|
|
+ let tempPath = currentPath;
|
|
|
+ while (tempPath.lastIndexOf('/') > 0) {
|
|
|
+ tempPath = tempPath.substring(0, tempPath.lastIndexOf('/'));
|
|
|
+ if (tempPath) { // 排除根路径
|
|
|
+ parentPaths.push(tempPath);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 去重并返回(确保父菜单层级展开)
|
|
|
+ return [...new Set(parentPaths)];
|
|
|
+ }else{
|
|
|
+ return ['/myTask'];
|
|
|
+ }
|
|
|
+ }
|
|
|
},
|
|
|
};
|
|
|
</script>
|