vben
authored
|
1
|
<template>
|
vben
authored
|
2
|
<div :class="`${prefixCls}-dom`" :style="getDomStyle"></div>
|
vben
authored
|
3
4
|
<div
v-click-outside="handleClickOutside"
|
vben
authored
|
5
|
:style="getWrapStyle"
|
vben
authored
|
6
7
8
9
10
|
:class="[
prefixCls,
getMenuTheme,
{
open: openMenu,
|
vben
authored
|
11
|
mini: getCollapsed,
|
vben
authored
|
12
13
|
},
]"
|
vben
authored
|
14
|
v-bind="getMenuEvents"
|
vben
authored
|
15
16
|
>
<AppLogo :showTitle="false" :class="`${prefixCls}-logo`" />
|
vben
authored
|
17
|
|
|
18
|
<LayoutTrigger :class="`${prefixCls}-trigger`" />
|
vben
authored
|
19
|
|
vben
authored
|
20
21
22
23
24
25
26
27
28
|
<ScrollContainer>
<ul :class="`${prefixCls}-module`">
<li
:class="[
`${prefixCls}-module__item `,
{
[`${prefixCls}-module__item--active`]: item.path === activePath,
},
]"
|
Vben
authored
|
29
|
v-bind="getItemEvents(item)"
|
vben
authored
|
30
31
32
|
v-for="item in menuModules"
:key="item.path"
>
|
Vben
authored
|
33
|
<SimpleMenuTag :item="item" collapseParent dot />
|
vben
authored
|
34
|
<Icon
|
vben
authored
|
35
|
:class="`${prefixCls}-module__icon`"
|
vben
authored
|
36
|
:size="getCollapsed ? 16 : 20"
|
Vben
authored
|
37
|
:icon="item.icon || (item.meta && item.meta.icon)"
|
vben
authored
|
38
|
/>
|
vben
authored
|
39
40
41
|
<p :class="`${prefixCls}-module__name`">
{{ t(item.name) }}
</p>
|
vben
authored
|
42
43
44
45
46
47
|
</li>
</ul>
</ScrollContainer>
<div :class="`${prefixCls}-menu-list`" ref="sideRef" :style="getMenuStyle">
<div
|
vben
authored
|
48
|
v-show="openMenu"
|
vben
authored
|
49
50
51
52
53
54
55
56
|
:class="[
`${prefixCls}-menu-list__title`,
{
show: openMenu,
},
]"
>
<span class="text"> {{ title }}</span>
|
vben
authored
|
57
58
|
<Icon
:size="16"
|
vben
authored
|
59
|
:icon="getMixSideFixed ? 'ri:pushpin-2-fill' : 'ri:pushpin-2-line'"
|
vben
authored
|
60
61
62
|
class="pushpin"
@click="handleFixedMenu"
/>
|
vben
authored
|
63
64
|
</div>
<ScrollContainer :class="`${prefixCls}-menu-list__content`">
|
vben
authored
|
65
|
<SimpleMenu
|
|
66
|
:items="childrenMenus"
|
vben
authored
|
67
|
:theme="getMenuTheme"
|
vben
authored
|
68
|
mixSider
|
vben
authored
|
69
70
71
72
73
74
75
76
77
78
79
80
81
|
@menuClick="handleMenuClick"
/>
</ScrollContainer>
<div
v-show="getShowDragBar && openMenu"
:class="`${prefixCls}-drag-bar`"
ref="dragBarRef"
></div>
</div>
</div>
</template>
<script lang="ts">
import type { Menu } from '/@/router/types';
|
vben
authored
|
82
|
import type { CSSProperties } from 'vue';
|
|
83
|
import { computed, defineComponent, onMounted, ref, unref } from 'vue';
|
vben
authored
|
84
|
import type { RouteLocationNormalized } from 'vue-router';
|
vben
authored
|
85
|
import { ScrollContainer } from '/@/components/Container';
|
|
86
|
import { SimpleMenu, SimpleMenuTag } from '/@/components/SimpleMenu';
|
Vben
authored
|
87
|
import { Icon } from '/@/components/Icon';
|
vben
authored
|
88
89
90
|
import { AppLogo } from '/@/components/Application';
import { useMenuSetting } from '/@/hooks/setting/useMenuSetting';
import { useDragLine } from './useLayoutSider';
|
vben
authored
|
91
|
import { useGlobSetting } from '/@/hooks/setting';
|
vben
authored
|
92
93
94
|
import { useDesign } from '/@/hooks/web/useDesign';
import { useI18n } from '/@/hooks/web/useI18n';
import { useGo } from '/@/hooks/web/usePage';
|
|
95
|
import { SIDE_BAR_MINI_WIDTH, SIDE_BAR_SHOW_TIT_MINI_WIDTH } from '/@/enums/appEnum';
|
vben
authored
|
96
|
import clickOutside from '/@/directives/clickOutside';
|
|
97
|
import { getChildrenMenus, getCurrentParentPath, getShallowMenus } from '/@/router/menus';
|
Vben
authored
|
98
|
import { listenerRouteChange } from '/@/logics/mitt/routeChange';
|
|
99
|
import LayoutTrigger from '../trigger/index.vue';
|
vben
authored
|
100
101
102
103
104
105
|
export default defineComponent({
name: 'LayoutMixSider',
components: {
ScrollContainer,
AppLogo,
|
vben
authored
|
106
|
SimpleMenu,
|
vben
authored
|
107
|
Icon,
|
|
108
|
LayoutTrigger,
|
Vben
authored
|
109
|
SimpleMenuTag,
|
vben
authored
|
110
111
112
113
114
115
116
|
},
directives: {
clickOutside,
},
setup() {
let menuModules = ref<Menu[]>([]);
const activePath = ref('');
|
|
117
|
const childrenMenus = ref<Menu[]>([]);
|
vben
authored
|
118
119
120
121
122
123
124
125
126
127
128
129
130
|
const openMenu = ref(false);
const dragBarRef = ref<ElRef>(null);
const sideRef = ref<ElRef>(null);
const currentRoute = ref<Nullable<RouteLocationNormalized>>(null);
const { prefixCls } = useDesign('layout-mix-sider');
const go = useGo();
const { t } = useI18n();
const {
getMenuWidth,
getCanDrag,
getCloseMixSidebarOnChange,
getMenuTheme,
|
vben
authored
|
131
|
getMixSideTrigger,
|
vben
authored
|
132
133
134
135
|
getRealWidth,
getMixSideFixed,
mixSideHasChildren,
setMenuSetting,
|
vben
authored
|
136
137
|
getIsMixSidebar,
getCollapsed,
|
vben
authored
|
138
|
} = useMenuSetting();
|
vben
authored
|
139
|
|
vben
authored
|
140
141
142
143
|
const { title } = useGlobSetting();
useDragLine(sideRef, dragBarRef, true);
|
Vben
authored
|
144
145
146
147
148
149
|
const getMenuStyle = computed((): CSSProperties => {
return {
width: unref(openMenu) ? `${unref(getMenuWidth)}px` : 0,
left: `${unref(getMixSideWidth)}px`,
};
});
|
vben
authored
|
150
|
|
vben
authored
|
151
|
const getIsFixed = computed(() => {
|
vben
authored
|
152
|
/* eslint-disable-next-line */
|
|
153
|
mixSideHasChildren.value = unref(childrenMenus).length > 0;
|
vben
authored
|
154
155
|
const isFixed = unref(getMixSideFixed) && unref(mixSideHasChildren);
if (isFixed) {
|
vben
authored
|
156
|
/* eslint-disable-next-line */
|
vben
authored
|
157
158
159
160
161
|
openMenu.value = true;
}
return isFixed;
});
|
vben
authored
|
162
163
164
165
|
const getMixSideWidth = computed(() => {
return unref(getCollapsed) ? SIDE_BAR_MINI_WIDTH : SIDE_BAR_SHOW_TIT_MINI_WIDTH;
});
|
Vben
authored
|
166
167
168
169
170
|
const getDomStyle = computed((): CSSProperties => {
const fixedWidth = unref(getIsFixed) ? unref(getRealWidth) : 0;
const width = `${unref(getMixSideWidth) + fixedWidth}px`;
return getWrapCommonStyle(width);
});
|
vben
authored
|
171
|
|
Vben
authored
|
172
173
174
175
|
const getWrapStyle = computed((): CSSProperties => {
const width = `${unref(getMixSideWidth)}px`;
return getWrapCommonStyle(width);
});
|
vben
authored
|
176
|
|
vben
authored
|
177
|
const getMenuEvents = computed(() => {
|
vben
authored
|
178
179
180
|
return !unref(getMixSideFixed)
? {
onMouseleave: () => {
|
|
181
|
setActive(true);
|
vben
authored
|
182
183
184
185
|
closeMenu();
},
}
: {};
|
vben
authored
|
186
187
|
});
|
vben
authored
|
188
189
190
191
192
193
|
const getShowDragBar = computed(() => unref(getCanDrag));
onMounted(async () => {
menuModules.value = await getShallowMenus();
});
|
Vben
authored
|
194
|
listenerRouteChange((route) => {
|
vben
authored
|
195
|
currentRoute.value = route;
|
vben
authored
|
196
|
setActive(true);
|
vben
authored
|
197
|
if (unref(getCloseMixSidebarOnChange)) {
|
vben
authored
|
198
|
closeMenu();
|
vben
authored
|
199
200
201
|
}
});
|
vben
authored
|
202
203
204
205
206
207
208
209
210
211
|
function getWrapCommonStyle(width: string): CSSProperties {
return {
width,
maxWidth: width,
minWidth: width,
flex: `0 0 ${width}`,
};
}
// Process module menu click
|
|
212
|
async function handleModuleClick(path: string, hover = false) {
|
vben
authored
|
213
214
|
const children = await getChildrenMenus(path);
if (unref(activePath) === path) {
|
vben
authored
|
215
|
if (!hover) {
|
vben
authored
|
216
217
218
219
220
|
if (!unref(openMenu)) {
openMenu.value = true;
} else {
closeMenu();
}
|
|
221
222
223
224
|
} else {
if (!unref(openMenu)) {
openMenu.value = true;
}
|
vben
authored
|
225
|
}
|
vben
authored
|
226
227
228
229
230
231
232
233
234
|
if (!unref(openMenu)) {
setActive();
}
} else {
openMenu.value = true;
activePath.value = path;
}
if (!children || children.length === 0) {
|
|
235
236
|
if (!hover) go(path);
childrenMenus.value = [];
|
vben
authored
|
237
|
closeMenu();
|
vben
authored
|
238
239
|
return;
}
|
|
240
|
childrenMenus.value = children;
|
vben
authored
|
241
242
|
}
|
vben
authored
|
243
|
// Set the currently active menu and submenu
|
vben
authored
|
244
|
async function setActive(setChildren = false) {
|
vben
authored
|
245
246
|
const path = currentRoute.value?.path;
if (!path) return;
|
|
247
|
activePath.value = await getCurrentParentPath(path);
|
vben
authored
|
248
|
// hanldeModuleClick(parentPath);
|
vben
authored
|
249
|
if (unref(getIsMixSidebar)) {
|
vben
authored
|
250
251
252
253
254
|
const activeMenu = unref(menuModules).find((item) => item.path === unref(activePath));
const p = activeMenu?.path;
if (p) {
const children = await getChildrenMenus(p);
if (setChildren) {
|
|
255
|
childrenMenus.value = children;
|
vben
authored
|
256
257
258
259
|
if (unref(getMixSideFixed)) {
openMenu.value = children.length > 0;
}
|
vben
authored
|
260
261
|
}
if (children.length === 0) {
|
|
262
|
childrenMenus.value = [];
|
vben
authored
|
263
264
265
|
}
}
}
|
vben
authored
|
266
267
268
269
270
271
272
|
}
function handleMenuClick(path: string) {
go(path);
}
function handleClickOutside() {
|
vben
authored
|
273
|
setActive(true);
|
vben
authored
|
274
|
closeMenu();
|
vben
authored
|
275
276
|
}
|
vben
authored
|
277
278
279
|
function getItemEvents(item: Menu) {
if (unref(getMixSideTrigger) === 'hover') {
return {
|
|
280
281
282
283
284
|
onMouseenter: () => handleModuleClick(item.path, true),
onClick: async () => {
const children = await getChildrenMenus(item.path);
if (item.path && (!children || children.length === 0)) go(item.path);
},
|
vben
authored
|
285
286
287
|
};
}
return {
|
|
288
|
onClick: () => handleModuleClick(item.path),
|
vben
authored
|
289
290
291
|
};
}
|
vben
authored
|
292
293
294
295
296
297
|
function handleFixedMenu() {
setMenuSetting({
mixSideFixed: !unref(getIsFixed),
});
}
|
vben
authored
|
298
|
// Close menu
|
vben
authored
|
299
300
301
302
303
304
|
function closeMenu() {
if (!unref(getIsFixed)) {
openMenu.value = false;
}
}
|
vben
authored
|
305
306
307
308
|
return {
t,
prefixCls,
menuModules,
|
|
309
|
handleModuleClick: handleModuleClick,
|
vben
authored
|
310
|
activePath,
|
|
311
|
childrenMenus: childrenMenus,
|
vben
authored
|
312
313
314
315
316
317
318
319
320
|
getShowDragBar,
handleMenuClick,
getMenuStyle,
handleClickOutside,
sideRef,
dragBarRef,
title,
openMenu,
getMenuTheme,
|
vben
authored
|
321
322
|
getItemEvents,
getMenuEvents,
|
vben
authored
|
323
324
325
|
getDomStyle,
handleFixedMenu,
getMixSideFixed,
|
vben
authored
|
326
327
|
getWrapStyle,
getCollapsed,
|
vben
authored
|
328
329
330
331
332
333
334
335
336
337
338
339
340
341
|
};
},
});
</script>
<style lang="less">
@prefix-cls: ~'@{namespace}-layout-mix-sider';
@width: 80px;
.@{prefix-cls} {
position: fixed;
top: 0;
left: 0;
z-index: @layout-mix-sider-fixed-z-index;
height: 100%;
overflow: hidden;
|
Vben
authored
|
342
|
background-color: @sider-dark-bg-color;
|
vben
authored
|
343
|
transition: all 0.2s ease 0s;
|
vben
authored
|
344
|
|
vben
authored
|
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
|
&-dom {
height: 100%;
overflow: hidden;
transition: all 0.2s ease 0s;
}
&-logo {
display: flex;
height: @header-height;
padding-left: 0 !important;
justify-content: center;
img {
width: @logo-width;
height: @logo-width;
}
}
&.light {
.@{prefix-cls}-logo {
border-bottom: 1px solid rgb(238, 238, 238);
}
&.open {
|
vben
authored
|
369
|
> .scrollbar {
|
vben
authored
|
370
371
372
373
374
375
376
377
378
379
380
|
border-right: 1px solid rgb(238, 238, 238);
}
}
.@{prefix-cls}-module {
&__item {
font-weight: normal;
color: rgba(0, 0, 0, 0.65);
&--active {
color: @primary-color;
|
Vben
authored
|
381
|
background-color: unset;
|
vben
authored
|
382
383
384
|
}
}
}
|
vben
authored
|
385
|
.@{prefix-cls}-menu-list {
|
vben
authored
|
386
387
388
389
|
&__content {
box-shadow: 0 0 4px 0 rgba(0, 0, 0, 0.1);
}
|
vben
authored
|
390
391
392
393
394
395
396
397
398
399
|
&__title {
.pushpin {
color: rgba(0, 0, 0, 0.35);
&:hover {
color: rgba(0, 0, 0, 0.85);
}
}
}
}
|
vben
authored
|
400
|
}
|
Vben
authored
|
401
|
@border-color: @sider-dark-lighten-bg-color;
|
vben
authored
|
402
403
404
405
|
&.dark {
&.open {
.@{prefix-cls}-logo {
|
Vben
authored
|
406
|
// border-bottom: 1px solid @border-color;
|
vben
authored
|
407
408
|
}
|
vben
authored
|
409
|
> .scrollbar {
|
vben
authored
|
410
|
border-right: 1px solid @border-color;
|
vben
authored
|
411
412
413
|
}
}
.@{prefix-cls}-menu-list {
|
Vben
authored
|
414
|
background-color: @sider-dark-bg-color;
|
vben
authored
|
415
416
417
418
|
&__title {
color: @white;
border-bottom: none;
|
vben
authored
|
419
|
border-bottom: 1px solid @border-color;
|
vben
authored
|
420
421
422
423
|
}
}
}
|
vben
authored
|
424
|
> .scrollbar {
|
vben
authored
|
425
|
height: calc(100% - @header-height - 38px);
|
vben
authored
|
426
427
|
}
|
vben
authored
|
428
429
430
431
432
433
434
435
436
437
|
&.mini &-module {
&__name {
display: none;
}
&__icon {
margin-bottom: 0;
}
}
|
vben
authored
|
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
|
&-module {
position: relative;
padding-top: 1px;
&__item {
position: relative;
padding: 12px 0;
color: rgba(255, 255, 255, 0.65);
text-align: center;
cursor: pointer;
transition: all 0.3s ease;
&:hover {
color: @white;
}
// &:hover,
&--active {
font-weight: 700;
color: @white;
|
Vben
authored
|
457
|
background-color: @sider-dark-darken-bg-color;
|
vben
authored
|
458
459
460
461
462
463
464
|
&::before {
position: absolute;
top: 0;
left: 0;
width: 3px;
height: 100%;
|
Vben
authored
|
465
|
background-color: @primary-color;
|
vben
authored
|
466
467
468
469
470
471
472
473
|
content: '';
}
}
}
&__icon {
margin-bottom: 8px;
font-size: 24px;
|
vben
authored
|
474
|
transition: all 0.2s;
|
vben
authored
|
475
476
477
478
479
|
}
&__name {
margin-bottom: 0;
font-size: 12px;
|
vben
authored
|
480
|
transition: all 0.2s;
|
vben
authored
|
481
482
483
|
}
}
|
vben
authored
|
484
485
486
487
488
|
&-trigger {
position: absolute;
bottom: 0;
left: 0;
width: 100%;
|
|
489
|
font-size: 14px;
|
vben
authored
|
490
|
color: rgba(255, 255, 255, 0.65);
|
|
491
|
text-align: center;
|
vben
authored
|
492
|
cursor: pointer;
|
|
493
494
495
|
background-color: @trigger-dark-bg-color;
height: 36px;
line-height: 36px;
|
vben
authored
|
496
497
498
499
|
}
&.light &-trigger {
color: rgba(0, 0, 0, 0.65);
|
Vben
authored
|
500
|
background-color: #fff;
|
|
501
|
border-top: 1px solid #eee;
|
vben
authored
|
502
503
|
}
|
vben
authored
|
504
505
506
507
508
|
&-menu-list {
position: fixed;
top: 0;
width: 200px;
height: calc(100%);
|
Vben
authored
|
509
|
background-color: #fff;
|
vben
authored
|
510
|
transition: all 0.2s;
|
vben
authored
|
511
512
513
514
|
&__title {
display: flex;
height: @header-height;
|
vben
authored
|
515
|
// margin-left: -6px;
|
vben
authored
|
516
517
518
519
520
521
|
font-size: 18px;
color: @primary-color;
border-bottom: 1px solid rgb(238, 238, 238);
opacity: 0;
transition: unset;
align-items: center;
|
vben
authored
|
522
|
justify-content: space-between;
|
vben
authored
|
523
524
|
&.show {
|
vben
authored
|
525
|
min-width: 130px;
|
vben
authored
|
526
527
528
|
opacity: 1;
transition: all 0.5s ease;
}
|
vben
authored
|
529
530
531
532
533
534
535
536
537
538
|
.pushpin {
margin-right: 6px;
color: rgba(255, 255, 255, 0.65);
cursor: pointer;
&:hover {
color: #fff;
}
}
|
vben
authored
|
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
|
}
&__content {
height: calc(100% - @header-height) !important;
.scrollbar__wrap {
height: 100%;
overflow-x: hidden;
}
.scrollbar__bar.is-horizontal {
display: none;
}
.ant-menu {
height: 100%;
}
.ant-menu-inline,
.ant-menu-vertical,
.ant-menu-vertical-left {
border-right: 1px solid transparent;
}
}
}
&-drag-bar {
position: absolute;
|
vben
authored
|
567
568
569
570
|
top: 50px;
right: -1px;
width: 1px;
height: calc(100% - 50px);
|
vben
authored
|
571
|
cursor: ew-resize;
|
Vben
authored
|
572
|
background-color: #f8f8f9;
|
vben
authored
|
573
574
575
576
577
578
|
border-top: none;
border-bottom: none;
box-shadow: 0 0 4px 0 rgba(28, 36, 56, 0.15);
}
}
</style>
|