tab页面修改 只保持最近的八个页面

This commit is contained in:
2026-08-25 15:09:20 +08:00
parent 2d738549b5
commit e89863900e
+28
View File
@@ -1,6 +1,32 @@
import cache from '@/plugins/cache'
const PERSIST_KEY = 'tags-view-visited'
const MAX_VISITED_VIEWS = 8
function removeViewCache(state, view) {
const cachedViewIndex = state.cachedViews.indexOf(view.name)
if (cachedViewIndex > -1) {
state.cachedViews.splice(cachedViewIndex, 1)
}
state.iframeViews = state.iframeViews.filter(item => item.path !== view.path)
}
function trimVisitedViews(state, currentView) {
while (state.visitedViews.length > MAX_VISITED_VIEWS) {
const removableViewIndex = state.visitedViews.findIndex(view => {
const isAffix = view.meta && view.meta.affix
return !isAffix && view.path !== currentView.path
})
if (removableViewIndex === -1) {
return
}
const [removedView] = state.visitedViews.splice(removableViewIndex, 1)
removeViewCache(state, removedView)
}
}
// 布局已固定,不启用标签页持久化
function isPersistEnabled() {
@@ -43,6 +69,7 @@ const mutations = {
title: view.meta.title || 'no-name'
})
)
trimVisitedViews(state, view)
saveVisitedViews(state.visitedViews)
},
ADD_VISITED_VIEW_FIRST: (state, view) => {
@@ -52,6 +79,7 @@ const mutations = {
title: view.meta.title || 'no-name'
})
)
trimVisitedViews(state, view)
},
ADD_CACHED_VIEW: (state, view) => {
if (state.cachedViews.includes(view.name)) return