Browse Source

新增tab对象简化页签操作

RuoYi 4 years ago
parent
commit
adcb6194c8

+ 6 - 13
ruoyi-ui/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
         }

+ 3 - 0
ruoyi-ui/src/plugins/index.js

@@ -1,3 +1,4 @@
1
+import tab from './tab'
1 2
 import auth from './auth'
2 3
 import cache from './cache'
3 4
 import modal from './modal'
@@ -5,6 +6,8 @@ import download from './download'
5 6
 
6 7
 export default {
7 8
   install(Vue) {
9
+    // 页签操作
10
+    Vue.prototype.$tab = tab
8 11
     // 认证对象
9 12
     Vue.prototype.$auth = auth
10 13
     // 缓存对象

+ 68 - 0
ruoyi-ui/src/plugins/tab.js

@@ -0,0 +1,68 @@
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
+}

+ 1 - 1
ruoyi-ui/src/store/modules/tagsView.js

@@ -14,7 +14,7 @@ const mutations = {
14 14
   },
15 15
   ADD_CACHED_VIEW: (state, view) => {
16 16
     if (state.cachedViews.includes(view.name)) return
17
-    if (!view.meta.noCache) {
17
+    if (view.meta && !view.meta.noCache) {
18 18
       state.cachedViews.push(view.name)
19 19
     }
20 20
   },

+ 6 - 9
ruoyi-ui/src/utils/request.js

@@ -48,19 +48,16 @@ service.interceptors.response.use(res => {
48 48
       return res.data
49 49
     }
50 50
     if (code === 401) {
51
-      let doms = document.getElementsByClassName('el-message-box')[0]
52
-      if(doms === undefined){
53
-        MessageBox.confirm('登录状态已过期,您可以继续留在该页面,或者重新登录', '系统提示', {
51
+      MessageBox.confirm('登录状态已过期,您可以继续留在该页面,或者重新登录', '系统提示', {
54 52
           confirmButtonText: '重新登录',
55 53
           cancelButtonText: '取消',
56 54
           type: 'warning'
57 55
         }
58
-        ).then(() => {
59
-          store.dispatch('LogOut').then(() => {
60
-            location.href = '/index';
61
-          })
62
-        }).catch(() => {});
63
-      }
56
+      ).then(() => {
57
+        store.dispatch('LogOut').then(() => {
58
+          location.href = '/index';
59
+        })
60
+      }).catch(() => {});
64 61
       return Promise.reject('无效的会话,或者会话已过期,请重新登录。')
65 62
     } else if (code === 500) {
66 63
       Message({

+ 2 - 2
ruoyi-ui/src/views/monitor/job/log.vue

@@ -245,8 +245,8 @@ export default {
245 245
     },
246 246
     // 返回按钮
247 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 252
     handleQuery() {

+ 14 - 0
ruoyi-ui/src/views/system/dict/data.vue

@@ -79,6 +79,15 @@
79 79
           v-hasPermi="['system:dict:export']"
80 80
         >导出</el-button>
81 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 91
       <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
83 92
     </el-row>
84 93
 
@@ -316,6 +325,11 @@ export default {
316 325
       this.queryParams.pageNum = 1;
317 326
       this.getList();
318 327
     },
328
+    // 返回按钮
329
+    handleClose() {
330
+      const obj = { path: "/system/dict" };
331
+      this.$tab.closeOpenPage(obj);
332
+    },
319 333
     /** 重置按钮操作 */
320 334
     resetQuery() {
321 335
       this.resetForm("queryForm");

+ 2 - 2
ruoyi-ui/src/views/system/role/authUser.vue

@@ -153,8 +153,8 @@ export default {
153 153
     },
154 154
     // 返回按钮
155 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 160
     handleQuery() {

+ 2 - 2
ruoyi-ui/src/views/system/user/authRole.vue

@@ -109,8 +109,8 @@ export default {
109 109
     },
110 110
     /** 关闭按钮 */
111 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
 };

+ 1 - 2
ruoyi-ui/src/views/system/user/profile/resetPwd.vue

@@ -64,8 +64,7 @@ export default {
64 64
       });
65 65
     },
66 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
 };

+ 1 - 2
ruoyi-ui/src/views/system/user/profile/userInfo.vue

@@ -68,8 +68,7 @@ export default {
68 68
       });
69 69
     },
70 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
 };

+ 2 - 2
ruoyi-ui/src/views/tool/gen/editTable.vue

@@ -211,8 +211,8 @@ export default {
211 211
     },
212 212
     /** 关闭按钮 */
213 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 218
   mounted() {