20260817225227

This commit is contained in:
oneao committed 2026-08-17 22:52:27 +08:00
1 parent d3acc7d28f
commit b90ae89b0e
39 files changed
+3861 -353

No files matched your search

+26 -7
View File
@@ -12,11 +12,21 @@ export const useAppStore = defineStore('app', {
/** 界面语言(占位:项目暂无 i18n 文案,仅保留切换状态) */
locale: 'zh-CN',
/** 已访问页签列表;工作台固定不可关闭 */
visitedTabs: [{ key: '/dashboard', label: '工作台', closable: false }],
visitedTabs: [{ key: '/dashboard', label: '工作台', closable: false, name: 'Dashboard' }],
/** 路由刷新计数表:key 为路由 fullPath,值变化即强制重渲染该路由 */
routeRefreshKeys: {},
}),
getters: {
/** keep-alive 的 include 列表:当前打开页签对应的组件名(去重)。
* 页签关闭时该集合随之缩小,keep-alive 据此销毁对应缓存实例,
* 实现"关闭页签即销毁缓存" */
cachedViews: (state) => {
const names = state.visitedTabs.map((t) => t.name).filter(Boolean)
return [...new Set(names)]
},
},
actions: {
setDark(value) {
this.darkMode = !!value
@@ -43,30 +53,39 @@ export const useAppStore = defineStore('app', {
removeVisitedTab(key) {
const index = this.visitedTabs.findIndex((t) => t.key === key)
if (index >= 0) this.visitedTabs.splice(index, 1)
// 同步清理该页签的刷新计数(对齐 old1:关闭即释放,避免 key 无限累积)
if (key in this.routeRefreshKeys) delete this.routeRefreshKeys[key]
},
/** 关闭其他:保留工作台(不可关)与指定 key */
closeOthers(key) {
this.visitedTabs = this.visitedTabs.filter(
(t) => t.key === '/dashboard' || t.key === key,
)
this.visitedTabs = this.visitedTabs.filter((t) => t.key === '/dashboard' || t.key === key)
this.pruneOrphanRefreshKeys()
},
/** 关闭左侧:保留工作台与指定 key 及其右侧 */
closeLeft(key) {
const idx = this.visitedTabs.findIndex((t) => t.key === key)
if (idx <= 0) return
this.visitedTabs = this.visitedTabs.filter(
(t, i) => i >= idx || t.key === '/dashboard',
)
this.visitedTabs = this.visitedTabs.filter((t, i) => i >= idx || t.key === '/dashboard')
this.pruneOrphanRefreshKeys()
},
/** 关闭右侧:保留指定 key 及其左侧(含工作台) */
closeRight(key) {
const idx = this.visitedTabs.findIndex((t) => t.key === key)
if (idx < 0) return
this.visitedTabs = this.visitedTabs.filter((t, i) => i <= idx)
this.pruneOrphanRefreshKeys()
},
/** 关闭全部:仅保留工作台 */
closeAll() {
this.visitedTabs = this.visitedTabs.filter((t) => t.key === '/dashboard')
this.pruneOrphanRefreshKeys()
},
/** 清理已关闭页签残留的刷新计数,避免 routeRefreshKeys 无限增长 */
pruneOrphanRefreshKeys() {
const keep = new Set(this.visitedTabs.map((t) => t.key))
for (const key of Object.keys(this.routeRefreshKeys)) {
if (!keep.has(key)) delete this.routeRefreshKeys[key]
}
},
getRouteRefreshKey(key) {
return this.routeRefreshKeys[key] ?? 0