@@ -4,12 +4,12 @@ import { emitter } from "@/utils/mitt";
44import { RouteConfigs } from " ../../types" ;
55import { useTags } from " ../../hooks/useTag" ;
66import { routerArrays } from " @/layout/types" ;
7- import { isEqual , isAllEmpty } from " @pureadmin/utils" ;
87import { handleAliveRoute , getTopMenu } from " @/router/utils" ;
98import { useSettingStoreHook } from " @/store/modules/settings" ;
9+ import { useResizeObserver , useFullscreen } from " @vueuse/core" ;
10+ import { isEqual , isAllEmpty , debounce } from " @pureadmin/utils" ;
1011import { useMultiTagsStoreHook } from " @/store/modules/multiTags" ;
1112import { ref , watch , unref , toRaw , nextTick , onBeforeUnmount } from " vue" ;
12- import { useResizeObserver , useDebounceFn , useFullscreen } from " @vueuse/core" ;
1313
1414import ExitFullscreen from " @iconify-icons/ri/fullscreen-exit-fill" ;
1515import Fullscreen from " @iconify-icons/ri/fullscreen-fill" ;
@@ -54,20 +54,22 @@ const topPath = getTopMenu()?.path;
5454const { VITE_HIDE_HOME } = import .meta .env ;
5555const { isFullscreen, toggle } = useFullscreen ();
5656
57- const dynamicTagView = () => {
57+ const dynamicTagView = async () => {
58+ await nextTick ();
5859 const index = multiTags .value .findIndex (item => {
59- if (item .query ) {
60+ if (! isAllEmpty ( route .query ) ) {
6061 return isEqual (route .query , item .query );
61- } else if (item .params ) {
62+ } else if (! isAllEmpty ( route .params ) ) {
6263 return isEqual (route .params , item .params );
6364 } else {
64- return item .path === route .path ;
65+ return route .path === item .path ;
6566 }
6667 });
6768 moveToView (index );
6869};
6970
7071const moveToView = async (index : number ): Promise <void > => {
72+ await nextTick ();
7173 const tabNavPadding = 10 ;
7274 if (! instance .refs [" dynamic" + index ]) return ;
7375 const tabItemEl = instance .refs [" dynamic" + index ][0 ];
@@ -78,9 +80,6 @@ const moveToView = async (index: number): Promise<void> => {
7880 ? scrollbarDom .value ?.offsetWidth
7981 : 0 ;
8082
81- // 获取视图更新后dom
82- await nextTick ();
83-
8483 // 已有标签页总长度(包含溢出部分)
8584 const tabDomWidth = tabDom .value ? tabDom .value ?.offsetWidth : 0 ;
8685
@@ -135,31 +134,29 @@ const handleScroll = (offset: number): void => {
135134 }
136135};
137136
138- function dynamicRouteTag(value : string , parentPath : string ): void {
137+ function dynamicRouteTag(value : string ): void {
139138 const hasValue = multiTags .value .some (item => {
140139 return item .path === value ;
141140 });
142141
143- function concatPath(arr : object [], value : string , parentPath : string ) {
142+ function concatPath(arr : object [], value : string ) {
144143 if (! hasValue ) {
145144 arr .forEach ((arrItem : any ) => {
146- const pathConcat = parentPath + arrItem .path ;
147- if (arrItem .path === value || pathConcat === value ) {
145+ if (arrItem .path === value || arrItem .path === value ) {
148146 useMultiTagsStoreHook ().handleTags (" push" , {
149147 path: value ,
150- parentPath: ` /${parentPath .split (" /" )[1 ]} ` ,
151148 meta: arrItem .meta ,
152149 name: arrItem .name
153150 });
154151 } else {
155152 if (arrItem .children && arrItem .children .length > 0 ) {
156- concatPath (arrItem .children , value , parentPath );
153+ concatPath (arrItem .children , value );
157154 }
158155 }
159156 });
160157 }
161158 }
162- concatPath (router .options .routes as any , value , parentPath );
159+ concatPath (router .options .routes as any , value );
163160}
164161
165162/** 刷新路由 */
@@ -465,7 +462,7 @@ function tagOnClick(item) {
465462 // showMenuModel(item?.path, item?.query);
466463}
467464
468- watch ([ route ] , () => {
465+ watch (route , () => {
469466 activeIndex .value = - 1 ;
470467 dynamicTagView ();
471468});
@@ -493,18 +490,16 @@ onMounted(() => {
493490 });
494491
495492 // 接收侧边栏切换传递过来的参数
496- emitter .on (" changLayoutRoute" , ({ indexPath , parentPath }) => {
497- dynamicRouteTag (indexPath , parentPath );
493+ emitter .on (" changLayoutRoute" , ({ indexPath }) => {
494+ dynamicRouteTag (indexPath );
498495 setTimeout (() => {
499496 showMenuModel (indexPath );
500497 });
501498 });
502499
503500 useResizeObserver (
504501 scrollbarDom ,
505- useDebounceFn (() => {
506- dynamicTagView ();
507- }, 200 )
502+ debounce (() => dynamicTagView ())
508503 );
509504});
510505
0 commit comments