Browse Source

创建阅卷工作状态轮询查询

xiatian 6 năm trước cách đây
mục cha
commit
62c6223a5b
2 tập tin đã thay đổi với 143 bổ sung0 xóa
  1. 33 0
      src/modules/marking/views/MarkWork.vue
  2. 110 0
      src/plugins/axios.js

+ 33 - 0
src/modules/marking/views/MarkWork.vue

@@ -337,8 +337,41 @@ export default {
           this.filterMarkWork();
           this.paging();
           this.loading = false;
+          this.getWorkStatus();
         });
     },
+    getWorkStatus() {
+      let creatingWorkIds = this.getCreatingWorkId();
+      if (creatingWorkIds != "") {
+        this.$httpWithoutBar
+          .get(
+            MARKING_API + "/markWorks/getWorkList?workIds=" + creatingWorkIds
+          )
+          .then(response => {
+            response.data.forEach(element => {
+              if (element.status != 0) {
+                this.tableData.forEach(e => {
+                  if (e.id == element.id) {
+                    e.status = element.status;
+                  }
+                });
+              }
+            });
+            setTimeout(() => {
+              this.getWorkStatus();
+            }, 5000);
+          });
+      }
+    },
+    getCreatingWorkId() {
+      var tempData = [];
+      this.tableData.forEach(element => {
+        if (element.status == 0) {
+          tempData.push(element.id);
+        }
+      });
+      return tempData.join(",");
+    },
     searchMarkWork() {
       this.filterMarkWork();
       this.paging();

+ 110 - 0
src/plugins/axios.js

@@ -19,6 +19,7 @@ let config = {
 
 const _$httpWith500Msg = axios.create(config);
 const _$http = axios.create(config); // no auto 500 error UI
+const _$httpWithoutBar = axios.create(config);
 
 /**
  * A. token lifecycle
@@ -299,6 +300,106 @@ _$http.interceptors.response.use(
   }
 );
 
+_$httpWithoutBar.interceptors.request.use(
+  // no auto 500 error UI
+  function(config) {
+    networkInformationHint();
+    // Do something before request is sent
+    if (config.url.includes("/login") === false) {
+      if (!wk_token) {
+        const user = JSON.parse(window.sessionStorage.getItem("user"));
+        if (!user) {
+          if (
+            window.___lastInvalidDate === undefined ||
+            window.___lastInvalidDate < Date.now() - 300
+          ) {
+            Vue.prototype.$alert("登录失效,请重新登录!", "提示", {
+              confirmButtonText: "确定",
+              callback: () => {
+                router.push("/login/" + getRootOrgId());
+              }
+            });
+            window.___lastInvalidDate = Date.now();
+          }
+          return;
+        }
+        wk_token = user.token;
+        wk_key = user.key;
+        wk_orgId = user.rootOrgId;
+      }
+      if (wk_token && config.headers.common["token"] == null) {
+        config.headers.common["token"] = wk_token;
+        config.headers.common["key"] = wk_key;
+      }
+    } else {
+      wk_token = null;
+    }
+    return config;
+  },
+  function(error) {
+    // Do something with request error
+    Vue.prototype.$notify({
+      showClose: true,
+      message: error,
+      type: "error"
+    });
+    return Promise.reject(error);
+  }
+);
+_$httpWithoutBar.interceptors.response.use(
+  // no auto 500 error UI
+  response => {
+    recordRequest(response);
+    return response;
+  },
+  error => {
+    if (!error.response) {
+      Vue.prototype.$notify({
+        showClose: true,
+        message: "网络连接异常,请检查网络设置。",
+        type: "error"
+      });
+      return Promise.reject(error);
+    }
+    // 这里是返回状态码不为200时候的错误处理
+    let status = error.response.status;
+
+    // 登录失效 跳转登录页面
+    if (status == 403 || status == 401) {
+      if (
+        window.___lastInvalidDate === undefined ||
+        window.___lastInvalidDate < Date.now() - 300
+      ) {
+        Vue.prototype.$alert("登录失效,请重新登录!", "提示", {
+          confirmButtonText: "确定",
+          callback: () => {
+            router.push("/login/" + getRootOrgId());
+          }
+        });
+        window.___lastInvalidDate = Date.now();
+      }
+      return Promise.reject(error);
+    } else if (status == 405) {
+      Vue.prototype.$alert("没有权限!", "提示", {
+        confirmButtonText: "确定",
+        callback: () => {
+          router.push("/login/" + getRootOrgId());
+        }
+      });
+      return Promise.reject(error);
+    } else if (status == 502) {
+      Vue.prototype.$alert("服务器异常!", "提示", {
+        confirmButtonText: "确定"
+      });
+      return Promise.reject(error);
+    }
+
+    if (status != 200) {
+      return Promise.reject(error);
+    }
+  }
+);
+
 Plugin.install = function(Vue) {
   Vue.$http = _$http; // no auto 500 error UI
   Object.defineProperties(Vue.prototype, {
@@ -330,6 +431,15 @@ Plugin.install = function(Vue) {
       }
     }
   });
+
+  Vue.$httpWithoutBar = _$httpWithoutBar;
+  Object.defineProperties(Vue.prototype, {
+    $httpWithoutBar: {
+      get() {
+        return _$httpWithoutBar;
+      }
+    }
+  });
 };
 
 Vue.use(Plugin);