This commit is contained in:
zlwu committed 2026-08-21 09:35:11 +08:00
1 parent b9ff9c9d67
commit 44749ae716
87 files changed
+35089 -21918

No files matched your search

+31 -4
View File
@@ -93,13 +93,31 @@ export const useWorktabStore = defineStore(
return opened.value.find((tab) => tab.path === path)
}
/** 门户首页(不可关闭、不可取消固定) */
const isHomeTab = (tab: Partial<WorkTab>): boolean => {
const home = HOME_PAGE_PATH || '/home'
return tab.path === home || tab.name === 'PortalHome'
}
/**
* 检查标签页是否可关闭
*/
const isTabClosable = (tab: WorkTab): boolean => {
if (isHomeTab(tab)) return false
return !tab.fixedTab
}
/** 确保首页始终为固定标签(修复持久化丢失 fixedTab 的情况) */
const ensureHomeTabFixed = (): void => {
const home = HOME_PAGE_PATH || '/home'
opened.value = opened.value.map((tab) =>
isHomeTab(tab) && !tab.fixedTab ? { ...tab, path: tab.path || home, fixedTab: true } : tab
)
if (current.value.path && isHomeTab(current.value) && !current.value.fixedTab) {
current.value = { ...current.value, fixedTab: true }
}
}
/**
* 过滤不应展示在 worktab 中的父级占位路由。
* `/system` 仅用于承载与重定向,真实标签页为其子路由(如 `/system/info/tenant`)。
@@ -247,7 +265,8 @@ export const useWorktabStore = defineStore(
}
if (existingIndex === -1) {
const newTab = { ...tab, fixedTab: singlePage ? false : tab.fixedTab }
const shouldFix = !singlePage && (Boolean(tab.fixedTab) || isHomeTab(tab))
const newTab = { ...tab, fixedTab: shouldFix }
if (singlePage) {
markTabsToRemove(opened.value.filter((t) => t.path !== newTab.path))
@@ -261,9 +280,9 @@ export const useWorktabStore = defineStore(
return
}
const insertIndex = tab.fixedTab ? findFixedTabInsertIndex() : opened.value.length
const insertIndex = shouldFix ? findFixedTabInsertIndex() : opened.value.length
if (tab.fixedTab) {
if (shouldFix) {
opened.value.splice(insertIndex, 0, newTab)
} else {
opened.value.push(newTab)
@@ -275,6 +294,8 @@ export const useWorktabStore = defineStore(
} else {
// 更新现有标签页(当动态路由参数或查询变更时,复用同一标签)
const existingTab = opened.value[existingIndex]
const shouldFix =
!singlePage && (Boolean(tab.fixedTab) || Boolean(existingTab.fixedTab) || isHomeTab(tab))
opened.value[existingIndex] = {
...existingTab,
@@ -282,7 +303,7 @@ export const useWorktabStore = defineStore(
params: tab.params,
query: tab.query,
title: tab.title || existingTab.title,
fixedTab: singlePage ? false : (tab.fixedTab ?? existingTab.fixedTab),
fixedTab: shouldFix,
keepAlive: tab.keepAlive ?? existingTab.keepAlive,
name: tab.name || existingTab.name,
icon: tab.icon || existingTab.icon
@@ -563,6 +584,10 @@ export const useWorktabStore = defineStore(
}
const tab = { ...opened.value[targetIndex] }
// 首页始终固定,不允许取消
if (isHomeTab(tab) && tab.fixedTab) {
return
}
tab.fixedTab = !tab.fixedTab
// 移除原位置
@@ -620,6 +645,8 @@ export const useWorktabStore = defineStore(
opened.value = validTabs
}
ensureHomeTabFixed()
if (isSinglePageMode()) {
enforceSinglePageTabs()
} else {