11<script setup>
2- const { tm , locale } = useI18n ();
2+ const { tm , _locale } = useI18n ();
33
44const getComp = computed (() => {
55 const textValue = tm (' BarLeft' );
@@ -75,6 +75,8 @@ const rowHeight = 32;
7575const chunkPading = 6 ;
7676const rowHeightpx = ` ${ rowHeight} px` ;
7777
78+ const thisElSubEnum = ref (undefined );
79+
7880const route = useRoute ();
7981
8082const openMenu = (MenuOpenEvent ) => {
@@ -94,17 +96,8 @@ const openMenu = (MenuOpenEvent) => {
9496 openMenuList .add (MenuOpenEvent);
9597};
9698
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-
10699const closeMenu = (MenuOpenEvent ) => {
107- deleteSetItem (MenuOpenEvent, openMenuList );
100+ openMenuList . delete (MenuOpenEvent);
108101 menuRef .value .close (MenuOpenEvent);
109102};
110103
@@ -123,17 +116,34 @@ const highlyIsQualified = (height) => {
123116
124117const { $mitt } = useNuxtApp ();
125118onMounted (() => {
126- $mitt .on (' routeSwitching' , () => {
127- nextTick (() => {
128- retractMenuBar ();
129- });
119+ $mitt .on (' mainDomChange' , () => {
120+ retractMenuBar ();
130121 });
131122});
132123onBeforeUnmount (() => {
133- $mitt .off (' routeSwitching ' );
124+ $mitt .off (' mainDomChange ' );
134125});
135126
127+ const routeMessage = useRouteMessageStore ();
136128const 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+
137147 let height = menuDivRef .value .clientHeight ;
138148 for (const item of openMenuList) {
139149 if (highlyIsQualified (height)) {
@@ -145,9 +155,6 @@ const retractMenuBar = () => {
145155 closeMenu (item);
146156 }
147157 }
148- // for (const item of openMenuList) {
149- // menuRef.value.open(item);
150- // }
151158};
152159onMounted (() => {
153160 // 每次缩放改变的时候,判断有没有栏目需要缩回去,先展开的,优先缩进
@@ -164,12 +171,11 @@ onMounted(() => {
164171 let height = menuDivRef .value .clientHeight ;
165172 // 初次加载的时候尝试打开当前栏目分类
166173 // 记一下目前所在分类的title
167- let thisElSubEnum = null ;
168174 for (const [index , item ] of navigationList .value .entries ()) {
169- if (thisElSubEnum === null ) {
175+ if (thisElSubEnum . value === undefined ) {
170176 if (item .children .find ((item1 ) => route .path .includes (item1 .url ))) {
171177 // 当前所在不入列尾
172- thisElSubEnum = index;
178+ thisElSubEnum . value = index;
173179 } else {
174180 openMenuList .add (String (index));
175181 }
@@ -183,7 +189,7 @@ onMounted(() => {
183189 if (highlyIsQualified (height)) {
184190 break ;
185191 }
186- if (thisElSubEnum !== index) {
192+ if (thisElSubEnum . value !== index) {
187193 height = height - (item .children .length * rowHeight + chunkPading);
188194 closeMenu (String (index));
189195 }
@@ -234,6 +240,7 @@ const backToTopBtnShow = ref(false);
234240 :default-openeds =" defaultOpeneds"
235241 @close =" closeMenu"
236242 @open =" openMenu" >
243+ <!-- 它的 index 要求是字符串不然控制台发警告 -->
237244 <el-sub-menu
238245 v-for =" (item, index) in navigationList"
239246 :key =" `barleft-1-link-${index}`"
0 commit comments