Commit 7b0c1690 authored by jingnan's avatar jingnan 👀

历史页签缓存至localstorage

parent 2e589749
...@@ -214,25 +214,25 @@ export default { ...@@ -214,25 +214,25 @@ export default {
}, },
getVisitedViews() { getVisitedViews() {
setTimeout(() => { setTimeout(() => {
if (!this.$utils._get(this.showViews, this.activeModel.id)) { // if (!this.$utils._get(this.showViews, this.activeModel.id)) {
this.visitedViews = [] // this.visitedViews = []
} else { // } else {
// this.$set(this, 'visitedViews', this.$store.state.tagsView.visitedViews[this.activeModel.id].filter(x => (x.path !== '/dee-task-center/workflow/task-center/home'))) // this.$set(this, 'visitedViews', this.$store.state.tagsView.visitedViews[this.activeModel.id].filter(x => (x.path !== '/dee-task-center/workflow/task-center/home')))
let list = [] let list = []
Object.keys(this.$store.state.tagsView.visitedViews).forEach(key => { Object.keys(this.$store.state.tagsView.visitedViews).forEach(key => {
list = [...list, ...this.$store.state.tagsView.visitedViews[key]] list = [...list, ...this.$store.state.tagsView.visitedViews[key]]
}) })
const filterViews = list.filter(x => (x.path !== '/home' && x.path !== '/businessHome' && x.path !== '/systemHome' && x.path !== '/DevopsHome' && x.path !== '/safeHome')) const filterViews = list.filter(x => (x.path !== '/home' && x.path !== '/businessHome' && x.path !== '/systemHome' && x.path !== '/DevopsHome' && x.path !== '/safeHome'))
const tempViews = filterViews.reduce((acc, current) => { const tempViews = filterViews.reduce((acc, current) => {
const exists = acc.find(item => item.title === current.title) const exists = acc.find(item => item.title === current.title)
if (!exists) { if (!exists) {
acc.push(current) acc.push(current)
} }
return acc return acc
}, []) }, [])
this.$set(this, 'visitedViews', tempViews) this.$set(this, 'visitedViews', tempViews)
// this.$set(this, 'visitedViews', list.filter(x => (x.path !== '/home' && x.path !== '/businessHome' && x.path !== '/systemHome' && x.path !== '/DevopsHome' && x.path !== '/safeHome'))) // this.$set(this, 'visitedViews', list.filter(x => (x.path !== '/home' && x.path !== '/businessHome' && x.path !== '/systemHome' && x.path !== '/DevopsHome' && x.path !== '/safeHome')))
} // }
}, 0) }, 0)
}, },
// 更新标签 title // 更新标签 title
......
const state = { const state = {
visitedViews: sessionStorage.getItem('visitedViews') ? JSON.parse(sessionStorage.getItem('visitedViews')) : {}, visitedViews: localStorage.getItem('visitedViews') ? JSON.parse(localStorage.getItem('visitedViews')) : {},
cachedViews: [], cachedViews: [],
previousRouter: [], previousRouter: [],
cachedMenuPages: {} cachedMenuPages: {}
...@@ -8,7 +8,7 @@ const state = { ...@@ -8,7 +8,7 @@ const state = {
const mutations = { const mutations = {
ADD_VISITED_VIEW: (state, view) => { ADD_VISITED_VIEW: (state, view) => {
if(view.belongModel !== 'todoTask' && view.path.includes('/dee-task-center/workflow/task-center/home')) return if (view.belongModel !== 'todoTask' && view.path.includes('/dee-task-center/workflow/task-center/home')) return
state.previousRouter.unshift({ ...view }) // 记录前一路由地址 state.previousRouter.unshift({ ...view }) // 记录前一路由地址
state.previousRouter = state.previousRouter.splice(0, 2) state.previousRouter = state.previousRouter.splice(0, 2)
const belongModel = sessionStorage.getItem('activePageModel') ? JSON.parse(sessionStorage.getItem('activePageModel')).id : 'todoTask' const belongModel = sessionStorage.getItem('activePageModel') ? JSON.parse(sessionStorage.getItem('activePageModel')).id : 'todoTask'
...@@ -40,6 +40,7 @@ const mutations = { ...@@ -40,6 +40,7 @@ const mutations = {
state.visitedViews[belongModel].shift() state.visitedViews[belongModel].shift()
}*/ }*/
sessionStorage.setItem('visitedViews', JSON.stringify(state.visitedViews)) sessionStorage.setItem('visitedViews', JSON.stringify(state.visitedViews))
localStorage.setItem('visitedViews', JSON.stringify(state.visitedViews))
}, },
ADD_CACHED_VIEW: (state, view) => { ADD_CACHED_VIEW: (state, view) => {
if (state.cachedViews.includes(view.name) || view.name === 'navigation') return if (state.cachedViews.includes(view.name) || view.name === 'navigation') return
...@@ -61,6 +62,7 @@ const mutations = { ...@@ -61,6 +62,7 @@ const mutations = {
} }
} }
sessionStorage.setItem('visitedViews', JSON.stringify(state.visitedViews)) sessionStorage.setItem('visitedViews', JSON.stringify(state.visitedViews))
localStorage.setItem('visitedViews', JSON.stringify(state.visitedViews))
}, },
DEL_CACHED_VIEW: (state, view) => { DEL_CACHED_VIEW: (state, view) => {
const index = state.cachedViews.indexOf(view.name) const index = state.cachedViews.indexOf(view.name)
...@@ -76,6 +78,7 @@ const mutations = { ...@@ -76,6 +78,7 @@ const mutations = {
return v.meta.affix || v.path === view.path return v.meta.affix || v.path === view.path
}) })
sessionStorage.setItem('visitedViews', JSON.stringify(state.visitedViews)) sessionStorage.setItem('visitedViews', JSON.stringify(state.visitedViews))
localStorage.setItem('visitedViews', JSON.stringify(state.visitedViews))
}, },
DEL_OTHERS_CACHED_VIEWS: (state, view) => { DEL_OTHERS_CACHED_VIEWS: (state, view) => {
const index = state.cachedViews.indexOf(view.name) const index = state.cachedViews.indexOf(view.name)
...@@ -90,6 +93,7 @@ const mutations = { ...@@ -90,6 +93,7 @@ const mutations = {
DEL_ALL_VISITED_VIEWS: state => { DEL_ALL_VISITED_VIEWS: state => {
state.visitedViews = {} state.visitedViews = {}
sessionStorage.setItem('visitedViews', '{}') sessionStorage.setItem('visitedViews', '{}')
// localStorage.setItem('visitedViews', '{}')
}, },
DEL_ALL_CACHED_VIEWS: state => { DEL_ALL_CACHED_VIEWS: state => {
state.cachedViews = [] state.cachedViews = []
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment