1
1
<script setup>
2
- const { tm , locale } = useI18n ();
2
+ const { tm , _locale } = useI18n ();
3
3
4
4
const getComp = computed (() => {
5
5
const textValue = tm (' BarLeft' );
@@ -75,6 +75,8 @@ const rowHeight = 32;
75
75
const chunkPading = 6 ;
76
76
const rowHeightpx = ` ${ rowHeight} px` ;
77
77
78
+ const thisElSubEnum = ref (undefined );
79
+
78
80
const route = useRoute ();
79
81
80
82
const openMenu = (MenuOpenEvent ) => {
@@ -94,17 +96,8 @@ const openMenu = (MenuOpenEvent) => {
94
96
openMenuList .add (MenuOpenEvent);
95
97
};
96
98
97
- const deleteSetItem = (target , setList ) => {
98
- for (const item of setList) {
99
- if (item === target) {
100
- setList .delete (item);
101
- break ;
102
- }
103
- }
104
- };
105
-
106
99
const closeMenu = (MenuOpenEvent ) => {
107
- deleteSetItem (MenuOpenEvent, openMenuList );
100
+ openMenuList . delete (MenuOpenEvent);
108
101
menuRef .value .close (MenuOpenEvent);
109
102
};
110
103
@@ -123,17 +116,34 @@ const highlyIsQualified = (height) => {
123
116
124
117
const { $mitt } = useNuxtApp ();
125
118
onMounted (() => {
126
- $mitt .on (' routeSwitching' , () => {
127
- nextTick (() => {
128
- retractMenuBar ();
129
- });
119
+ $mitt .on (' mainDomChange' , () => {
120
+ retractMenuBar ();
130
121
});
131
122
});
132
123
onBeforeUnmount (() => {
133
- $mitt .off (' routeSwitching ' );
124
+ $mitt .off (' mainDomChange ' );
134
125
});
135
126
127
+ const routeMessage = useRouteMessageStore ();
136
128
const retractMenuBar = () => {
129
+ let thisElSubEnmu_cache = undefined ;
130
+ if (routeMessage .toPath !== ' /' ) {
131
+ for (const [index , item ] of navigationList .value .entries ()) {
132
+ if (
133
+ item .children .find ((item1 ) => routeMessage .toPath .includes (item1 .url ))
134
+ ) {
135
+ // 当前所在不入列尾
136
+ thisElSubEnmu_cache = index;
137
+ break ;
138
+ }
139
+ }
140
+ if (thisElSubEnum .value !== undefined )
141
+ openMenuList .add (String (thisElSubEnum .value ));
142
+
143
+ openMenuList .delete (String (thisElSubEnmu_cache));
144
+ thisElSubEnum .value = thisElSubEnmu_cache;
145
+ }
146
+
137
147
let height = menuDivRef .value .clientHeight ;
138
148
for (const item of openMenuList) {
139
149
if (highlyIsQualified (height)) {
@@ -145,9 +155,6 @@ const retractMenuBar = () => {
145
155
closeMenu (item);
146
156
}
147
157
}
148
- // for (const item of openMenuList) {
149
- // menuRef.value.open(item);
150
- // }
151
158
};
152
159
onMounted (() => {
153
160
// 每次缩放改变的时候,判断有没有栏目需要缩回去,先展开的,优先缩进
@@ -164,12 +171,11 @@ onMounted(() => {
164
171
let height = menuDivRef .value .clientHeight ;
165
172
// 初次加载的时候尝试打开当前栏目分类
166
173
// 记一下目前所在分类的title
167
- let thisElSubEnum = null ;
168
174
for (const [index , item ] of navigationList .value .entries ()) {
169
- if (thisElSubEnum === null ) {
175
+ if (thisElSubEnum . value === undefined ) {
170
176
if (item .children .find ((item1 ) => route .path .includes (item1 .url ))) {
171
177
// 当前所在不入列尾
172
- thisElSubEnum = index;
178
+ thisElSubEnum . value = index;
173
179
} else {
174
180
openMenuList .add (String (index));
175
181
}
@@ -183,7 +189,7 @@ onMounted(() => {
183
189
if (highlyIsQualified (height)) {
184
190
break ;
185
191
}
186
- if (thisElSubEnum !== index) {
192
+ if (thisElSubEnum . value !== index) {
187
193
height = height - (item .children .length * rowHeight + chunkPading);
188
194
closeMenu (String (index));
189
195
}
@@ -234,6 +240,7 @@ const backToTopBtnShow = ref(false);
234
240
:default-openeds =" defaultOpeneds"
235
241
@close =" closeMenu"
236
242
@open =" openMenu" >
243
+ <!-- 它的 index 要求是字符串不然控制台发警告 -->
237
244
<el-sub-menu
238
245
v-for =" (item, index) in navigationList"
239
246
:key =" `barleft-1-link-${index}`"
0 commit comments