feat(TagsView): 快捷导航栏添加关闭左侧和右侧的标签

This commit is contained in:
有来技术
2022-01-01 09:24:26 +08:00
parent 09bc719a61
commit 9799d3e570
2 changed files with 44 additions and 9 deletions

View File

@@ -210,7 +210,7 @@ function closeSelectedTag(view: TagView) {
} }
function closeLeftTags() { function closeLeftTags() {
ctx.$tab.closeLeftPage(selectedTag.value).then(visitedViews => { tagsViewStoreHook().delLeftViews(selectedTag.value).then(({visitedViews}) => {
if (!visitedViews.find(i => i.fullPath === route.fullPath)) { if (!visitedViews.find(i => i.fullPath === route.fullPath)) {
toLastView(visitedViews) toLastView(visitedViews)
} }
@@ -218,7 +218,7 @@ function closeLeftTags() {
} }
function closeRightTags() { function closeRightTags() {
ctx.$tab.closeRightPage(selectedTag.value).then(visitedViews => { tagsViewStoreHook().delRightViews(selectedTag.value).then(({visitedViews}) => {
if (!visitedViews.find(i => i.fullPath === route.fullPath)) { if (!visitedViews.find(i => i.fullPath === route.fullPath)) {
toLastView(visitedViews) toLastView(visitedViews)
} }

View File

@@ -101,14 +101,49 @@ const tagsViewStore = defineStore({
}) })
}, },
delLeftViews(view: any) { delLeftViews(view: any) {
const currIndex = this.visitedViews.findIndex(v => v.path === view.path) return new Promise(resolve => {
if (currIndex === -1) { const currIndex = this.visitedViews.findIndex(v => v.path === view.path)
return if (currIndex === -1) {
} return
this.visitedViews = this.visitedViews.filter((item, index) => {
if(index>=currIndex||(item.meta&&item.meta.affix)){
return true
} }
this.visitedViews = this.visitedViews.filter((item, index) => {
// affix:true 固定tag例如“首页”
if (index >= currIndex || (item.meta && item.meta.affix)) {
return true
}
const cacheIndex = this.cachedViews.indexOf(item.name)
if (cacheIndex > -1) {
this.cachedViews.splice(cacheIndex, 1)
}
return false
})
resolve({
visitedViews: [...this.visitedViews]
})
})
},
delRightViews(view: any) {
return new Promise(resolve => {
const currIndex = this.visitedViews.findIndex(v => v.path === view.path)
if (currIndex === -1) {
return
}
this.visitedViews = this.visitedViews.filter((item, index) => {
// affix:true 固定tag例如“首页”
if (index <= currIndex || (item.meta && item.meta.affix)) {
return true
}
const cacheIndex = this.cachedViews.indexOf(item.name)
if (cacheIndex > -1) {
this.cachedViews.splice(cacheIndex, 1)
}
return false
})
resolve({
visitedViews: [...this.visitedViews]
})
}) })
}, },
delAllViews(view: any) { delAllViews(view: any) {