@lambo-design/pro-layout 1.0.0-beta.45 → 1.0.0-beta.451
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +11 -4
- package/src/components/pro-layout-header/index.vue +220 -0
- package/src/components/pro-layout-header/pro-layout-logo/index.vue +206 -0
- package/src/components/pro-layout-header/pro-layout-nav/components/pro-layout-nav-slide-menu.vue +399 -0
- package/src/components/pro-layout-header/pro-layout-nav/index-slide.vue +226 -0
- package/src/components/pro-layout-header/pro-layout-nav/index.vue +565 -0
- package/src/components/pro-layout-header/pro-layout-slogan/index.vue +40 -0
- package/src/components/pro-layout-header/pro-layout-tools/components/pro-layout-tools-quick-collect.vue +79 -0
- package/src/components/pro-layout-header/pro-layout-tools/components/pro-layout-tools-quick-document.vue +116 -0
- package/src/components/pro-layout-header/pro-layout-tools/components/pro-layout-tools-quick-fullscreen.vue +144 -0
- package/src/components/pro-layout-header/pro-layout-tools/components/pro-layout-tools-quick-icons.vue +99 -0
- package/src/components/pro-layout-header/pro-layout-tools/components/pro-layout-tools-quick-intl.vue +110 -0
- package/src/components/pro-layout-header/pro-layout-tools/components/pro-layout-tools-quick-notice.vue +133 -0
- package/src/components/pro-layout-header/pro-layout-tools/components/pro-layout-tools-quick-search.vue +305 -0
- package/src/components/pro-layout-header/pro-layout-tools/components/pro-layout-tools-quick-todo.vue +145 -0
- package/src/components/pro-layout-header/pro-layout-tools/components/pro-layout-tools-user.vue +64 -0
- package/src/components/pro-layout-header/pro-layout-tools/index.vue +38 -0
- package/src/components/pro-layout-header/pro-layout-trigger/index.vue +84 -0
- package/src/components/{pro-layout-sider-collapsed-menu.vue → pro-layout-sider/components/pro-layout-sider-collapsed-menu.vue} +30 -11
- package/src/components/{pro-layout-sider-icon.vue → pro-layout-sider/components/pro-layout-sider-icon.vue} +2 -2
- package/src/components/pro-layout-sider/components/pro-layout-sider-menu-item.vue +137 -0
- package/src/components/pro-layout-sider/components/pro-layout-sider-other-menu.vue +140 -0
- package/src/components/pro-layout-sider/components/pro-layout-sider-search.vue +345 -0
- package/src/components/pro-layout-sider/index.vue +477 -0
- package/src/components/{pro-layout-tabs.vue → pro-layout-tabs/index.vue} +118 -23
- package/src/index.vue +306 -40
- package/src/styles/color.less +267 -0
- package/src/styles/images/xiaoxitongzhi.png +0 -0
- package/src/styles/other-menu.less +63 -111
- package/src/utils/menuItem.js +10 -0
- package/src/utils/sider.js +16 -1
- package/src/components/pro-layout-header.vue +0 -52
- package/src/components/pro-layout-logo.vue +0 -79
- package/src/components/pro-layout-nav.vue +0 -150
- package/src/components/pro-layout-other-menu.vue +0 -138
- package/src/components/pro-layout-sider-menu-item.vue +0 -37
- package/src/components/pro-layout-sider.vue +0 -240
- package/src/components/pro-layout-tools-user.vue +0 -84
- package/src/components/pro-layout-tools.vue +0 -21
- package/src/components/pro-layout-trigger.vue +0 -48
package/src/components/pro-layout-header/pro-layout-nav/components/pro-layout-nav-slide-menu.vue
ADDED
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="menu-list" ref="menuList">
|
|
3
|
+
<ul class="top-menu" :style="layoutSize === 'default' ? {height: '64px'} : {height: '50px'}" ref="topNav">
|
|
4
|
+
<template v-for="(item,index) in topMenList" >
|
|
5
|
+
<li class="top-menu-item"
|
|
6
|
+
:class="{ 'active': getIsActive(item) }"
|
|
7
|
+
:key="item.appId"
|
|
8
|
+
@click="selectApp(item.appId)">
|
|
9
|
+
<div class="menu-item" :style="layoutSize === 'default' ? {paddingTop: '10px'} : {paddingTop: '2px'}">
|
|
10
|
+
<p class="menu-icon" v-show="systemInfo.navLogo==='1'"><Icon :type="item.icon" :size="20"></Icon></p>
|
|
11
|
+
<p class="menu-txt" :title="item.name">{{ item.name }}</p>
|
|
12
|
+
</div>
|
|
13
|
+
</li>
|
|
14
|
+
</template>
|
|
15
|
+
</ul>
|
|
16
|
+
</div>
|
|
17
|
+
</template>
|
|
18
|
+
|
|
19
|
+
<script>
|
|
20
|
+
import Bus from '@lambo-design/shared/utils/bus'
|
|
21
|
+
import { deepCopy } from '@lambo-design/shared/utils/assist'
|
|
22
|
+
import _ from "lodash";
|
|
23
|
+
import {getSessionStorage} from "@lambo-design/shared/utils/n";
|
|
24
|
+
|
|
25
|
+
export default {
|
|
26
|
+
props: {
|
|
27
|
+
acceptInt: {
|
|
28
|
+
type: Number,
|
|
29
|
+
default: 0
|
|
30
|
+
},
|
|
31
|
+
topMenListNum: {
|
|
32
|
+
type: Number,
|
|
33
|
+
default: 0
|
|
34
|
+
},
|
|
35
|
+
availableWidth: {
|
|
36
|
+
type: Number,
|
|
37
|
+
default: 800
|
|
38
|
+
},
|
|
39
|
+
notHomeIndex: {
|
|
40
|
+
type: Boolean,
|
|
41
|
+
default: true
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
data() {
|
|
45
|
+
return {
|
|
46
|
+
systemInfo:{},
|
|
47
|
+
pointer:0,
|
|
48
|
+
arrowFlag: true,
|
|
49
|
+
acceptAppId: '',
|
|
50
|
+
navList: [],
|
|
51
|
+
topMenList: [],
|
|
52
|
+
topTqmMenList:[],
|
|
53
|
+
otherList: [],
|
|
54
|
+
activeName: '',
|
|
55
|
+
topMenuNum: 7,
|
|
56
|
+
displayMenuNum: 7, // 实际显示的菜单数量
|
|
57
|
+
lastTopMenuNum:-1,
|
|
58
|
+
originMenuList: [],
|
|
59
|
+
layoutSize:"default",
|
|
60
|
+
// menuItemWidths: [], // 存储每个菜单项的宽度
|
|
61
|
+
resizeObserver: null,
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
methods: {
|
|
65
|
+
initListener() {
|
|
66
|
+
Bus.$on('system-info',(data) => {
|
|
67
|
+
this.initSystemInfo(data);
|
|
68
|
+
})
|
|
69
|
+
Bus.$on('nav-list', (data) => {
|
|
70
|
+
this.initNav(data)
|
|
71
|
+
})
|
|
72
|
+
Bus.$on('change-app', ({ appId, appInfo }) => {
|
|
73
|
+
this.changeApp(appId, appInfo)
|
|
74
|
+
})
|
|
75
|
+
},
|
|
76
|
+
destroyListener() {
|
|
77
|
+
Bus.$off('system-info')
|
|
78
|
+
Bus.$off('nav-list')
|
|
79
|
+
Bus.$off('change-app')
|
|
80
|
+
},
|
|
81
|
+
initSystemInfo(data) {
|
|
82
|
+
if (data) {
|
|
83
|
+
this.systemInfo = data
|
|
84
|
+
this.layoutSize = data.layoutSize ? data.layoutSize : 'default';
|
|
85
|
+
this.topMenuNum = Number.isInteger(data.topMenu) ? data.topMenu : 4;
|
|
86
|
+
this.acceptAppId = data.acceptAppId ? data.acceptAppId : '';
|
|
87
|
+
if (!this.activeName && this.notHomeIndex) {
|
|
88
|
+
this.activeName = this.acceptAppId
|
|
89
|
+
}
|
|
90
|
+
this.initNav(this.navList)
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
initNav(data) {
|
|
94
|
+
// 过滤掉首页项,获取真实的业务数据
|
|
95
|
+
const realData = data.filter(item => item.appId !== 'backHome');
|
|
96
|
+
if (realData.toString() === this.navList.toString() && this.topMenuNum === this.lastTopMenuNum) {
|
|
97
|
+
return
|
|
98
|
+
}
|
|
99
|
+
this.navList = realData
|
|
100
|
+
this.lastTopMenuNum = this.topMenuNum
|
|
101
|
+
|
|
102
|
+
let dataClone = _.cloneDeep(realData);
|
|
103
|
+
// 如果配置了显示首页且显示样式是应用式,在列表最前面添加首页项
|
|
104
|
+
if (dataClone && dataClone.length > 0 && this.systemInfo.backToHome && this.systemInfo.backToHomeStyle === "app") {
|
|
105
|
+
const homeItem = {
|
|
106
|
+
appId: 'backHome',
|
|
107
|
+
name: this.systemInfo.backToHomeText || '首页',
|
|
108
|
+
icon: 'ios-home',
|
|
109
|
+
selected: false
|
|
110
|
+
};
|
|
111
|
+
dataClone.unshift(homeItem);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
this.topMenList = dataClone
|
|
115
|
+
this.$emit('topMen-list', this.topMenList);
|
|
116
|
+
|
|
117
|
+
// 计算可以显示的菜单数量
|
|
118
|
+
this.calculateDisplayMenuNum();
|
|
119
|
+
|
|
120
|
+
if (this.topMenList.length > 0) {
|
|
121
|
+
let appId = this.topMenList[0].appId
|
|
122
|
+
if (this.systemInfo.backToHome && this.systemInfo.backToHomeStyle === "app") {
|
|
123
|
+
appId = this.topMenList[1].appId;
|
|
124
|
+
}
|
|
125
|
+
for (let i = 0; i < this.topMenList.length; i++) {
|
|
126
|
+
if (this.topMenList[i].selected == true) {
|
|
127
|
+
appId = this.topMenList[i].appId
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
if (this.activeName) {
|
|
131
|
+
appId = this.activeName
|
|
132
|
+
}
|
|
133
|
+
if (this.notHomeIndex) {
|
|
134
|
+
this.selectApp(appId)
|
|
135
|
+
} else if (this.systemInfo.backToHome === "1" && this.systemInfo.backToHomeStyle === "app") {
|
|
136
|
+
this.activeName = 'backHome'
|
|
137
|
+
sessionStorage.setItem('fromHomeIndex', 'true')
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
// 计算可以显示的菜单数量
|
|
142
|
+
calculateDisplayMenuNum() {
|
|
143
|
+
this.$nextTick(() => {
|
|
144
|
+
if (!this.$refs.menuList) return;
|
|
145
|
+
|
|
146
|
+
// 获取单个菜单项的平均宽度
|
|
147
|
+
// const menuItems = this.$refs.menuList.querySelectorAll('.top-menu-item');
|
|
148
|
+
// if (menuItems.length === 0) return;
|
|
149
|
+
|
|
150
|
+
let totalWidth = 0;
|
|
151
|
+
let itemWidths = [];
|
|
152
|
+
|
|
153
|
+
// 临时显示所有菜单项以测量宽度
|
|
154
|
+
// menuItems.forEach((item, index) => {
|
|
155
|
+
// item.style.display = 'block';
|
|
156
|
+
// const width = item.offsetWidth;
|
|
157
|
+
// itemWidths.push(width);
|
|
158
|
+
// totalWidth += width;
|
|
159
|
+
// });
|
|
160
|
+
|
|
161
|
+
// this.menuItemWidths = itemWidths;
|
|
162
|
+
|
|
163
|
+
// 计算可以显示的菜单数量
|
|
164
|
+
let displayCount = 0;
|
|
165
|
+
let accumulatedWidth = 0;
|
|
166
|
+
const reservedWidth = 40; // 预留一些边距
|
|
167
|
+
|
|
168
|
+
this.topMenList.forEach((item, index) => {
|
|
169
|
+
const estimatedWidth = this.estimateMenuItemWidth(item);
|
|
170
|
+
if (accumulatedWidth + estimatedWidth <= this.availableWidth - reservedWidth) {
|
|
171
|
+
accumulatedWidth += estimatedWidth;
|
|
172
|
+
displayCount++;
|
|
173
|
+
}
|
|
174
|
+
})
|
|
175
|
+
//
|
|
176
|
+
// for (let i = 0; i < itemWidths.length; i++) {
|
|
177
|
+
// if (accumulatedWidth + itemWidths[i] <= this.availableWidth - reservedWidth) {
|
|
178
|
+
// accumulatedWidth += itemWidths[i];
|
|
179
|
+
// displayCount++;
|
|
180
|
+
// } else {
|
|
181
|
+
// break;
|
|
182
|
+
// }
|
|
183
|
+
// }
|
|
184
|
+
|
|
185
|
+
// 确保至少显示一个菜单项
|
|
186
|
+
let displayMenuNum = Math.max(1, displayCount);
|
|
187
|
+
|
|
188
|
+
// 如果配置的数量更小则依赖配置
|
|
189
|
+
if(this.topMenuNum < displayMenuNum){
|
|
190
|
+
this.displayMenuNum = this.topMenuNum
|
|
191
|
+
}else{
|
|
192
|
+
this.displayMenuNum = displayMenuNum
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// this.displayMenuNum = Math.max(1, displayCount);
|
|
196
|
+
// 判断是否需要显示箭头
|
|
197
|
+
const needArrows = this.topMenList.length > this.displayMenuNum && this.displayMenuNum > 0;
|
|
198
|
+
this.$emit('topMen-num', this.displayMenuNum);
|
|
199
|
+
this.$emit('topMen-true', needArrows);
|
|
200
|
+
|
|
201
|
+
// 向父组件报告实际宽度
|
|
202
|
+
this.$emit('menu-width-change', totalWidth);
|
|
203
|
+
|
|
204
|
+
//重新调整样式
|
|
205
|
+
// menuItems.forEach((item, index) => {
|
|
206
|
+
// if(!(this.pointer <= index && index < (this.pointer + this.displayMenuNum))){
|
|
207
|
+
// item.style.display = 'none';
|
|
208
|
+
// }else{
|
|
209
|
+
// item.style.display = 'block'
|
|
210
|
+
// }
|
|
211
|
+
// });
|
|
212
|
+
});
|
|
213
|
+
},
|
|
214
|
+
estimateMenuItemWidth(item) {
|
|
215
|
+
// 基础宽度:内边距 + 边框
|
|
216
|
+
let baseWidth = 30;
|
|
217
|
+
|
|
218
|
+
// 图标宽度
|
|
219
|
+
if (item.icon && this.systemInfo.navLogo === '1') {
|
|
220
|
+
baseWidth += 30;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// 文字宽度估算(每个字符约14px)
|
|
224
|
+
|
|
225
|
+
const textWidth = (item.name || '').length * 14;
|
|
226
|
+
return baseWidth + textWidth;
|
|
227
|
+
},
|
|
228
|
+
|
|
229
|
+
selectApp(appId) {
|
|
230
|
+
if (appId) {
|
|
231
|
+
if (appId === 'backHome') {
|
|
232
|
+
Bus.$emit("change-app", {
|
|
233
|
+
appId,
|
|
234
|
+
appInfo: {}
|
|
235
|
+
});
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
this.activeName = appId
|
|
239
|
+
let res = this.navList.filter(app => app.appId == appId)
|
|
240
|
+
Bus.$emit('change-app', { appId, appInfo: res[0] })
|
|
241
|
+
}
|
|
242
|
+
},
|
|
243
|
+
changeApp(appId, appInfo){
|
|
244
|
+
if (appId) {
|
|
245
|
+
this.activeName = appId
|
|
246
|
+
}
|
|
247
|
+
},
|
|
248
|
+
// 监听菜单容器大小变化
|
|
249
|
+
observeResize() {
|
|
250
|
+
if (window.ResizeObserver) {
|
|
251
|
+
this.resizeObserver = new ResizeObserver(() => {
|
|
252
|
+
this.calculateDisplayMenuNum();
|
|
253
|
+
this.controlVisable()
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
if (this.$refs.menuList) {
|
|
257
|
+
this.resizeObserver.observe(this.$refs.menuList);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
},
|
|
261
|
+
controlVisable(){
|
|
262
|
+
//重新调整样式
|
|
263
|
+
const menuItems = this.$refs.menuList.querySelectorAll('.top-menu-item');
|
|
264
|
+
menuItems.forEach((item, index) => {
|
|
265
|
+
if(!(this.pointer <= index && index < (this.pointer + this.displayMenuNum))){
|
|
266
|
+
item.style.display = 'none';
|
|
267
|
+
}else{
|
|
268
|
+
item.style.display = 'block';
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
},
|
|
272
|
+
getIsActive(item) {
|
|
273
|
+
// 如果不是首页模式,直接比较 appId
|
|
274
|
+
if (this.notHomeIndex) {
|
|
275
|
+
return this.activeName === item.appId;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// 如果是首页模式,检查当前 activeName 对应的应用是否隐藏了左侧菜单
|
|
279
|
+
const appList = getSessionStorage('appList');
|
|
280
|
+
if (appList && Array.isArray(appList) && appList.length > 0) {
|
|
281
|
+
// 查找当前 activeName 对应的应用
|
|
282
|
+
const currentApp = appList.find(app => app.appId === this.activeName);
|
|
283
|
+
// 如果找到应用且隐藏了左侧菜单,该应用应该保持激活状态
|
|
284
|
+
if (currentApp) {
|
|
285
|
+
let isHideLeftMenu;
|
|
286
|
+
if (currentApp.extendProps) {
|
|
287
|
+
if (typeof currentApp.extendProps === 'string') {
|
|
288
|
+
isHideLeftMenu = JSON.parse(currentApp.extendProps)?.is_hide_left_menu;
|
|
289
|
+
} else {
|
|
290
|
+
isHideLeftMenu = currentApp.extendProps.is_hide_left_menu;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
if (!isHideLeftMenu && currentApp.setting) {
|
|
294
|
+
if (typeof currentApp.setting === 'string') {
|
|
295
|
+
isHideLeftMenu = JSON.parse(currentApp.setting)?.is_hide_left_menu;
|
|
296
|
+
} else {
|
|
297
|
+
isHideLeftMenu = currentApp.setting.is_hide_left_menu;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
if ((isHideLeftMenu === '1' || isHideLeftMenu === 1) && this.activeName === item.appId) {
|
|
301
|
+
return true;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
// 否则只有 backHome 项应该是激活的
|
|
307
|
+
return 'backHome' === item.appId;
|
|
308
|
+
}
|
|
309
|
+
},
|
|
310
|
+
watch: {
|
|
311
|
+
acceptInt(val){
|
|
312
|
+
this.pointer = val;
|
|
313
|
+
this.controlVisable()
|
|
314
|
+
},
|
|
315
|
+
availableWidth(newVal, oldVal) {
|
|
316
|
+
if (newVal !== oldVal) {
|
|
317
|
+
this.calculateDisplayMenuNum();
|
|
318
|
+
}
|
|
319
|
+
},
|
|
320
|
+
topMenList() {
|
|
321
|
+
this.calculateDisplayMenuNum();
|
|
322
|
+
}
|
|
323
|
+
},
|
|
324
|
+
mounted() {
|
|
325
|
+
this.calculateDisplayMenuNum();
|
|
326
|
+
this.$nextTick(() => {
|
|
327
|
+
this.observeResize();
|
|
328
|
+
});
|
|
329
|
+
},
|
|
330
|
+
created() {
|
|
331
|
+
this.initListener()
|
|
332
|
+
},
|
|
333
|
+
beforeDestroy() {
|
|
334
|
+
this.destroyListener();
|
|
335
|
+
if (this.resizeObserver) {
|
|
336
|
+
this.resizeObserver.disconnect();
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
</script>
|
|
341
|
+
|
|
342
|
+
<style scoped lang="less">
|
|
343
|
+
@import '@lambo-design/core/src/styles/default.less';
|
|
344
|
+
.menu-list {
|
|
345
|
+
height: 100%;
|
|
346
|
+
line-height: 24px;
|
|
347
|
+
cursor: pointer;
|
|
348
|
+
font-size: 16px;
|
|
349
|
+
margin-left: 15px;
|
|
350
|
+
overflow: hidden;
|
|
351
|
+
|
|
352
|
+
.top-menu {
|
|
353
|
+
overflow: hidden;
|
|
354
|
+
white-space: nowrap;
|
|
355
|
+
|
|
356
|
+
.top-menu-item {
|
|
357
|
+
padding-left: 15px;
|
|
358
|
+
padding-right: 15px;
|
|
359
|
+
position: relative;
|
|
360
|
+
height: 100%;
|
|
361
|
+
list-style: none;
|
|
362
|
+
float: left;
|
|
363
|
+
transition: all 0.3s ease;
|
|
364
|
+
|
|
365
|
+
&:hover {
|
|
366
|
+
.menu-item {
|
|
367
|
+
// hover styles
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
&.active {
|
|
371
|
+
.menu-item {
|
|
372
|
+
// active styles
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
.menu-item {
|
|
376
|
+
display: flex;
|
|
377
|
+
margin-top: 10px;
|
|
378
|
+
text-align: center;
|
|
379
|
+
}
|
|
380
|
+
.menu-icon {
|
|
381
|
+
height: 20px;
|
|
382
|
+
line-height: 20px;
|
|
383
|
+
text-align: center;
|
|
384
|
+
margin-right: 10px;
|
|
385
|
+
margin-top: 3px;
|
|
386
|
+
}
|
|
387
|
+
.menu-txt {
|
|
388
|
+
text-align: center;
|
|
389
|
+
font-size: 14px;
|
|
390
|
+
line-height: 2;
|
|
391
|
+
white-space: nowrap;
|
|
392
|
+
overflow: hidden;
|
|
393
|
+
text-overflow: ellipsis;
|
|
394
|
+
max-width: 120px; // 限制最大宽度
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
</style>
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="pro-layout-nav-slide-wrapper" ref="slideWrapper">
|
|
3
|
+
<div class="nav-box-slide" ref="navBox" :style="{ width: availableWidth + 'px' }">
|
|
4
|
+
<LamboProNavSlideMenu
|
|
5
|
+
:not-home-index="notHomeIndex"
|
|
6
|
+
:accept-int="pointer"
|
|
7
|
+
:available-width="availableWidth"
|
|
8
|
+
@topMen-list="handleCustomEvent"
|
|
9
|
+
@topMen-num="topMen"
|
|
10
|
+
@topMen-true="topMenTrue"
|
|
11
|
+
@menu-width-change="handleMenuWidthChange"
|
|
12
|
+
ref="menu"
|
|
13
|
+
></LamboProNavSlideMenu>
|
|
14
|
+
</div>
|
|
15
|
+
<!--slide按钮-->
|
|
16
|
+
<div class="tools-box-slide" v-if="shouldShowArrows">
|
|
17
|
+
<div style="margin-right: 50px;">
|
|
18
|
+
<Icon
|
|
19
|
+
class="more-menu"
|
|
20
|
+
style="margin-right: 10px"
|
|
21
|
+
type="md-arrow-dropleft-circle"
|
|
22
|
+
v-if="arrowFlag"
|
|
23
|
+
@click="moveMenu('left')"
|
|
24
|
+
:style="{ opacity: canMoveLeft ? 1 : 0.3 }"
|
|
25
|
+
/>
|
|
26
|
+
<Icon
|
|
27
|
+
type="md-arrow-dropright-circle"
|
|
28
|
+
class="more-menu"
|
|
29
|
+
v-if="arrowFlag"
|
|
30
|
+
@click="moveMenu('right')"
|
|
31
|
+
:style="{ opacity: canMoveRight ? 1 : 0.3 }"
|
|
32
|
+
/>
|
|
33
|
+
</div>
|
|
34
|
+
</div>
|
|
35
|
+
</div>
|
|
36
|
+
</template>
|
|
37
|
+
|
|
38
|
+
<script>
|
|
39
|
+
import LamboProNavSlideMenu from './components/pro-layout-nav-slide-menu'
|
|
40
|
+
|
|
41
|
+
export default {
|
|
42
|
+
props: {
|
|
43
|
+
availableWidth: {
|
|
44
|
+
type: Number,
|
|
45
|
+
default: 800
|
|
46
|
+
},
|
|
47
|
+
autoCalculateWidth: {
|
|
48
|
+
type: Boolean,
|
|
49
|
+
default: true
|
|
50
|
+
},
|
|
51
|
+
notHomeIndex: {
|
|
52
|
+
type: Boolean,
|
|
53
|
+
default: true
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
data(){
|
|
57
|
+
return {
|
|
58
|
+
pointer: 0,
|
|
59
|
+
topList: [],
|
|
60
|
+
topNum: 0,
|
|
61
|
+
arrowFlag: false,
|
|
62
|
+
menuActualWidth: 0,
|
|
63
|
+
shouldShowArrows: false,
|
|
64
|
+
canMoveLeft: false,
|
|
65
|
+
canMoveRight: false,
|
|
66
|
+
resizeObserver: null,
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
components: {
|
|
70
|
+
LamboProNavSlideMenu
|
|
71
|
+
},
|
|
72
|
+
methods:{
|
|
73
|
+
handleCustomEvent(data) {
|
|
74
|
+
// 接收子组件传递的数据
|
|
75
|
+
this.topList = data;
|
|
76
|
+
this.checkWidthAndArrows();
|
|
77
|
+
},
|
|
78
|
+
topMen(data){
|
|
79
|
+
this.topNum = data;
|
|
80
|
+
this.checkWidthAndArrows();
|
|
81
|
+
},
|
|
82
|
+
topMenTrue(data){
|
|
83
|
+
this.arrowFlag = data;
|
|
84
|
+
this.checkWidthAndArrows();
|
|
85
|
+
},
|
|
86
|
+
// 处理菜单宽度变化
|
|
87
|
+
handleMenuWidthChange(width) {
|
|
88
|
+
this.menuActualWidth = width;
|
|
89
|
+
this.checkWidthAndArrows();
|
|
90
|
+
},
|
|
91
|
+
// 检查宽度并决定是否显示箭头
|
|
92
|
+
checkWidthAndArrows() {
|
|
93
|
+
this.$nextTick(() => {
|
|
94
|
+
if (!this.autoCalculateWidth) {
|
|
95
|
+
this.shouldShowArrows = this.arrowFlag;
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// 计算实际菜单宽度
|
|
100
|
+
const navBox = this.$refs.navBox;
|
|
101
|
+
if (navBox) {
|
|
102
|
+
const menuContainer = navBox.querySelector('.menu-list');
|
|
103
|
+
if (menuContainer) {
|
|
104
|
+
this.menuActualWidth = menuContainer.scrollWidth;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// 预留箭头按钮空间
|
|
109
|
+
const arrowSpace = 80;
|
|
110
|
+
const effectiveWidth = this.availableWidth - arrowSpace;
|
|
111
|
+
|
|
112
|
+
// 判断是否需要显示箭头
|
|
113
|
+
this.shouldShowArrows = this.menuActualWidth > effectiveWidth;
|
|
114
|
+
|
|
115
|
+
if (this.shouldShowArrows) {
|
|
116
|
+
this.updateArrowStates();
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// 触发宽度变化事件
|
|
120
|
+
this.$emit('width-change', {
|
|
121
|
+
available: this.availableWidth,
|
|
122
|
+
actual: this.menuActualWidth,
|
|
123
|
+
needArrows: this.shouldShowArrows
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
});
|
|
127
|
+
},
|
|
128
|
+
// 更新箭头状态
|
|
129
|
+
updateArrowStates() {
|
|
130
|
+
if (!this.shouldShowArrows) {
|
|
131
|
+
this.canMoveLeft = false;
|
|
132
|
+
this.canMoveRight = false;
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// 计算最大可移动位置
|
|
137
|
+
const maxPointer = Math.max(0, this.topList.length - this.topNum);
|
|
138
|
+
|
|
139
|
+
this.canMoveLeft = this.pointer > 0;
|
|
140
|
+
this.canMoveRight = this.pointer < maxPointer;
|
|
141
|
+
},
|
|
142
|
+
moveMenu: function (direction) {
|
|
143
|
+
if (!this.shouldShowArrows) return;
|
|
144
|
+
|
|
145
|
+
const maxPointer = Math.max(0, this.topList.length - this.topNum);
|
|
146
|
+
|
|
147
|
+
if (direction === "right") {
|
|
148
|
+
if (this.pointer < maxPointer) {
|
|
149
|
+
this.pointer++;
|
|
150
|
+
}
|
|
151
|
+
} else {
|
|
152
|
+
if (this.pointer > 0) {
|
|
153
|
+
this.pointer--;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
this.updateArrowStates();
|
|
158
|
+
|
|
159
|
+
this.flag = false;
|
|
160
|
+
let self = this;
|
|
161
|
+
setTimeout(() => {
|
|
162
|
+
self.flag = true;
|
|
163
|
+
}, 0);
|
|
164
|
+
},
|
|
165
|
+
// 监听容器大小变化
|
|
166
|
+
observeResize() {
|
|
167
|
+
if (window.ResizeObserver) {
|
|
168
|
+
this.resizeObserver = new ResizeObserver(() => {
|
|
169
|
+
this.checkWidthAndArrows();
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
if (this.$refs.slideWrapper) {
|
|
173
|
+
this.resizeObserver.observe(this.$refs.slideWrapper);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
},
|
|
177
|
+
},
|
|
178
|
+
watch: {
|
|
179
|
+
availableWidth(newVal) {
|
|
180
|
+
this.checkWidthAndArrows();
|
|
181
|
+
},
|
|
182
|
+
pointer() {
|
|
183
|
+
this.updateArrowStates();
|
|
184
|
+
}
|
|
185
|
+
},
|
|
186
|
+
mounted() {
|
|
187
|
+
this.$nextTick(() => {
|
|
188
|
+
this.checkWidthAndArrows();
|
|
189
|
+
this.observeResize();
|
|
190
|
+
});
|
|
191
|
+
},
|
|
192
|
+
beforeDestroy() {
|
|
193
|
+
if (this.resizeObserver) {
|
|
194
|
+
this.resizeObserver.disconnect();
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
</script>
|
|
199
|
+
|
|
200
|
+
<style scoped lang="less">
|
|
201
|
+
.pro-layout-nav-slide-wrapper {
|
|
202
|
+
display: flex;
|
|
203
|
+
align-items: center;
|
|
204
|
+
height: 100%;
|
|
205
|
+
width: 100%;
|
|
206
|
+
|
|
207
|
+
.nav-box-slide{
|
|
208
|
+
overflow: hidden;
|
|
209
|
+
flex: 1;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
.tools-box-slide{
|
|
213
|
+
flex-shrink: 0;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
.more-menu {
|
|
218
|
+
font-size: 22px;
|
|
219
|
+
cursor: pointer;
|
|
220
|
+
transition: opacity 0.3s ease;
|
|
221
|
+
|
|
222
|
+
&:hover {
|
|
223
|
+
opacity: 0.8 !important;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
</style>
|