1
1
<script lang="ts" setup>
2
+ import { computed , useSlots } from ' vue' ;
3
+
2
4
import { preferences , usePreferences } from ' @vben/preferences' ;
3
5
import { useAccessStore } from ' @vben/stores' ;
4
6
import { VbenFullScreen } from ' @vben-core/shadcn-ui' ;
@@ -22,26 +24,100 @@ withDefaults(defineProps<Props>(), {
22
24
23
25
const accessStore = useAccessStore ();
24
26
const { globalSearchShortcutKey } = usePreferences ();
27
+ const slots = useSlots ();
28
+ const rightSlots = computed (() => {
29
+ const list = [{ index: 30 , name: ' user-dropdown' }];
30
+ if (preferences .widget .globalSearch ) {
31
+ list .push ({
32
+ index: 5 ,
33
+ name: ' global-search' ,
34
+ });
35
+ }
36
+ if (preferences .widget .themeToggle ) {
37
+ list .push ({
38
+ index: 10 ,
39
+ name: ' theme-toggle' ,
40
+ });
41
+ }
42
+ if (preferences .widget .languageToggle ) {
43
+ list .push ({
44
+ index: 15 ,
45
+ name: ' language-toggle' ,
46
+ });
47
+ }
48
+ if (preferences .widget .fullscreen ) {
49
+ list .push ({
50
+ index: 20 ,
51
+ name: ' fullscreen' ,
52
+ });
53
+ }
54
+ if (preferences .widget .notification ) {
55
+ list .push ({
56
+ index: 25 ,
57
+ name: ' notification' ,
58
+ });
59
+ }
60
+
61
+ Object .keys (slots ).forEach ((key ) => {
62
+ const name = key .split (' -' );
63
+ if (key .startsWith (' header-right' )) {
64
+ list .push ({ index: Number (name [2 ]), name: key });
65
+ }
66
+ });
67
+ return list .sort ((a , b ) => a .index - b .index );
68
+ });
69
+ const leftSlots = computed (() => {
70
+ const list: any [] = [];
71
+
72
+ Object .keys (slots ).forEach ((key ) => {
73
+ const name = key .split (' -' );
74
+ if (key .startsWith (' header-left' )) {
75
+ list .push ({ index: Number (name [2 ]), name: key });
76
+ }
77
+ });
78
+ return list .sort ((a , b ) => a .index - b .index );
79
+ });
25
80
</script >
26
81
27
82
<template >
83
+ <template
84
+ v-for =" slot in leftSlots .filter ((item ) => item .index < 5 )"
85
+ :key =" slot .name "
86
+ >
87
+ <slot :name =" slot.name" ></slot >
88
+ </template >
28
89
<div class =" flex-center hidden lg:block" >
29
90
<slot name =" breadcrumb" ></slot >
30
91
</div >
92
+ <template
93
+ v-for =" slot in leftSlots .filter ((item ) => item .index > 5 )"
94
+ :key =" slot .name "
95
+ >
96
+ <slot :name =" slot.name" ></slot >
97
+ </template >
31
98
<div class =" flex h-full min-w-0 flex-1 items-center" >
32
99
<slot name =" menu" ></slot >
33
100
</div >
34
101
<div class =" flex h-full min-w-0 flex-shrink-0 items-center" >
35
- <GlobalSearch
36
- v-if =" preferences.widget.globalSearch"
37
- :enable-shortcut-key =" globalSearchShortcutKey"
38
- :menus =" accessStore.accessMenus"
39
- class =" mr-4"
40
- />
41
- <ThemeToggle v-if =" preferences.widget.themeToggle" class =" mr-2" />
42
- <LanguageToggle v-if =" preferences.widget.languageToggle" class =" mr-2" />
43
- <VbenFullScreen v-if =" preferences.widget.fullscreen" class =" mr-2" />
44
- <slot v-if =" preferences.widget.notification" name =" notification" ></slot >
45
- <slot name =" user-dropdown" ></slot >
102
+ <template v-for =" slot in rightSlots " :key =" slot .name " >
103
+ <slot :name =" slot.name" >
104
+ <template v-if =" slot .name === ' global-search' " >
105
+ <GlobalSearch
106
+ :enable-shortcut-key =" globalSearchShortcutKey"
107
+ :menus =" accessStore.accessMenus"
108
+ class =" mr-4"
109
+ />
110
+ </template >
111
+ <template v-else-if =" slot .name === ' theme-toggle' " >
112
+ <ThemeToggle class =" mr-2" />
113
+ </template >
114
+ <template v-else-if =" slot .name === ' language-toggle' " >
115
+ <LanguageToggle class =" mr-2" />
116
+ </template >
117
+ <template v-else-if =" slot .name === ' fullscreen' " >
118
+ <VbenFullScreen class =" mr-2" />
119
+ </template >
120
+ </slot >
121
+ </template >
46
122
</div >
47
123
</template >
0 commit comments