feat: add `Close to the Right` option on tagsview
This commit is contained in:
parent
92fcc8c50b
commit
c320c1c63f
|
@ -22,6 +22,7 @@
|
|||
<li @click="refreshSelectedTag(selectedTag)">Refresh</li>
|
||||
<li v-if="!isAffix(selectedTag)" @click="closeSelectedTag(selectedTag)">Close</li>
|
||||
<li @click="closeOthersTags">Close Others</li>
|
||||
<li v-if="!isLastView()" @click="closeRightTags">Close to the Right</li>
|
||||
<li @click="closeAllTags(selectedTag)">Close All</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
@ -76,6 +77,9 @@ export default {
|
|||
isAffix(tag) {
|
||||
return tag.meta && tag.meta.affix
|
||||
},
|
||||
isLastView() {
|
||||
return this.selectedTag.fullPath === this.visitedViews[this.visitedViews.length - 1].fullPath
|
||||
},
|
||||
filterAffixTags(routes, basePath = '/') {
|
||||
let tags = []
|
||||
routes.forEach(route => {
|
||||
|
@ -159,6 +163,13 @@ export default {
|
|||
this.moveToCurrentTag()
|
||||
})
|
||||
},
|
||||
closeRightTags() {
|
||||
this.$store.dispatch('tagsView/delRightTags', this.selectedTag).then(visitedViews => {
|
||||
if (!visitedViews.find(i => i.fullPath === this.$route.fullPath)) {
|
||||
this.toLastView(visitedViews)
|
||||
}
|
||||
})
|
||||
},
|
||||
closeAllTags(view) {
|
||||
this.$store.dispatch('tagsView/delAllViews').then(({ visitedViews }) => {
|
||||
if (this.affixTags.some(tag => tag.path === view.path)) {
|
||||
|
@ -167,7 +178,7 @@ export default {
|
|||
this.toLastView(visitedViews, view)
|
||||
})
|
||||
},
|
||||
toLastView(visitedViews, view) {
|
||||
toLastView(visitedViews, view = {}) {
|
||||
const latestView = visitedViews.slice(-1)[0]
|
||||
if (latestView) {
|
||||
this.$router.push(latestView.fullPath)
|
||||
|
|
|
@ -66,6 +66,19 @@ const mutations = {
|
|||
},
|
||||
MOVE_VIEW: (state, { oldIndex, newIndex }) => {
|
||||
state.visitedViews.splice(newIndex, 0, state.visitedViews.splice(oldIndex, 1)[0])
|
||||
},
|
||||
DEL_RIGHT_VIEWS: (state, view) => {
|
||||
const index = state.visitedViews.findIndex(v => v.path === view.path)
|
||||
if (index === -1) {
|
||||
return
|
||||
}
|
||||
const arr = state.visitedViews.splice(index + 1)
|
||||
arr.forEach(item => {
|
||||
const index = state.cachedViews.indexOf(item.name)
|
||||
if (index > -1) {
|
||||
state.cachedViews.splice(index, 1)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -155,6 +168,12 @@ const actions = {
|
|||
},
|
||||
moveView({ commit }, arg) {
|
||||
commit('MOVE_VIEW', arg)
|
||||
},
|
||||
delRightTags({ commit }, view) {
|
||||
return new Promise(resolve => {
|
||||
commit('DEL_RIGHT_VIEWS', view)
|
||||
resolve([...state.visitedViews])
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue