feat(TagsView): tagsView样式调整

This commit is contained in:
有来技术
2022-01-01 00:11:10 +08:00
parent e142bdf9a5
commit c04c9c7ddd
4 changed files with 331 additions and 274 deletions

View File

@@ -1,16 +1,15 @@
import { defineStore } from "pinia";
import { store } from "@/store";
import {defineStore} from "pinia";
import {store} from "@/store";
import {TagsViewState} from "@store/interface";
const tagsViewStore=defineStore({
id:"tagsView",
state:():TagsViewState=>( {
const tagsViewStore = defineStore({
id: "tagsView",
state: (): TagsViewState => ({
visitedViews: [],
cachedViews: []
}),
actions: {
addVisitedView ( view:any) {
addVisitedView(view: any) {
if (this.visitedViews.some(v => v.path === view.path)) return
this.visitedViews.push(
Object.assign({}, view, {
@@ -18,58 +17,58 @@ const tagsViewStore=defineStore({
})
)
},
addCachedView(view:any) {
addCachedView(view: any) {
if (this.cachedViews.includes(view.name)) return
if (!view.meta.noCache) {
this.cachedViews.push(view.name)
}
},
delVisitedView( view:any) {
return new Promise(resolve => {
for (const [i, v] of this.visitedViews.entries()) {
if (v.path === view.path) {
this.visitedViews.splice(i, 1)
break
}
}
resolve([...this.visitedViews])
})
delVisitedView(view: any) {
return new Promise(resolve => {
for (const [i, v] of this.visitedViews.entries()) {
if (v.path === view.path) {
this.visitedViews.splice(i, 1)
break
}
}
resolve([...this.visitedViews])
})
},
delCachedView ( view:any) {
return new Promise(resolve => {
const index = this.cachedViews.indexOf(view.name)
index > -1 && this.cachedViews.splice(index, 1)
resolve([...this.cachedViews])
})
delCachedView(view: any) {
return new Promise(resolve => {
const index = this.cachedViews.indexOf(view.name)
index > -1 && this.cachedViews.splice(index, 1)
resolve([...this.cachedViews])
})
},
delOthersVisitedViews (view:any) {
return new Promise(resolve => {
this.visitedViews = this.visitedViews.filter(v => {
return v.meta?.affix || v.path === view.path
})
resolve([...this.visitedViews])
})
delOthersVisitedViews(view: any) {
return new Promise(resolve => {
this.visitedViews = this.visitedViews.filter(v => {
return v.meta?.affix || v.path === view.path
})
resolve([...this.visitedViews])
})
},
delOthersCachedViews( view:any) {
return new Promise(resolve => {
const index = this.cachedViews.indexOf(view.name)
if (index > -1) {
this.cachedViews = this.cachedViews.slice(index, index + 1)
} else {
// if index = -1, there is no cached tags
this.cachedViews = []
}
resolve([...this.cachedViews])
})
delOthersCachedViews(view: any) {
return new Promise(resolve => {
const index = this.cachedViews.indexOf(view.name)
if (index > -1) {
this.cachedViews = this.cachedViews.slice(index, index + 1)
} else {
// if index = -1, there is no cached tags
this.cachedViews = []
}
resolve([...this.cachedViews])
})
},
updateVisitedView (view:any) {
updateVisitedView(view: any) {
for (let v of this.visitedViews) {
if (v.path === view.path) {
v = Object.assign(v, view)
@@ -77,31 +76,42 @@ const tagsViewStore=defineStore({
}
}
},
addView( view:any) {
this.addVisitedView( view)
addView(view: any) {
this.addVisitedView(view)
this.addCachedView(view)
},
delView( view:any) {
delView(view: any) {
return new Promise(resolve => {
this.delVisitedView(view)
this.delCachedView( view)
this.delVisitedView(view)
this.delCachedView(view)
resolve({
visitedViews: [...this.visitedViews],
cachedViews: [...this.cachedViews]
})
})
},
delOthersViews( view:any) {
delOthersViews(view: any) {
return new Promise(resolve => {
this.delOthersVisitedViews(view)
this.delOthersCachedViews(view)
this.delOthersVisitedViews(view)
this.delOthersCachedViews(view)
resolve({
visitedViews: [...this.visitedViews],
cachedViews: [...this.cachedViews]
})
})
},
delAllViews( view:any) {
delLeftViews(view: any) {
const currIndex = this.visitedViews.findIndex(v => v.path === view.path)
if (currIndex === -1) {
return
}
this.visitedViews = this.visitedViews.filter((item, index) => {
if(index>=currIndex||(item.meta&&item.meta.affix)){
return true
}
})
},
delAllViews(view: any) {
return new Promise(resolve => {
const affixTags = this.visitedViews.filter(tag => tag.meta?.affix)
this.visitedViews = affixTags