tab页面修改 只保持最近的八个页面
This commit is contained in:
@@ -1,6 +1,32 @@
|
|||||||
import cache from '@/plugins/cache'
|
import cache from '@/plugins/cache'
|
||||||
|
|
||||||
const PERSIST_KEY = 'tags-view-visited'
|
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() {
|
function isPersistEnabled() {
|
||||||
@@ -43,6 +69,7 @@ const mutations = {
|
|||||||
title: view.meta.title || 'no-name'
|
title: view.meta.title || 'no-name'
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
trimVisitedViews(state, view)
|
||||||
saveVisitedViews(state.visitedViews)
|
saveVisitedViews(state.visitedViews)
|
||||||
},
|
},
|
||||||
ADD_VISITED_VIEW_FIRST: (state, view) => {
|
ADD_VISITED_VIEW_FIRST: (state, view) => {
|
||||||
@@ -52,6 +79,7 @@ const mutations = {
|
|||||||
title: view.meta.title || 'no-name'
|
title: view.meta.title || 'no-name'
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
trimVisitedViews(state, view)
|
||||||
},
|
},
|
||||||
ADD_CACHED_VIEW: (state, view) => {
|
ADD_CACHED_VIEW: (state, view) => {
|
||||||
if (state.cachedViews.includes(view.name)) return
|
if (state.cachedViews.includes(view.name)) return
|
||||||
|
|||||||
Reference in New Issue
Block a user