From 1a8174885f7d4ce312dff409a01f32fb3e0380c1 Mon Sep 17 00:00:00 2001
From: lixiangyan1314 <1915766026@qq.com>
Date: Sun, 19 Sep 2021 09:36:24 +0800
Subject: [PATCH] =?UTF-8?q?topnav=E6=A8=A1=E5=BC=8F=E8=8F=9C=E5=8D=95?=
=?UTF-8?q?=E4=BF=AE=E6=94=B9?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
ruoyi-ui/src/components/TopNav/index.vue | 58 +++++++++++++++++++-----
1 file changed, 47 insertions(+), 11 deletions(-)
diff --git a/ruoyi-ui/src/components/TopNav/index.vue b/ruoyi-ui/src/components/TopNav/index.vue
index 1b7c4d9e..907c40ba 100644
--- a/ruoyi-ui/src/components/TopNav/index.vue
+++ b/ruoyi-ui/src/components/TopNav/index.vue
@@ -6,7 +6,7 @@
>
+ >
{{ item.meta.title }}
@@ -19,7 +19,7 @@
:index="item.path"
:key="index"
v-if="index >= visibleNumber"
- >
+ >
{{ item.meta.title }}
@@ -52,9 +52,9 @@ export default {
if (menu.hidden !== true) {
// 兼容顶部栏一级菜单内部跳转
if (menu.path === "/") {
- topMenus.push(menu.children[0]);
+ topMenus.push(menu.children[0]);
} else {
- topMenus.push(menu);
+ topMenus.push(menu);
}
}
});
@@ -112,13 +112,19 @@ export default {
beforeDestroy() {
window.removeEventListener('resize', this.setVisibleNumber)
},
- mounted() {
+ /**
+ @desc: this.setVisibleNumber()原先在mounted()中,但是会引起一些问题
+ 1. 主菜单数量大于 visibleNumber时(默认设置为5),无法显示当前选中的主菜单
+ 2. 点击5后面的主菜单下的子菜单,也无法显示当主菜单选中
+ */
+ created() {
this.setVisibleNumber();
},
methods: {
// 根据宽度计算设置显示栏数
setVisibleNumber() {
- const width = document.body.getBoundingClientRect().width / 3;
+ // 此处为了显示更多个菜单
+ const width = document.body.getBoundingClientRect().width / 2.2;
this.visibleNumber = parseInt(width / 85);
},
// 默认激活的路由
@@ -144,6 +150,31 @@ export default {
} else {
// 显示左侧联动菜单
this.activeRoutes(key);
+
+ /**
+ @desc: 此模式为开启TopNav,
+ 点击主菜单时,默认跳转到第一个子菜单
+ */
+ let myRoutes = [];
+ if (this.childrenMenus && this.childrenMenus.length > 0) {
+ this.childrenMenus.map((item) => {
+ if (key == item.parentPath || (key == "index" && "" == item.path)) {
+ myRoutes.push(item);
+ }
+ });
+ }
+ setTimeout(() => {
+ if(!!(myRoutes[0].path)) {
+ this.$router.replace({
+ path: myRoutes[0].path
+ })
+ } else {
+ this.$router.replace({
+ path: '/index'
+ })
+ }
+ }, 200)
+
}
},
// 当前激活的路由
@@ -161,7 +192,7 @@ export default {
}
return routes;
},
- ishttp(url) {
+ ishttp(url) {
return url.indexOf('http://') !== -1 || url.indexOf('https://') !== -1
}
},
@@ -169,10 +200,11 @@ export default {