Commit 63b7ee096a34be6523b8426c072b054e32f4bd88

Authored by YunaiV
1 parent cff4391f

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

yudao-ui-admin/src/components/TopNav/index.vue
... ... @@ -47,7 +47,7 @@ export default {
47 47 topMenus() {
48 48 let topMenus = [];
49 49 this.routers.map((menu) => {
50   - if (menu.hidden === false) {
  50 + if (menu.hidden !== true) {
51 51 topMenus.push(menu);
52 52 }
53 53 });
... ... @@ -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) {
... ...
yudao-ui-admin/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;
... ...