This commit is contained in:
dap
2025-02-06 22:38:05 +08:00
11 changed files with 51 additions and 7 deletions

View File

@@ -20,6 +20,7 @@
}
},
"dependencies": {
"@vben-core/preferences": "workspace:*",
"@vben-core/shared": "workspace:*",
"@vben-core/typings": "workspace:*",
"pinia": "catalog:",

View File

@@ -1,13 +1,17 @@
import type { TabDefinition } from '@vben-core/typings';
import type { Router, RouteRecordNormalized } from 'vue-router';
import type { TabDefinition } from '@vben-core/typings';
import { toRaw } from 'vue';
import { preferences } from '@vben-core/preferences';
import {
openRouteInNewWindow,
startProgress,
stopProgress,
} from '@vben-core/shared/utils';
import { acceptHMRUpdate, defineStore } from 'pinia';
import { toRaw } from 'vue';
interface TabbarState {
/**
@@ -104,6 +108,7 @@ export const useTabbarStore = defineStore('core-tabbar', {
});
if (tabIndex === -1) {
const maxCount = preferences.tabbar.maxCount;
// 获取动态路由打开数,超过 0 即代表需要控制打开数
const maxNumOfOpenTab = (routeTab?.meta?.maxNumOfOpenTab ??
-1) as number;
@@ -119,8 +124,14 @@ export const useTabbarStore = defineStore('core-tabbar', {
(item) => item.name === routeTab.name,
);
index !== -1 && this.tabs.splice(index, 1);
} else if (maxCount > 0 && this.tabs.length >= maxCount) {
// 关闭第一个
const index = this.tabs.findIndex(
(item) =>
!Reflect.has(item.meta, 'affixTab') || !item.meta.affixTab,
);
index !== -1 && this.tabs.splice(index, 1);
}
this.tabs.push(tab);
} else {
// 页面已经存在,不重复添加选项卡,只更新选项卡参数