From e89863900e80ef5db42638bb94c39f87850a9512 Mon Sep 17 00:00:00 2001 From: yangbin <1796443586@qq.com> Date: Tue, 25 Aug 2026 15:09:20 +0800 Subject: [PATCH] =?UTF-8?q?tab=E9=A1=B5=E9=9D=A2=E4=BF=AE=E6=94=B9=20=20?= =?UTF-8?q?=E5=8F=AA=E4=BF=9D=E6=8C=81=E6=9C=80=E8=BF=91=E7=9A=84=E5=85=AB?= =?UTF-8?q?=E4=B8=AA=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/store/modules/tagsView.js | 28 ++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/frontend/src/store/modules/tagsView.js b/frontend/src/store/modules/tagsView.js index d5d0deac..93c50827 100644 --- a/frontend/src/store/modules/tagsView.js +++ b/frontend/src/store/modules/tagsView.js @@ -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