Prechádzať zdrojové kódy

v3.8.0 新增tab对象简化页签操作

YunaiV 3 rokov pred
rodič
commit
8e0415a8fe

+ 3 - 0
yudao-ui-admin/src/plugins/index.js

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

+ 67 - 0
yudao-ui-admin/src/plugins/tab.js

@@ -0,0 +1,67 @@
+import store from '@/store'
+import router from '@/router';
+
+export default {
+  // 刷新当前tab页签
+  refreshPage(obj) {
+    const { path, query, matched } = router.currentRoute;
+    if (obj === undefined) {
+      matched.forEach((m) => {
+        if (m.components && m.components.default && m.components.default.name) {
+          if (!['Layout', 'ParentView'].includes(m.components.default.name)) {
+            obj = { name: m.components.default.name, path: path, query: query };
+          }
+        }
+      });
+    }
+    return store.dispatch('tagsView/delCachedView', obj).then(() => {
+      const { path, query } = obj
+      router.replace({
+        path: '/redirect' + path,
+        query: query
+      })
+    })
+  },
+  // 关闭当前tab页签,打开新页签
+  closeOpenPage(obj) {
+    store.dispatch("tagsView/delView", router.currentRoute);
+    if (obj !== undefined) {
+      return router.push(obj);
+    }
+  },
+  // 关闭指定tab页签
+  closePage(obj) {
+    if (obj === undefined) {
+      return store.dispatch('tagsView/delView', router.currentRoute).then(({ lastPath }) => {
+        return router.push(lastPath || '/');
+      });
+    }
+    return store.dispatch('tagsView/delView', obj);
+  },
+  // 关闭所有tab页签
+  closeAllPage() {
+    return store.dispatch('tagsView/delAllViews');
+  },
+  // 关闭左侧tab页签
+  closeLeftPage(obj) {
+    return store.dispatch('tagsView/delLeftTags', obj || router.currentRoute);
+  },
+  // 关闭右侧tab页签
+  closeRightPage(obj) {
+    return store.dispatch('tagsView/delRightTags', obj || router.currentRoute);
+  },
+  // 关闭其他tab页签
+  closeOtherPage(obj) {
+    return store.dispatch('tagsView/delOthersViews', obj || router.currentRoute);
+  },
+  // 添加tab页签
+  openPage(title, url) {
+    var obj = { path: url, meta: { title: title } }
+    store.dispatch('tagsView/addView', obj);
+    return router.push(url);
+  },
+  // 修改tab页签
+  updatePage(obj) {
+    return store.dispatch('tagsView/updateVisitedView', obj);
+  }
+}

+ 1 - 1
yudao-ui-admin/src/store/modules/tagsView.js

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

+ 1 - 2
yudao-ui-admin/src/views/bpm/form/formEditor.vue

@@ -449,8 +449,7 @@ export default {
     },
     /** 关闭按钮 */
     close() {
-      this.$store.dispatch("tagsView/delView", this.$route);
-      this.$router.push({ path: "/bpm/manager/form", query: { t: Date.now()}})
+      this.$tab.closeOpenPage({ path: "/bpm/manager/form" });
     },
     encodeFields() {
       const fields = []

+ 1 - 2
yudao-ui-admin/src/views/bpm/model/modelEditor.vue

@@ -111,8 +111,7 @@ export default {
     },
     /** 关闭按钮 */
     close() {
-      this.$store.dispatch("tagsView/delView", this.$route);
-      this.$router.push({ path: "/bpm/manager/model", query: { t: Date.now()}})
+      this.$tab.closeOpenPage({ path: "/bpm/manager/model" });
     },
   }
 };

+ 1 - 2
yudao-ui-admin/src/views/bpm/oa/leave/create.vue

@@ -66,8 +66,7 @@ export default {
         // 添加的提交
         createLeave(this.form).then(response => {
           this.$modal.msgSuccess("发起成功");
-          this.$store.dispatch("tagsView/delView", this.$route);
-          this.$router.push({ path: "/bpm/oa/leave"});
+          this.$tab.closeOpenPage({ path: "/bpm/oa/leave" });
         });
       });
     }

+ 1 - 1
yudao-ui-admin/src/views/bpm/processInstance/create.vue

@@ -146,7 +146,7 @@ export default {
       }).then(response => {
         this.$modal.msgSuccess("发起流程成功");
         // 关闭当前窗口
-        this.$store.dispatch("tagsView/delView", this.$route);
+        this.$tab.closeOpenPage();
         this.$router.go(-1);
       }).catch(() => {
         conf.disabled = false; // 表单开启

+ 1 - 1
yudao-ui-admin/src/views/bpm/processInstance/detail.vue

@@ -302,7 +302,7 @@ export default {
       }).then(response => {
         this.$modal.msgSuccess("发起流程成功");
         // 关闭当前窗口
-        this.$store.dispatch("tagsView/delView", this.$route);
+        this.$tab.closeOpenPage();
         this.$router.go(-1);
       }).catch(() => {
         conf.disabled = false; // 表单开启

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

@@ -64,8 +64,7 @@ export default {
       });
     },
     close() {
-      this.$store.dispatch("tagsView/delView", this.$route);
-      this.$router.push({ path: "/index" });
+      this.$tab.closePage();
     }
   }
 };

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

@@ -68,8 +68,7 @@ export default {
       });
     },
     close() {
-      this.$store.dispatch("tagsView/delView", this.$route);
-      this.$router.push({ path: "/index" });
+      this.$tab.closePage();
     }
   }
 };

+ 1 - 2
yudao-ui-admin/src/views/system/user/profile/userSocial.vue

@@ -92,8 +92,7 @@ export default {
       });
     },
     close() {
-      this.$store.dispatch("tagsView/delView", this.$route);
-      this.$router.push({ path: "/index" });
+      this.$tab.closePage();
     }
   }
 };

+ 4 - 2
yudao-ui-admin/src/views/tool/codegen/editTable.vue

@@ -211,8 +211,10 @@ export default {
     },
     /** 关闭按钮 */
     close() {
-      this.$store.dispatch("tagsView/delView", this.$route);
-      this.$router.push({ path: "/tool/codegen", query: { t: Date.now()}})
+      this.$tab.closeOpenPage({
+        path: "/tool/codegen",
+        query: { t: Date.now(), pageNum: this.$route.query.pageNum } }
+      );
     }
   },
   mounted() {