Skip to content

Commit 88843ab

Browse files
committed
perf: perf the control logic of Tab
* 解决AI提示的警告
1 parent 9388983 commit 88843ab

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

packages/stores/src/modules/tabbar.ts

+14-8
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export const useTabbarStore = defineStore('core-tabbar', {
6363
(item) => !keySet.has(getTabKeyFromTab(item)),
6464
);
6565

66-
this.updateCacheTabs();
66+
await this.updateCacheTabs();
6767
},
6868
/**
6969
* @zh_CN 关闭标签页
@@ -107,7 +107,7 @@ export const useTabbarStore = defineStore('core-tabbar', {
107107
* @param routeTab
108108
*/
109109
addTab(routeTab: TabDefinition): TabDefinition {
110-
const tab = cloneTab(routeTab);
110+
let tab = cloneTab(routeTab);
111111
if (!tab.key) {
112112
tab.key = getTabKey(routeTab);
113113
}
@@ -162,7 +162,7 @@ export const useTabbarStore = defineStore('core-tabbar', {
162162
mergedTab.meta.newTabTitle = curMeta.newTabTitle;
163163
}
164164
}
165-
165+
tab = mergedTab;
166166
this.tabs.splice(tabIndex, 1, mergedTab);
167167
}
168168
this.updateCacheTabs();
@@ -609,16 +609,22 @@ function getTabKey(tab: RouteLocationNormalized | RouteRecordNormalized) {
609609
fullPath,
610610
path,
611611
meta: { fullPathKey } = {},
612-
query: { pageKey } = {},
612+
query = {},
613613
} = tab as RouteLocationNormalized;
614+
// pageKey可能是数组(查询参数重复时可能出现)
615+
const pageKey = Array.isArray(query.pageKey)
616+
? query.pageKey[0]
617+
: query.pageKey;
618+
let rawKey;
614619
if (pageKey) {
615-
return pageKey as string;
620+
rawKey = pageKey;
621+
} else {
622+
rawKey = fullPathKey === false ? path : (fullPath ?? path);
616623
}
617-
const rawKey = fullPathKey === false ? path : fullPath;
618624
try {
619-
return decodeURIComponent(rawKey || path);
625+
return decodeURIComponent(rawKey);
620626
} catch {
621-
return rawKey || path;
627+
return rawKey;
622628
}
623629
}
624630

0 commit comments

Comments
 (0)