Commit 41c6aa91478ced9f3eeac98563c1500cdd1cfa6f
1 parent
63b7ee09
v3.5.0 兼容顶部栏一级菜单内部跳转
Showing
1 changed file
with
27 additions
and
13 deletions
yudao-ui-admin/src/components/TopNav/index.vue
| ... | ... | @@ -30,9 +30,6 @@ |
| 30 | 30 | <script> |
| 31 | 31 | import { constantRoutes } from "@/router"; |
| 32 | 32 | |
| 33 | -// 不需要激活的路由 | |
| 34 | -const noactiveList = ["/user/profile", "/dict/type", "/gen/edit", "/job/log"]; | |
| 35 | - | |
| 36 | 33 | export default { |
| 37 | 34 | data() { |
| 38 | 35 | return { |
| ... | ... | @@ -40,6 +37,8 @@ export default { |
| 40 | 37 | visibleNumber: 5, |
| 41 | 38 | // 是否为首次加载 |
| 42 | 39 | isFrist: false, |
| 40 | + // 当前激活菜单的 index | |
| 41 | + currentIndex: undefined | |
| 43 | 42 | }; |
| 44 | 43 | }, |
| 45 | 44 | computed: { |
| ... | ... | @@ -48,7 +47,12 @@ export default { |
| 48 | 47 | let topMenus = []; |
| 49 | 48 | this.routers.map((menu) => { |
| 50 | 49 | if (menu.hidden !== true) { |
| 51 | - topMenus.push(menu); | |
| 50 | + // 兼容顶部栏一级菜单内部跳转 | |
| 51 | + if (menu.path === "/") { | |
| 52 | + topMenus.push(menu.children[0]); | |
| 53 | + } else { | |
| 54 | + topMenus.push(menu); | |
| 55 | + } | |
| 52 | 56 | } |
| 53 | 57 | }); |
| 54 | 58 | return topMenus; |
| ... | ... | @@ -63,7 +67,11 @@ export default { |
| 63 | 67 | this.routers.map((router) => { |
| 64 | 68 | for (var item in router.children) { |
| 65 | 69 | if (router.children[item].parentPath === undefined) { |
| 66 | - router.children[item].path = router.path + "/" + router.children[item].path; | |
| 70 | + if(router.path === "/") { | |
| 71 | + router.children[item].path = "/redirect/" + router.children[item].path; | |
| 72 | + } else { | |
| 73 | + router.children[item].path = router.path + "/" + router.children[item].path; | |
| 74 | + } | |
| 67 | 75 | router.children[item].parentPath = router.path; |
| 68 | 76 | } |
| 69 | 77 | childrenMenus.push(router.children[item]); |
| ... | ... | @@ -75,12 +83,6 @@ export default { |
| 75 | 83 | activeMenu() { |
| 76 | 84 | const path = this.$route.path; |
| 77 | 85 | let activePath = this.routers[0].path; |
| 78 | - var noactive = noactiveList.some(function (item) { | |
| 79 | - return path.indexOf(item) !== -1; | |
| 80 | - }); | |
| 81 | - if (noactive) { | |
| 82 | - return; | |
| 83 | - } | |
| 84 | 86 | if (path.lastIndexOf("/") > 0) { |
| 85 | 87 | const tmpPath = path.substring(1, path.length); |
| 86 | 88 | activePath = "/" + tmpPath.substring(0, tmpPath.indexOf("/")); |
| ... | ... | @@ -91,7 +93,11 @@ export default { |
| 91 | 93 | activePath = "index"; |
| 92 | 94 | } |
| 93 | 95 | } |
| 94 | - this.activeRoutes(activePath); | |
| 96 | + var routes = this.activeRoutes(activePath); | |
| 97 | + if (routes.length === 0) { | |
| 98 | + activePath = this.currentIndex || this.routers[0].path | |
| 99 | + this.activeRoutes(activePath); | |
| 100 | + } | |
| 95 | 101 | return activePath; |
| 96 | 102 | }, |
| 97 | 103 | }, |
| ... | ... | @@ -112,10 +118,15 @@ export default { |
| 112 | 118 | }, |
| 113 | 119 | // 菜单选择事件 |
| 114 | 120 | handleSelect(key, keyPath) { |
| 121 | + this.currentIndex = key; | |
| 115 | 122 | if (key.indexOf("http://") !== -1 || key.indexOf("https://") !== -1) { |
| 116 | 123 | // http(s):// 路径新窗口打开 |
| 117 | 124 | window.open(key, "_blank"); |
| 125 | + } else if (key.indexOf("/redirect") !== -1) { | |
| 126 | + // /redirect 路径内部打开 | |
| 127 | + this.$router.push({ path: key.replace("/redirect", "") }); | |
| 118 | 128 | } else { |
| 129 | + // 显示左侧联动菜单 | |
| 119 | 130 | this.activeRoutes(key); |
| 120 | 131 | } |
| 121 | 132 | }, |
| ... | ... | @@ -129,7 +140,10 @@ export default { |
| 129 | 140 | } |
| 130 | 141 | }); |
| 131 | 142 | } |
| 132 | - this.$store.commit("SET_SIDEBAR_ROUTERS", routes); | |
| 143 | + if(routes.length > 0) { | |
| 144 | + this.$store.commit("SET_SIDEBAR_ROUTERS", routes); | |
| 145 | + } | |
| 146 | + return routes; | |
| 133 | 147 | } |
| 134 | 148 | }, |
| 135 | 149 | }; | ... | ... |