Przeglądaj źródła

一级目录跳转

panhui 5 lat temu
rodzic
commit
01e7547e77

+ 13 - 2
src/main/vue/src/components/SysMenu.vue

@@ -4,8 +4,10 @@
     </el-menu-item>
     <el-submenu v-else :index="'' + menu.id">
         <template slot="title">
-            <i class="fa-fw" :class="menu.icon" v-if="menu.icon"></i>
-            <span slot="title">{{ menu.name }}</span>
+            <div @click="goPath(menu.path, '' + menu.id, menu.children)">
+                <i class="fa-fw" :class="menu.icon" v-if="menu.icon"></i>
+                <span slot="title">{{ menu.name }}</span>
+            </div>
         </template>
         <sys-menu v-for="item in menu.children" :menu="item" :key="item.id"></sys-menu>
     </el-submenu>
@@ -25,6 +27,15 @@ export default {
     methods: {
         click(e) {
             console.log(e);
+        },
+        goPath(path, index, children) {
+            let child = children.find(item => {
+                return this.$route.path === item.path && this.$route;
+            });
+            if (path && this.$route && this.$route.path !== path && !child) {
+                this.$router.push(path);
+                this.$emit('open', index);
+            }
         }
     },
     computed: {

+ 18 - 1
src/main/vue/src/views/Admin.vue

@@ -13,8 +13,9 @@
                 :default-active="activeMenu"
                 style="border-right: 1px solid #545c64;"
                 class="el-menu-vertical-demo"
+                ref="menu"
             >
-                <sys-menu v-for="item in menus" :menu="item" :key="item.id"> </sys-menu>
+                <sys-menu v-for="item in menus" @open="open" :menu="item" :key="item.id"> </sys-menu>
             </el-menu>
         </el-aside>
         <el-container>
@@ -191,6 +192,15 @@ export default {
                         parents_copy.push(i);
                         this.menuPath = parents_copy.map(i => i.name);
                         this.activeMenu = '' + i.id;
+                        if (i.children) {
+                            let child = i.children.find(_child => {
+                                return _child.path === path;
+                            });
+                            if (!!child) {
+                                parents_copy.push(i);
+                                findActiveMenu(parents_copy, i.children);
+                            }
+                        }
                     } else {
                         if (i.children) {
                             parents_copy.push(i);
@@ -280,6 +290,13 @@ export default {
                 this.captcha = res.image;
                 this.pwdForm.key = res.key;
             });
+        },
+        open(index) {
+            this.$nextTick(() => {
+                setTimeout(() => {
+                    this.$refs.menu.open(index);
+                }, 100);
+            });
         }
     },
     watch: {