提交
This commit is contained in:
1 parent
3d98104455
commit
0d52442902
76 files changed
+21994
-12642
No files matched your search
@@ -206,9 +206,9 @@ export const useWorktabStore = defineStore(
|
||||
removeKeepAliveExclude(tab.name)
|
||||
}
|
||||
|
||||
// 先根据路由名称查找(应对动态路由参数导致的多开问题),找不到再根据路径查找
|
||||
// 默认:先按 name 复用(动态参数同页);worktabMulti 仅按 path 匹配以支持同 name 多开
|
||||
let existingIndex = -1
|
||||
if (tab.name) {
|
||||
if (!tab.worktabMulti && tab.name) {
|
||||
existingIndex = opened.value.findIndex((t) => t.name === tab.name)
|
||||
}
|
||||
if (existingIndex === -1) {
|
||||
@@ -239,6 +239,7 @@ export const useWorktabStore = defineStore(
|
||||
title: tab.title || existingTab.title,
|
||||
fixedTab: tab.fixedTab ?? existingTab.fixedTab,
|
||||
keepAlive: tab.keepAlive ?? existingTab.keepAlive,
|
||||
worktabMulti: tab.worktabMulti ?? existingTab.worktabMulti,
|
||||
name: tab.name || existingTab.name,
|
||||
icon: tab.icon || existingTab.icon
|
||||
}
|
||||
@@ -430,6 +431,8 @@ export const useWorktabStore = defineStore(
|
||||
*/
|
||||
const addKeepAliveExclude = (tab: WorkTab): void => {
|
||||
if (!tab.keepAlive || !tab.name) return
|
||||
// 同 name 多开:仍有其它同名标签时勿排除,否则会清掉其它实例缓存
|
||||
if (opened.value.some((t) => t.name === tab.name)) return
|
||||
|
||||
if (!keepAliveExclude.value.includes(tab.name)) {
|
||||
keepAliveExclude.value.push(tab.name)
|
||||
@@ -449,9 +452,15 @@ export const useWorktabStore = defineStore(
|
||||
* 将传入的一组选项卡的组件名称标记为排除缓存
|
||||
*/
|
||||
const markTabsToRemove = (tabs: WorkTab[]): void => {
|
||||
const removePaths = new Set(tabs.map((t) => t.path))
|
||||
tabs.forEach((tab) => {
|
||||
if (tab.name) {
|
||||
addKeepAliveExclude(tab)
|
||||
if (!tab.keepAlive || !tab.name) return
|
||||
const stillOpen = opened.value.some(
|
||||
(t) => t.name === tab.name && !removePaths.has(t.path)
|
||||
)
|
||||
if (stillOpen) return
|
||||
if (!keepAliveExclude.value.includes(tab.name)) {
|
||||
keepAliveExclude.value.push(tab.name)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user