|
|
|
|
@ -1,4 +1,5 @@ |
|
|
|
|
import {rightSideRouteTransition} from '@/config' |
|
|
|
|
import {createMutations} from "@/utils" |
|
|
|
|
|
|
|
|
|
const state = { |
|
|
|
|
visitedViews: [], |
|
|
|
|
@ -7,78 +8,62 @@ const state = { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const mutations = { |
|
|
|
|
SET_VISITED_VIEWS(state, views) { |
|
|
|
|
state.visitedViews = views |
|
|
|
|
}, |
|
|
|
|
SET_CACHED_VIEWS(state, views) { |
|
|
|
|
state.cachedViews = views |
|
|
|
|
}, |
|
|
|
|
...createMutations(state), |
|
|
|
|
|
|
|
|
|
ADD_VISITED_VIEW: (state, view) => { |
|
|
|
|
addVisitedView(state, view) { |
|
|
|
|
if (state.visitedViews.some(v => v.path === view.path)) return |
|
|
|
|
state.visitedViews.push({...view, title: view.meta.title || 'no-name'}) |
|
|
|
|
}, |
|
|
|
|
ADD_CACHED_VIEW: (state, view) => { |
|
|
|
|
addCachedView(state, view) { |
|
|
|
|
if (state.cachedViews.includes(view.name)) return |
|
|
|
|
if (!view.meta.noCache && !view.meta.iframe) { |
|
|
|
|
state.cachedViews.push(view.name) |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
DEL_VISITED_VIEW: (state, view) => { |
|
|
|
|
delVisitedView(state, view) { |
|
|
|
|
const index = state.visitedViews.findIndex(i => i.path === view.path) |
|
|
|
|
index > -1 && state.visitedViews.splice(index, 1) |
|
|
|
|
}, |
|
|
|
|
DEL_CACHED_VIEW: (state, view) => { |
|
|
|
|
delCachedView(state, view) { |
|
|
|
|
const index = state.cachedViews.indexOf(view.name) |
|
|
|
|
index > -1 && state.cachedViews.splice(index, 1) |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
DEL_OTHERS_VISITED_VIEWS: (state, view) => { |
|
|
|
|
state.visitedViews = state.visitedViews.filter(v => { |
|
|
|
|
return v.meta.affix || v.path === view.path |
|
|
|
|
}) |
|
|
|
|
}, |
|
|
|
|
DEL_OTHERS_CACHED_VIEWS: (state, view) => { |
|
|
|
|
const index = state.cachedViews.indexOf(view.name) |
|
|
|
|
if (index > -1) { |
|
|
|
|
state.cachedViews = state.cachedViews.slice(index, index + 1) |
|
|
|
|
} |
|
|
|
|
else state.cachedViews = [] |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
UPDATE_VISITED_VIEW: (state, view) => { |
|
|
|
|
updateVisitedViews(state, view) { |
|
|
|
|
for (let v of state.visitedViews) { |
|
|
|
|
if (v.path === view.path) { |
|
|
|
|
v = Object.assign(v, view) |
|
|
|
|
break |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
SET_TRANSITION_NAME: (state, name) => { |
|
|
|
|
state.transitionName = name |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const actions = { |
|
|
|
|
addView({commit, dispatch}, view) { |
|
|
|
|
commit('ADD_VISITED_VIEW', view) |
|
|
|
|
commit('ADD_CACHED_VIEW', view) |
|
|
|
|
addView({commit}, view) { |
|
|
|
|
commit('addVisitedView', view) |
|
|
|
|
commit('addCachedView', view) |
|
|
|
|
}, |
|
|
|
|
delView({commit}, view) { |
|
|
|
|
commit('DEL_VISITED_VIEW', view) |
|
|
|
|
commit('DEL_CACHED_VIEW', view) |
|
|
|
|
commit('iframe/DEL_IFRAME', view.meta ? view.meta.iframe : null, {root: true}) |
|
|
|
|
commit('delVisitedView', view) |
|
|
|
|
commit('delCachedView', view) |
|
|
|
|
commit('iframe/delIframe', view.meta ? view.meta.iframe : null, {root: true}) |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
delOthersViews({commit, state}, view) { |
|
|
|
|
commit('DEL_OTHERS_VISITED_VIEWS', view) |
|
|
|
|
commit('DEL_OTHERS_CACHED_VIEWS', view) |
|
|
|
|
delOthersViews({state, commit}, view) { |
|
|
|
|
const visitedViews = state.visitedViews.filter(v => v.meta.affix || v.path === view.path) |
|
|
|
|
let cachedViews = [] |
|
|
|
|
const index = state.cachedViews.indexOf(view.name) |
|
|
|
|
if (index > -1) { |
|
|
|
|
cachedViews = state.cachedViews.slice(index, index + 1) |
|
|
|
|
} |
|
|
|
|
commit('visitedViews', visitedViews) |
|
|
|
|
commit('cachedViews', cachedViews) |
|
|
|
|
}, |
|
|
|
|
delAllViews({state, commit}) { |
|
|
|
|
commit('SET_VISITED_VIEWS', state.visitedViews.filter(tag => tag.meta.affix)) |
|
|
|
|
commit('SET_CACHED_VIEWS', []) |
|
|
|
|
commit('visitedViews', state.visitedViews.filter(tag => tag.meta.affix)) |
|
|
|
|
commit('cachedViews', []) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|