Commit f87e1d822ccedbc8157775c8d58212fa4a6a6252
1 parent
19f62078
v3.8.0 新增tab对象简化页签操作
Showing
2 changed files
with
32 additions
and
15 deletions
yudao-ui-admin/src/layout/components/TagsView/index.vue
| ... | ... | @@ -152,31 +152,24 @@ export default { |
| 152 | 152 | }) |
| 153 | 153 | }, |
| 154 | 154 | 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); | |
| 163 | 156 | }, |
| 164 | 157 | closeSelectedTag(view) { |
| 165 | - this.$store.dispatch('tagsView/delView', view).then(({ visitedViews }) => { | |
| 158 | + this.$tab.closePage(view).then(({ visitedViews }) => { | |
| 166 | 159 | if (this.isActive(view)) { |
| 167 | 160 | this.toLastView(visitedViews, view) |
| 168 | 161 | } |
| 169 | 162 | }) |
| 170 | 163 | }, |
| 171 | 164 | closeRightTags() { |
| 172 | - this.$store.dispatch('tagsView/delRightTags', this.selectedTag).then(visitedViews => { | |
| 165 | + this.$tab.closeRightPage(this.selectedTag).then(visitedViews => { | |
| 173 | 166 | if (!visitedViews.find(i => i.fullPath === this.$route.fullPath)) { |
| 174 | 167 | this.toLastView(visitedViews) |
| 175 | 168 | } |
| 176 | 169 | }) |
| 177 | 170 | }, |
| 178 | 171 | closeLeftTags() { |
| 179 | - this.$store.dispatch('tagsView/delLeftTags', this.selectedTag).then(visitedViews => { | |
| 172 | + this.$tab.closeLeftPage(this.selectedTag).then(visitedViews => { | |
| 180 | 173 | if (!visitedViews.find(i => i.fullPath === this.$route.fullPath)) { |
| 181 | 174 | this.toLastView(visitedViews) |
| 182 | 175 | } |
| ... | ... | @@ -184,12 +177,12 @@ export default { |
| 184 | 177 | }, |
| 185 | 178 | closeOthersTags() { |
| 186 | 179 | this.$router.push(this.selectedTag).catch(()=>{}); |
| 187 | - this.$store.dispatch('tagsView/delOthersViews', this.selectedTag).then(() => { | |
| 180 | + this.$tab.closeOtherPage(this.selectedTag).then(() => { | |
| 188 | 181 | this.moveToCurrentTag() |
| 189 | 182 | }) |
| 190 | 183 | }, |
| 191 | 184 | closeAllTags(view) { |
| 192 | - this.$store.dispatch('tagsView/delAllViews').then(({ visitedViews }) => { | |
| 185 | + this.$tab.closeAllPage().then(({ visitedViews }) => { | |
| 193 | 186 | if (this.affixTags.some(tag => tag.path === this.$route.path)) { |
| 194 | 187 | return |
| 195 | 188 | } | ... | ... |
yudao-ui-admin/src/store/modules/tagsView.js
| ... | ... | @@ -63,7 +63,7 @@ const mutations = { |
| 63 | 63 | } |
| 64 | 64 | } |
| 65 | 65 | }, |
| 66 | - | |
| 66 | + | |
| 67 | 67 | DEL_RIGHT_VIEWS: (state, view) => { |
| 68 | 68 | const index = state.visitedViews.findIndex(v => v.path === view.path) |
| 69 | 69 | if (index === -1) { |
| ... | ... | @@ -79,6 +79,23 @@ const mutations = { |
| 79 | 79 | } |
| 80 | 80 | return false |
| 81 | 81 | }) |
| 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 | + }) | |
| 82 | 99 | } |
| 83 | 100 | } |
| 84 | 101 | |
| ... | ... | @@ -172,7 +189,14 @@ const actions = { |
| 172 | 189 | commit('DEL_RIGHT_VIEWS', view) |
| 173 | 190 | resolve([...state.visitedViews]) |
| 174 | 191 | }) |
| 175 | - } | |
| 192 | + }, | |
| 193 | + | |
| 194 | + delLeftTags({ commit }, view) { | |
| 195 | + return new Promise(resolve => { | |
| 196 | + commit('DEL_LEFT_VIEWS', view) | |
| 197 | + resolve([...state.visitedViews]) | |
| 198 | + }) | |
| 199 | + }, | |
| 176 | 200 | } |
| 177 | 201 | |
| 178 | 202 | export default { | ... | ... |