forked from liweijie/education
Merge branch 'main' of https://gitea.fengyingkj.top/zhaichao/education
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user