作者 RuoYi

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

@@ -95,21 +95,20 @@ export default { @@ -95,21 +95,20 @@ export default {
95 return activePath; 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 mounted() { 104 mounted() {
99 this.setVisibleNumber(); 105 this.setVisibleNumber();
100 }, 106 },
101 methods: { 107 methods: {
102 // 根据宽度计算设置显示栏数 108 // 根据宽度计算设置显示栏数
103 setVisibleNumber() { 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 handleSelect(key, keyPath) { 114 handleSelect(key, keyPath) {
@@ -3,7 +3,7 @@ @@ -3,7 +3,7 @@
3 <hamburger id="hamburger-container" :is-active="sidebar.opened" class="hamburger-container" @toggleClick="toggleSideBar" /> 3 <hamburger id="hamburger-container" :is-active="sidebar.opened" class="hamburger-container" @toggleClick="toggleSideBar" />
4 4
5 <breadcrumb id="breadcrumb-container" class="breadcrumb-container" v-if="!topNav"/> 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 <div class="right-menu"> 8 <div class="right-menu">
9 <template v-if="device!=='mobile'"> 9 <template v-if="device!=='mobile'">
@@ -135,6 +135,11 @@ export default { @@ -135,6 +135,11 @@ export default {
135 float: left; 135 float: left;
136 } 136 }
137 137
  138 + .topmenu-container {
  139 + position: absolute;
  140 + left: 50px;
  141 + }
  142 +
138 .errLog-container { 143 .errLog-container {
139 display: inline-block; 144 display: inline-block;
140 vertical-align: top; 145 vertical-align: top;