Procházet zdrojové kódy

固定顶部导航栏&窗口大小改变实时更新栏数

RuoYi před 5 roky
rodič
revize
8e1a9a2433

+ 8 - 9
ruoyi-ui/src/components/TopNav/index.vue

@@ -95,21 +95,20 @@ export default {
95 95
       return activePath;
96 96
     },
97 97
   },
98
+  beforeMount() {
99
+    window.addEventListener('resize', this.setVisibleNumber)
100
+  },
101
+  beforeDestroy() {
102
+    window.removeEventListener('resize', this.setVisibleNumber)
103
+  },
98 104
   mounted() {
99 105
     this.setVisibleNumber();
100 106
   },
101 107
   methods: {
102 108
     // 根据宽度计算设置显示栏数
103 109
     setVisibleNumber() {
104
-      const width = document.body.getBoundingClientRect().width - 380;
105
-      const elWidth = this.$el.getBoundingClientRect().width;
106
-      const menuItemNodes = this.$el.children;
107
-      const menuWidth = Array.from(menuItemNodes).map(
108
-        (i) => i.getBoundingClientRect().width
109
-      );
110
-      this.visibleNumber = (
111
-        parseInt(width - elWidth) / parseInt(menuWidth)
112
-      ).toFixed(0);
110
+      const width = document.body.getBoundingClientRect().width / 3;
111
+      this.visibleNumber = parseInt(width / 85);
113 112
     },
114 113
     // 菜单选择事件
115 114
     handleSelect(key, keyPath) {

+ 6 - 1
ruoyi-ui/src/layout/components/Navbar.vue

@@ -3,7 +3,7 @@
3 3
     <hamburger id="hamburger-container" :is-active="sidebar.opened" class="hamburger-container" @toggleClick="toggleSideBar" />
4 4
 
5 5
     <breadcrumb id="breadcrumb-container" class="breadcrumb-container" v-if="!topNav"/>
6
-    <top-nav id="topmenu-container" class="breadcrumb-container" v-if="topNav"/>
6
+    <top-nav id="topmenu-container" class="topmenu-container" v-if="topNav"/>
7 7
 
8 8
     <div class="right-menu">
9 9
       <template v-if="device!=='mobile'">
@@ -135,6 +135,11 @@ export default {
135 135
     float: left;
136 136
   }
137 137
 
138
+  .topmenu-container {
139
+    position: absolute;
140
+    left: 50px;
141
+  }
142
+
138 143
   .errLog-container {
139 144
     display: inline-block;
140 145
     vertical-align: top;