|
@@ -26,6 +26,15 @@ function handleGotoPage(router: Router) {
|
|
|
go(unref(router.currentRoute).path, true);
|
|
|
}
|
|
|
|
|
|
+const getToTarget = (tabItem: RouteLocationNormalized) => {
|
|
|
+ const { params, path, query } = tabItem;
|
|
|
+ return {
|
|
|
+ params: params || {},
|
|
|
+ path,
|
|
|
+ query: query || {},
|
|
|
+ };
|
|
|
+};
|
|
|
+
|
|
|
const cacheTab = projectSetting.multiTabsSetting.cache;
|
|
|
|
|
|
export const useMultipleTabStore = defineStore({
|
|
@@ -147,15 +156,6 @@ export const useMultipleTabStore = defineStore({
|
|
|
},
|
|
|
|
|
|
async closeTab(tab: RouteLocationNormalized, router: Router) {
|
|
|
- const getToTarget = (tabItem: RouteLocationNormalized) => {
|
|
|
- const { params, path, query } = tabItem;
|
|
|
- return {
|
|
|
- params: params || {},
|
|
|
- path,
|
|
|
- query: query || {},
|
|
|
- };
|
|
|
- };
|
|
|
-
|
|
|
const close = (route: RouteLocationNormalized) => {
|
|
|
const { fullPath, meta: { affix } = {} } = route;
|
|
|
if (affix) {
|
|
@@ -196,13 +196,36 @@ export const useMultipleTabStore = defineStore({
|
|
|
toTarget = getToTarget(page);
|
|
|
}
|
|
|
close(currentRoute.value);
|
|
|
- replace(toTarget);
|
|
|
+ await replace(toTarget);
|
|
|
},
|
|
|
|
|
|
// Close according to key
|
|
|
async closeTabByKey(key: string, router: Router) {
|
|
|
const index = this.tabList.findIndex((item) => (item.fullPath || item.path) === key);
|
|
|
- index !== -1 && this.closeTab(this.tabList[index], router);
|
|
|
+ if (index !== -1) {
|
|
|
+ await this.closeTab(this.tabList[index], router);
|
|
|
+ const { currentRoute, replace } = router;
|
|
|
+ // 检查当前路由是否存在于tabList中
|
|
|
+ const isActivated = this.tabList.findIndex((item) => {
|
|
|
+ return item.fullPath === currentRoute.value.fullPath;
|
|
|
+ });
|
|
|
+ // 如果当前路由不存在于TabList中,尝试切换到其它路由
|
|
|
+ if (isActivated === -1) {
|
|
|
+ let pageIndex;
|
|
|
+ if (index > 0) {
|
|
|
+ pageIndex = index - 1;
|
|
|
+ } else if (index < this.tabList.length - 1) {
|
|
|
+ pageIndex = index + 1;
|
|
|
+ } else {
|
|
|
+ pageIndex = -1;
|
|
|
+ }
|
|
|
+ if (pageIndex >= 0) {
|
|
|
+ const page = this.tabList[index - 1];
|
|
|
+ const toTarget = getToTarget(page);
|
|
|
+ await replace(toTarget);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
},
|
|
|
|
|
|
// Sort the tabs
|