Skip to content

Commit 4d0e997

Browse files
committed
v3.8.0 新增tab对象简化页签操作
1 parent d432326 commit 4d0e997

File tree

2 files changed

+32
-15
lines changed

2 files changed

+32
-15
lines changed

src/layout/components/TagsView/index.vue

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -152,44 +152,37 @@ export default {
152152
})
153153
},
154154
refreshSelectedTag(view) {
155-
this.$store.dispatch('tagsView/delCachedView', view).then(() => {
156-
const { fullPath } = view
157-
this.$nextTick(() => {
158-
this.$router.replace({
159-
path: '/redirect' + fullPath
160-
})
161-
})
162-
})
155+
this.$tab.refreshPage(view);
163156
},
164157
closeSelectedTag(view) {
165-
this.$store.dispatch('tagsView/delView', view).then(({ visitedViews }) => {
158+
this.$tab.closePage(view).then(({ visitedViews }) => {
166159
if (this.isActive(view)) {
167160
this.toLastView(visitedViews, view)
168161
}
169162
})
170163
},
171164
closeRightTags() {
172-
this.$store.dispatch('tagsView/delRightTags', this.selectedTag).then(visitedViews => {
165+
this.$tab.closeRightPage(this.selectedTag).then(visitedViews => {
173166
if (!visitedViews.find(i => i.fullPath === this.$route.fullPath)) {
174167
this.toLastView(visitedViews)
175168
}
176169
})
177170
},
178171
closeLeftTags() {
179-
this.$store.dispatch('tagsView/delLeftTags', this.selectedTag).then(visitedViews => {
172+
this.$tab.closeLeftPage(this.selectedTag).then(visitedViews => {
180173
if (!visitedViews.find(i => i.fullPath === this.$route.fullPath)) {
181174
this.toLastView(visitedViews)
182175
}
183176
})
184177
},
185178
closeOthersTags() {
186179
this.$router.push(this.selectedTag).catch(()=>{});
187-
this.$store.dispatch('tagsView/delOthersViews', this.selectedTag).then(() => {
180+
this.$tab.closeOtherPage(this.selectedTag).then(() => {
188181
this.moveToCurrentTag()
189182
})
190183
},
191184
closeAllTags(view) {
192-
this.$store.dispatch('tagsView/delAllViews').then(({ visitedViews }) => {
185+
this.$tab.closeAllPage().then(({ visitedViews }) => {
193186
if (this.affixTags.some(tag => tag.path === this.$route.path)) {
194187
return
195188
}

src/store/modules/tagsView.js

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ const mutations = {
6363
}
6464
}
6565
},
66-
66+
6767
DEL_RIGHT_VIEWS: (state, view) => {
6868
const index = state.visitedViews.findIndex(v => v.path === view.path)
6969
if (index === -1) {
@@ -79,6 +79,23 @@ const mutations = {
7979
}
8080
return false
8181
})
82+
},
83+
84+
DEL_LEFT_VIEWS: (state, view) => {
85+
const index = state.visitedViews.findIndex(v => v.path === view.path)
86+
if (index === -1) {
87+
return
88+
}
89+
state.visitedViews = state.visitedViews.filter((item, idx) => {
90+
if (idx >= index || (item.meta && item.meta.affix)) {
91+
return true
92+
}
93+
const i = state.cachedViews.indexOf(item.name)
94+
if (i > -1) {
95+
state.cachedViews.splice(i, 1)
96+
}
97+
return false
98+
})
8299
}
83100
}
84101

@@ -172,7 +189,14 @@ const actions = {
172189
commit('DEL_RIGHT_VIEWS', view)
173190
resolve([...state.visitedViews])
174191
})
175-
}
192+
},
193+
194+
delLeftTags({ commit }, view) {
195+
return new Promise(resolve => {
196+
commit('DEL_LEFT_VIEWS', view)
197+
resolve([...state.visitedViews])
198+
})
199+
},
176200
}
177201

178202
export default {

0 commit comments

Comments
 (0)