瀏覽代碼

11482-【CR】【投资系统】增加审批流程-动态侧边菜单显示

hxy 3 周之前
父節點
當前提交
daa6163939
共有 1 個文件被更改,包括 20 次插入1 次删除
  1. 20 1
      ruoyi-ui/src/layout/components/Sidebar/index.vue

+ 20 - 1
ruoyi-ui/src/layout/components/Sidebar/index.vue

@@ -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>