Commit c5fad966d26a12bdc9f12a47ead10df13537c2e5
1 parent
1cc2e091
v3.5.0 页签新增关闭右侧
Showing
2 changed files
with
39 additions
and
0 deletions
yudao-ui-admin/src/layout/components/TagsView/index.vue
| @@ -21,6 +21,7 @@ | @@ -21,6 +21,7 @@ | ||
| 21 | <li @click="refreshSelectedTag(selectedTag)">刷新页面</li> | 21 | <li @click="refreshSelectedTag(selectedTag)">刷新页面</li> |
| 22 | <li v-if="!isAffix(selectedTag)" @click="closeSelectedTag(selectedTag)">关闭当前</li> | 22 | <li v-if="!isAffix(selectedTag)" @click="closeSelectedTag(selectedTag)">关闭当前</li> |
| 23 | <li @click="closeOthersTags">关闭其他</li> | 23 | <li @click="closeOthersTags">关闭其他</li> |
| 24 | + <li v-if="!isLastView()" @click="closeRightTags">关闭右侧</li> | ||
| 24 | <li @click="closeAllTags(selectedTag)">关闭所有</li> | 25 | <li @click="closeAllTags(selectedTag)">关闭所有</li> |
| 25 | </ul> | 26 | </ul> |
| 26 | </div> | 27 | </div> |
| @@ -83,6 +84,13 @@ export default { | @@ -83,6 +84,13 @@ export default { | ||
| 83 | isAffix(tag) { | 84 | isAffix(tag) { |
| 84 | return tag.meta && tag.meta.affix | 85 | return tag.meta && tag.meta.affix |
| 85 | }, | 86 | }, |
| 87 | + isLastView() { | ||
| 88 | + try { | ||
| 89 | + return this.selectedTag.fullPath === this.visitedViews[this.visitedViews.length - 1].fullPath | ||
| 90 | + } catch (err) { | ||
| 91 | + return false | ||
| 92 | + } | ||
| 93 | + }, | ||
| 86 | filterAffixTags(routes, basePath = '/') { | 94 | filterAffixTags(routes, basePath = '/') { |
| 87 | let tags = [] | 95 | let tags = [] |
| 88 | routes.forEach(route => { | 96 | routes.forEach(route => { |
| @@ -152,6 +160,13 @@ export default { | @@ -152,6 +160,13 @@ export default { | ||
| 152 | } | 160 | } |
| 153 | }) | 161 | }) |
| 154 | }, | 162 | }, |
| 163 | + closeRightTags() { | ||
| 164 | + this.$store.dispatch('tagsView/delRightTags', this.selectedTag).then(visitedViews => { | ||
| 165 | + if (!visitedViews.find(i => i.fullPath === this.$route.fullPath)) { | ||
| 166 | + this.toLastView(visitedViews) | ||
| 167 | + } | ||
| 168 | + }) | ||
| 169 | + }, | ||
| 155 | closeOthersTags() { | 170 | closeOthersTags() { |
| 156 | this.$router.push(this.selectedTag).catch(()=>{}); | 171 | this.$router.push(this.selectedTag).catch(()=>{}); |
| 157 | this.$store.dispatch('tagsView/delOthersViews', this.selectedTag).then(() => { | 172 | this.$store.dispatch('tagsView/delOthersViews', this.selectedTag).then(() => { |
yudao-ui-admin/src/store/modules/tagsView.js
| @@ -62,6 +62,23 @@ const mutations = { | @@ -62,6 +62,23 @@ const mutations = { | ||
| 62 | break | 62 | break |
| 63 | } | 63 | } |
| 64 | } | 64 | } |
| 65 | + }, | ||
| 66 | + | ||
| 67 | + DEL_RIGHT_VIEWS: (state, view) => { | ||
| 68 | + const index = state.visitedViews.findIndex(v => v.path === view.path) | ||
| 69 | + if (index === -1) { | ||
| 70 | + return | ||
| 71 | + } | ||
| 72 | + state.visitedViews = state.visitedViews.filter((item, idx) => { | ||
| 73 | + if (idx <= index || (item.meta && item.meta.affix)) { | ||
| 74 | + return true | ||
| 75 | + } | ||
| 76 | + const i = state.cachedViews.indexOf(item.name) | ||
| 77 | + if (i > -1) { | ||
| 78 | + state.cachedViews.splice(i, 1) | ||
| 79 | + } | ||
| 80 | + return false | ||
| 81 | + }) | ||
| 65 | } | 82 | } |
| 66 | } | 83 | } |
| 67 | 84 | ||
| @@ -148,6 +165,13 @@ const actions = { | @@ -148,6 +165,13 @@ const actions = { | ||
| 148 | 165 | ||
| 149 | updateVisitedView({ commit }, view) { | 166 | updateVisitedView({ commit }, view) { |
| 150 | commit('UPDATE_VISITED_VIEW', view) | 167 | commit('UPDATE_VISITED_VIEW', view) |
| 168 | + }, | ||
| 169 | + | ||
| 170 | + delRightTags({ commit }, view) { | ||
| 171 | + return new Promise(resolve => { | ||
| 172 | + commit('DEL_RIGHT_VIEWS', view) | ||
| 173 | + resolve([...state.visitedViews]) | ||
| 174 | + }) | ||
| 151 | } | 175 | } |
| 152 | } | 176 | } |
| 153 | 177 |