diff --git a/src/store/modules/tagsView.js b/src/store/modules/tagsView.js index b5f86bc..331836f 100644 --- a/src/store/modules/tagsView.js +++ b/src/store/modules/tagsView.js @@ -56,24 +56,32 @@ } }, - DEL_ALL_VISITED_VIEWS: state => { - // keep affix tags - const affixTags = state.visitedViews.filter((tag, index) => { - if (tag.meta.affix || index === 0) { - return true - } - }) - state.visitedViews = affixTags + DEL_ALL_VISITED_VIEWS: (state, delAll) => { + if (delAll) { + state.visitedViews = [] + } else { + // keep affix tags + const affixTags = state.visitedViews.filter((tag, index) => { + if (tag.meta.affix || index === 0) { + return true + } + }) + state.visitedViews = affixTags + } }, - DEL_ALL_CACHED_VIEWS: state => { + DEL_ALL_CACHED_VIEWS: (state, delAll) => { // state.cachedViews = [] // keep affix tags - const affixTags = state.cachedViews.filter((tag, index) => { - if (tag.meta.affix || index === 0) { - return true - } - }) - state.cachedViews = affixTags + if (delAll) { + state.cachedViews = [] + } else { + const affixTags = state.cachedViews.filter((tag, index) => { + if (tag.meta.affix || index === 0) { + return true + } + }) + state.cachedViews = affixTags + } }, UPDATE_VISITED_VIEW: (state, view) => { @@ -144,25 +152,26 @@ }) }, // 关闭全部 - delAllViews({ dispatch, state }, view) { + delAllViews({ dispatch, state }, delAll = false) { + debugger return new Promise(resolve => { - dispatch('delAllVisitedViews', view) - dispatch('delAllCachedViews', view) + dispatch('delAllVisitedViews', delAll) + dispatch('delAllCachedViews', delAll) resolve({ visitedViews: [...state.visitedViews], cachedViews: [...state.cachedViews] }) }) }, - delAllVisitedViews({ commit, state }) { + delAllVisitedViews({ commit, state }, delAll) { return new Promise(resolve => { - commit('DEL_ALL_VISITED_VIEWS') + commit('DEL_ALL_VISITED_VIEWS', delAll) resolve([...state.visitedViews]) }) }, - delAllCachedViews({ commit, state }) { + delAllCachedViews({ commit, state }, delAll) { return new Promise(resolve => { - commit('DEL_ALL_CACHED_VIEWS') + commit('DEL_ALL_CACHED_VIEWS', delAll) resolve([...state.cachedViews]) }) }, diff --git a/src/store/modules/tagsView.js b/src/store/modules/tagsView.js index b5f86bc..331836f 100644 --- a/src/store/modules/tagsView.js +++ b/src/store/modules/tagsView.js @@ -56,24 +56,32 @@ } }, - DEL_ALL_VISITED_VIEWS: state => { - // keep affix tags - const affixTags = state.visitedViews.filter((tag, index) => { - if (tag.meta.affix || index === 0) { - return true - } - }) - state.visitedViews = affixTags + DEL_ALL_VISITED_VIEWS: (state, delAll) => { + if (delAll) { + state.visitedViews = [] + } else { + // keep affix tags + const affixTags = state.visitedViews.filter((tag, index) => { + if (tag.meta.affix || index === 0) { + return true + } + }) + state.visitedViews = affixTags + } }, - DEL_ALL_CACHED_VIEWS: state => { + DEL_ALL_CACHED_VIEWS: (state, delAll) => { // state.cachedViews = [] // keep affix tags - const affixTags = state.cachedViews.filter((tag, index) => { - if (tag.meta.affix || index === 0) { - return true - } - }) - state.cachedViews = affixTags + if (delAll) { + state.cachedViews = [] + } else { + const affixTags = state.cachedViews.filter((tag, index) => { + if (tag.meta.affix || index === 0) { + return true + } + }) + state.cachedViews = affixTags + } }, UPDATE_VISITED_VIEW: (state, view) => { @@ -144,25 +152,26 @@ }) }, // 关闭全部 - delAllViews({ dispatch, state }, view) { + delAllViews({ dispatch, state }, delAll = false) { + debugger return new Promise(resolve => { - dispatch('delAllVisitedViews', view) - dispatch('delAllCachedViews', view) + dispatch('delAllVisitedViews', delAll) + dispatch('delAllCachedViews', delAll) resolve({ visitedViews: [...state.visitedViews], cachedViews: [...state.cachedViews] }) }) }, - delAllVisitedViews({ commit, state }) { + delAllVisitedViews({ commit, state }, delAll) { return new Promise(resolve => { - commit('DEL_ALL_VISITED_VIEWS') + commit('DEL_ALL_VISITED_VIEWS', delAll) resolve([...state.visitedViews]) }) }, - delAllCachedViews({ commit, state }) { + delAllCachedViews({ commit, state }, delAll) { return new Promise(resolve => { - commit('DEL_ALL_CACHED_VIEWS') + commit('DEL_ALL_CACHED_VIEWS', delAll) resolve([...state.cachedViews]) }) }, diff --git a/src/views/layout/components/AppHeader.vue b/src/views/layout/components/AppHeader.vue index 0701d5c..1faad3f 100644 --- a/src/views/layout/components/AppHeader.vue +++ b/src/views/layout/components/AppHeader.vue @@ -79,7 +79,9 @@ console.log('切换子系统:' + command.name) this.$store.commit('SET_CHANGEFLAG', '1') this.$store.commit('SET_SYSTEM', command) - this.$router.replace(command.url) + this.$store.dispatch('tagsView/delAllViews', true).then(({ visitedViews }) => { + this.$router.replace(command.url) + }) }, // 获取子系统 getSystems() {