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

+1
View File
@@ -8,3 +8,4 @@
export * from './jump'
export * from './worktab'
export * from './route'
export * from './keep-alive-exclude'
@@ -0,0 +1,58 @@
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
import { shouldAddKeepAliveExclude } from './keep-alive-exclude'
describe('shouldAddKeepAliveExclude', () => {
it('returns false when tab has no name or keepAlive is off', () => {
assert.equal(
shouldAddKeepAliveExclude({
tabName: undefined,
keepAlive: true,
openedHasSameName: false
}),
false
)
assert.equal(
shouldAddKeepAliveExclude({
tabName: 'CellStorageProtocolAudit',
keepAlive: false,
openedHasSameName: false
}),
false
)
})
it('skips exclude when same-name tab still open (close / worktabMulti guard)', () => {
assert.equal(
shouldAddKeepAliveExclude({
tabName: 'CellStorageProtocolAudit',
keepAlive: true,
openedHasSameName: true
}),
false
)
})
it('allows exclude when no same-name tab remains open', () => {
assert.equal(
shouldAddKeepAliveExclude({
tabName: 'ProductionPreTransitSample',
keepAlive: true,
openedHasSameName: false
}),
true
)
})
it('force=true excludes even when the tab is still in opened (tab click reload)', () => {
assert.equal(
shouldAddKeepAliveExclude({
tabName: 'CellStorageProtocolAudit',
keepAlive: true,
openedHasSameName: true,
force: true
}),
true
)
})
})
@@ -0,0 +1,17 @@
/**
* 判断是否应将组件名加入 KeepAlive exclude,以清除缓存并强制重新挂载。
*
* - 关闭标签:若仍有同名标签(worktabMulti),勿排除,避免清掉其它实例缓存
* - 点击已打开标签切换:force=true,即使标签仍在 opened 中也要排除,以强制重新加载
*/
export function shouldAddKeepAliveExclude(params: {
tabName?: string
keepAlive?: boolean
openedHasSameName: boolean
force?: boolean
}): boolean {
if (!params.keepAlive || !params.tabName) return false
if (params.force) return true
if (params.openedHasSameName) return false
return true
}