Commit b43a439b authored by jingnan's avatar jingnan 👀

历史页签缓存至localstorage

parent 22587e94
......@@ -214,25 +214,25 @@ export default {
},
getVisitedViews() {
setTimeout(() => {
if (!this.$utils._get(this.showViews, this.activeModel.id)) {
this.visitedViews = []
} else {
// 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 = []
Object.keys(this.$store.state.tagsView.visitedViews).forEach(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 tempViews = filterViews.reduce((acc, current) => {
const exists = acc.find(item => item.title === current.title)
if (!exists) {
acc.push(current)
}
return acc
}, [])
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')))
}
// if (!this.$utils._get(this.showViews, this.activeModel.id)) {
// this.visitedViews = []
// } else {
// 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 = []
Object.keys(this.$store.state.tagsView.visitedViews).forEach(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 tempViews = filterViews.reduce((acc, current) => {
const exists = acc.find(item => item.title === current.title)
if (!exists) {
acc.push(current)
}
return acc
}, [])
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')))
// }
}, 0)
},
// 更新标签 title
......
const state = {
visitedViews: sessionStorage.getItem('visitedViews') ? JSON.parse(sessionStorage.getItem('visitedViews')) : {},
visitedViews: localStorage.getItem('visitedViews') ? JSON.parse(localStorage.getItem('visitedViews')) : {},
cachedViews: [],
previousRouter: [],
cachedMenuPages: {}
......@@ -8,7 +8,7 @@ const state = {
const mutations = {
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 = state.previousRouter.splice(0, 2)
const belongModel = sessionStorage.getItem('activePageModel') ? JSON.parse(sessionStorage.getItem('activePageModel')).id : 'todoTask'
......@@ -40,6 +40,7 @@ const mutations = {
state.visitedViews[belongModel].shift()
}*/
sessionStorage.setItem('visitedViews', JSON.stringify(state.visitedViews))
localStorage.setItem('visitedViews', JSON.stringify(state.visitedViews))
},
ADD_CACHED_VIEW: (state, view) => {
if (state.cachedViews.includes(view.name) || view.name === 'navigation') return
......@@ -61,6 +62,7 @@ const mutations = {
}
}
sessionStorage.setItem('visitedViews', JSON.stringify(state.visitedViews))
localStorage.setItem('visitedViews', JSON.stringify(state.visitedViews))
},
DEL_CACHED_VIEW: (state, view) => {
const index = state.cachedViews.indexOf(view.name)
......@@ -76,6 +78,7 @@ const mutations = {
return v.meta.affix || v.path === view.path
})
sessionStorage.setItem('visitedViews', JSON.stringify(state.visitedViews))
localStorage.setItem('visitedViews', JSON.stringify(state.visitedViews))
},
DEL_OTHERS_CACHED_VIEWS: (state, view) => {
const index = state.cachedViews.indexOf(view.name)
......@@ -90,6 +93,7 @@ const mutations = {
DEL_ALL_VISITED_VIEWS: state => {
state.visitedViews = {}
sessionStorage.setItem('visitedViews', '{}')
// localStorage.setItem('visitedViews', '{}')
},
DEL_ALL_CACHED_VIEWS: state => {
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