This commit is contained in:
zlwu committed 2026-10-13 15:18:01 +08:00
1 parent d08f03ab03
commit cc843535f5
154 files changed
+17837 -5153

No files matched your search

+16 -6
View File
@@ -46,6 +46,7 @@ import { useCommon } from '@/hooks/core/useCommon'
import { useMenuStore } from '@/store/modules/menu'
import { useSettingStore } from '@/store/modules/setting'
import { getFirstSecondLevelMenuPath, isWorkbenchRoute } from '@/utils/navigation/route'
import { shouldAddKeepAliveExclude } from '@/utils/navigation/keep-alive-exclude'
interface WorktabState {
current: Partial<WorkTab>
@@ -428,14 +429,23 @@ export const useWorktabStore = defineStore(
/**
* 将指定选项卡添加到 keepAlive 排除列表中
* @param options.force 点击已打开标签切换时传 true,即使标签仍在 opened 中也排除缓存以强制重新挂载
*/
const addKeepAliveExclude = (tab: WorkTab): void => {
if (!tab.keepAlive || !tab.name) return
// 同 name 多开:仍有其它同名标签时勿排除,否则会清掉其它实例缓存
if (opened.value.some((t) => t.name === tab.name)) return
const addKeepAliveExclude = (tab: WorkTab, options?: { force?: boolean }): void => {
const name = tab.name
if (
!shouldAddKeepAliveExclude({
tabName: name,
keepAlive: tab.keepAlive,
openedHasSameName: opened.value.some((t) => t.name === name),
force: options?.force
})
) {
return
}
if (!keepAliveExclude.value.includes(tab.name)) {
keepAliveExclude.value.push(tab.name)
if (name && !keepAliveExclude.value.includes(name)) {
keepAliveExclude.value.push(name)
}
}