diff --git a/src/store/modules/tagsView.js b/src/store/modules/tagsView.js index b7e3be9..b5f86bc 100644 --- a/src/store/modules/tagsView.js +++ b/src/store/modules/tagsView.js @@ -20,19 +20,23 @@ }, DEL_VISITED_VIEW: (state, view) => { - for (const [i, v] of state.visitedViews.entries()) { - if (v.path === view.path) { - state.visitedViews.splice(i, 1) - break + if (!(state.visitedViews.length === 1 && state.visitedViews[0] === view)) { + for (const [i, v] of state.visitedViews.entries()) { + if (v.path === view.path) { + state.visitedViews.splice(i, 1) + break + } } } }, DEL_CACHED_VIEW: (state, view) => { - for (const i of state.cachedViews) { - if (i === view.name) { - const index = state.cachedViews.indexOf(i) - state.cachedViews.splice(index, 1) - break + if (!state.cachedViews.length === 1 && state.cachedViews[0] === view) { + for (const i of state.cachedViews) { + if (i === view.name) { + const index = state.cachedViews.indexOf(i) + state.cachedViews.splice(index, 1) + break + } } } }, @@ -54,11 +58,22 @@ DEL_ALL_VISITED_VIEWS: state => { // keep affix tags - const affixTags = state.visitedViews.filter(tag => tag.meta.affix) + const affixTags = state.visitedViews.filter((tag, index) => { + if (tag.meta.affix || index === 0) { + return true + } + }) state.visitedViews = affixTags }, DEL_ALL_CACHED_VIEWS: state => { - state.cachedViews = [] + // state.cachedViews = [] + // keep affix tags + const affixTags = state.cachedViews.filter((tag, index) => { + if (tag.meta.affix || index === 0) { + return true + } + }) + state.cachedViews = affixTags }, UPDATE_VISITED_VIEW: (state, view) => { @@ -128,7 +143,7 @@ resolve([...state.cachedViews]) }) }, - + // 关闭全部 delAllViews({ dispatch, state }, view) { return new Promise(resolve => { dispatch('delAllVisitedViews', view) diff --git a/src/store/modules/tagsView.js b/src/store/modules/tagsView.js index b7e3be9..b5f86bc 100644 --- a/src/store/modules/tagsView.js +++ b/src/store/modules/tagsView.js @@ -20,19 +20,23 @@ }, DEL_VISITED_VIEW: (state, view) => { - for (const [i, v] of state.visitedViews.entries()) { - if (v.path === view.path) { - state.visitedViews.splice(i, 1) - break + if (!(state.visitedViews.length === 1 && state.visitedViews[0] === view)) { + for (const [i, v] of state.visitedViews.entries()) { + if (v.path === view.path) { + state.visitedViews.splice(i, 1) + break + } } } }, DEL_CACHED_VIEW: (state, view) => { - for (const i of state.cachedViews) { - if (i === view.name) { - const index = state.cachedViews.indexOf(i) - state.cachedViews.splice(index, 1) - break + if (!state.cachedViews.length === 1 && state.cachedViews[0] === view) { + for (const i of state.cachedViews) { + if (i === view.name) { + const index = state.cachedViews.indexOf(i) + state.cachedViews.splice(index, 1) + break + } } } }, @@ -54,11 +58,22 @@ DEL_ALL_VISITED_VIEWS: state => { // keep affix tags - const affixTags = state.visitedViews.filter(tag => tag.meta.affix) + const affixTags = state.visitedViews.filter((tag, index) => { + if (tag.meta.affix || index === 0) { + return true + } + }) state.visitedViews = affixTags }, DEL_ALL_CACHED_VIEWS: state => { - state.cachedViews = [] + // state.cachedViews = [] + // keep affix tags + const affixTags = state.cachedViews.filter((tag, index) => { + if (tag.meta.affix || index === 0) { + return true + } + }) + state.cachedViews = affixTags }, UPDATE_VISITED_VIEW: (state, view) => { @@ -128,7 +143,7 @@ resolve([...state.cachedViews]) }) }, - + // 关闭全部 delAllViews({ dispatch, state }, view) { return new Promise(resolve => { dispatch('delAllVisitedViews', view) diff --git a/src/views/layout/components/TagsView/index.vue b/src/views/layout/components/TagsView/index.vue index 8683a46..3796293 100644 --- a/src/views/layout/components/TagsView/index.vue +++ b/src/views/layout/components/TagsView/index.vue @@ -2,7 +2,7 @@
{{ tag.title }} - +