作者 RuoYi

新增tab对象简化页签操作

@@ -152,31 +152,24 @@ export default { @@ -152,31 +152,24 @@ export default {
152 }) 152 })
153 }, 153 },
154 refreshSelectedTag(view) { 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 closeSelectedTag(view) { 157 closeSelectedTag(view) {
165 - this.$store.dispatch('tagsView/delView', view).then(({ visitedViews }) => { 158 + this.$tab.closePage(view).then(({ visitedViews }) => {
166 if (this.isActive(view)) { 159 if (this.isActive(view)) {
167 this.toLastView(visitedViews, view) 160 this.toLastView(visitedViews, view)
168 } 161 }
169 }) 162 })
170 }, 163 },
171 closeRightTags() { 164 closeRightTags() {
172 - this.$store.dispatch('tagsView/delRightTags', this.selectedTag).then(visitedViews => { 165 + this.$tab.closeRightPage(this.selectedTag).then(visitedViews => {
173 if (!visitedViews.find(i => i.fullPath === this.$route.fullPath)) { 166 if (!visitedViews.find(i => i.fullPath === this.$route.fullPath)) {
174 this.toLastView(visitedViews) 167 this.toLastView(visitedViews)
175 } 168 }
176 }) 169 })
177 }, 170 },
178 closeLeftTags() { 171 closeLeftTags() {
179 - this.$store.dispatch('tagsView/delLeftTags', this.selectedTag).then(visitedViews => { 172 + this.$tab.closeLeftPage(this.selectedTag).then(visitedViews => {
180 if (!visitedViews.find(i => i.fullPath === this.$route.fullPath)) { 173 if (!visitedViews.find(i => i.fullPath === this.$route.fullPath)) {
181 this.toLastView(visitedViews) 174 this.toLastView(visitedViews)
182 } 175 }
@@ -184,12 +177,12 @@ export default { @@ -184,12 +177,12 @@ export default {
184 }, 177 },
185 closeOthersTags() { 178 closeOthersTags() {
186 this.$router.push(this.selectedTag).catch(()=>{}); 179 this.$router.push(this.selectedTag).catch(()=>{});
187 - this.$store.dispatch('tagsView/delOthersViews', this.selectedTag).then(() => { 180 + this.$tab.closeOtherPage(this.selectedTag).then(() => {
188 this.moveToCurrentTag() 181 this.moveToCurrentTag()
189 }) 182 })
190 }, 183 },
191 closeAllTags(view) { 184 closeAllTags(view) {
192 - this.$store.dispatch('tagsView/delAllViews').then(({ visitedViews }) => { 185 + this.$tab.closeAllPage().then(({ visitedViews }) => {
193 if (this.affixTags.some(tag => tag.path === this.$route.path)) { 186 if (this.affixTags.some(tag => tag.path === this.$route.path)) {
194 return 187 return
195 } 188 }
  1 +import tab from './tab'
1 import auth from './auth' 2 import auth from './auth'
2 import cache from './cache' 3 import cache from './cache'
3 import modal from './modal' 4 import modal from './modal'
@@ -5,6 +6,8 @@ import download from './download' @@ -5,6 +6,8 @@ import download from './download'
5 6
6 export default { 7 export default {
7 install(Vue) { 8 install(Vue) {
  9 + // 页签操作
  10 + Vue.prototype.$tab = tab
8 // 认证对象 11 // 认证对象
9 Vue.prototype.$auth = auth 12 Vue.prototype.$auth = auth
10 // 缓存对象 13 // 缓存对象
  1 +import store from '@/store'
  2 +import router from '@/router';
  3 +
  4 +export default {
  5 + // 刷新当前tab页签
  6 + refreshPage(obj) {
  7 + const { path, matched } = router.currentRoute;
  8 + if (obj === undefined) {
  9 + matched.forEach((m) => {
  10 + if (m.components && m.components.default && m.components.default.name) {
  11 + if (!['Layout', 'ParentView'].includes(m.components.default.name)) {
  12 + obj = { name: m.components.default.name, path: path };
  13 + }
  14 + }
  15 + });
  16 + }
  17 + return store.dispatch('tagsView/delCachedView', obj).then(() => {
  18 + const { path } = obj
  19 + router.replace({
  20 + path: '/redirect' + path
  21 + })
  22 + })
  23 +
  24 +
  25 + },
  26 + // 关闭当前tab页签,打开新页签
  27 + closeOpenPage(obj) {
  28 + store.dispatch("tagsView/delView", router.currentRoute);
  29 + if (obj !== undefined) {
  30 + return router.push(obj);
  31 + }
  32 + },
  33 + // 关闭指定tab页签
  34 + closePage(obj) {
  35 + if (obj === undefined) {
  36 + return store.dispatch('tagsView/delView', router.currentRoute).then(({ lastPath }) => {
  37 + return router.push(lastPath || '/');
  38 + });
  39 + }
  40 + return store.dispatch('tagsView/delView', obj);
  41 + },
  42 + // 关闭所有tab页签
  43 + closeAllPage() {
  44 + return store.dispatch('tagsView/delAllViews');
  45 + },
  46 + // 关闭左侧tab页签
  47 + closeLeftPage(obj) {
  48 + return store.dispatch('tagsView/delLeftTags', obj || router.currentRoute);
  49 + },
  50 + // 关闭右侧tab页签
  51 + closeRightPage(obj) {
  52 + return store.dispatch('tagsView/delRightTags', obj || router.currentRoute);
  53 + },
  54 + // 关闭其他tab页签
  55 + closeOtherPage(obj) {
  56 + return store.dispatch('tagsView/delOthersViews', obj || router.currentRoute);
  57 + },
  58 + // 添加tab页签
  59 + addPage(title, url) {
  60 + var obj = { path: url, meta: { title: title } }
  61 + store.dispatch('tagsView/addView', obj);
  62 + return router.push(url);
  63 + },
  64 + // 修改tab页签
  65 + updatePage(obj) {
  66 + return store.dispatch('tagsView/updateVisitedView', obj);
  67 + }
  68 +}
@@ -14,7 +14,7 @@ const mutations = { @@ -14,7 +14,7 @@ const mutations = {
14 }, 14 },
15 ADD_CACHED_VIEW: (state, view) => { 15 ADD_CACHED_VIEW: (state, view) => {
16 if (state.cachedViews.includes(view.name)) return 16 if (state.cachedViews.includes(view.name)) return
17 - if (!view.meta.noCache) { 17 + if (view.meta && !view.meta.noCache) {
18 state.cachedViews.push(view.name) 18 state.cachedViews.push(view.name)
19 } 19 }
20 }, 20 },
@@ -245,8 +245,8 @@ export default { @@ -245,8 +245,8 @@ export default {
245 }, 245 },
246 // 返回按钮 246 // 返回按钮
247 handleClose() { 247 handleClose() {
248 - this.$store.dispatch("tagsView/delView", this.$route);  
249 - this.$router.push({ path: "/monitor/job" }); 248 + const obj = { path: "/monitor/job" };
  249 + this.$tab.closeOpenPage(obj);
250 }, 250 },
251 /** 搜索按钮操作 */ 251 /** 搜索按钮操作 */
252 handleQuery() { 252 handleQuery() {
@@ -79,6 +79,15 @@ @@ -79,6 +79,15 @@
79 v-hasPermi="['system:dict:export']" 79 v-hasPermi="['system:dict:export']"
80 >导出</el-button> 80 >导出</el-button>
81 </el-col> 81 </el-col>
  82 + <el-col :span="1.5">
  83 + <el-button
  84 + type="warning"
  85 + plain
  86 + icon="el-icon-close"
  87 + size="mini"
  88 + @click="handleClose"
  89 + >关闭</el-button>
  90 + </el-col>
82 <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> 91 <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
83 </el-row> 92 </el-row>
84 93
@@ -316,6 +325,11 @@ export default { @@ -316,6 +325,11 @@ export default {
316 this.queryParams.pageNum = 1; 325 this.queryParams.pageNum = 1;
317 this.getList(); 326 this.getList();
318 }, 327 },
  328 + // 返回按钮
  329 + handleClose() {
  330 + const obj = { path: "/system/dict" };
  331 + this.$tab.closeOpenPage(obj);
  332 + },
319 /** 重置按钮操作 */ 333 /** 重置按钮操作 */
320 resetQuery() { 334 resetQuery() {
321 this.resetForm("queryForm"); 335 this.resetForm("queryForm");
@@ -153,8 +153,8 @@ export default { @@ -153,8 +153,8 @@ export default {
153 }, 153 },
154 // 返回按钮 154 // 返回按钮
155 handleClose() { 155 handleClose() {
156 - this.$store.dispatch("tagsView/delView", this.$route);  
157 - this.$router.push({ path: "/system/role" }); 156 + const obj = { path: "/system/role" };
  157 + this.$tab.closeOpenPage(obj);
158 }, 158 },
159 /** 搜索按钮操作 */ 159 /** 搜索按钮操作 */
160 handleQuery() { 160 handleQuery() {
@@ -109,8 +109,8 @@ export default { @@ -109,8 +109,8 @@ export default {
109 }, 109 },
110 /** 关闭按钮 */ 110 /** 关闭按钮 */
111 close() { 111 close() {
112 - this.$store.dispatch("tagsView/delView", this.$route);  
113 - this.$router.push({ path: "/system/user" }); 112 + const obj = { path: "/system/user" };
  113 + this.$tab.closeOpenPage(obj);
114 }, 114 },
115 }, 115 },
116 }; 116 };
@@ -64,8 +64,7 @@ export default { @@ -64,8 +64,7 @@ export default {
64 }); 64 });
65 }, 65 },
66 close() { 66 close() {
67 - this.$store.dispatch("tagsView/delView", this.$route);  
68 - this.$router.push({ path: "/index" }); 67 + this.$tab.closePage();
69 } 68 }
70 } 69 }
71 }; 70 };
@@ -68,8 +68,7 @@ export default { @@ -68,8 +68,7 @@ export default {
68 }); 68 });
69 }, 69 },
70 close() { 70 close() {
71 - this.$store.dispatch("tagsView/delView", this.$route);  
72 - this.$router.push({ path: "/index" }); 71 + this.$tab.closePage();
73 } 72 }
74 } 73 }
75 }; 74 };
@@ -211,8 +211,8 @@ export default { @@ -211,8 +211,8 @@ export default {
211 }, 211 },
212 /** 关闭按钮 */ 212 /** 关闭按钮 */
213 close() { 213 close() {
214 - this.$store.dispatch("tagsView/delView", this.$route);  
215 - this.$router.push({ path: "/tool/gen", query: { t: Date.now(), pageNum: this.$route.query.pageNum } }) 214 + const obj = { path: "/tool/gen", query: { t: Date.now(), pageNum: this.$route.query.pageNum } };
  215 + this.$tab.closeOpenPage(obj);
216 } 216 }
217 }, 217 },
218 mounted() { 218 mounted() {