Explorar el Código

Merge branch 'master' of http://git.qmth.com.cn/ExamCloud-3/examcloud-web-admin

weiwenhai hace 6 años
padre
commit
2ccd8a99c5

+ 1 - 0
package.json

@@ -11,6 +11,7 @@
   },
   "dependencies": {
     "axios": "^0.18.0",
+    "axios-progress-bar": "^1.2.0",
     "bootstrap": "^4.2.1",
     "element-ui": "^2.4.9",
     "lodash": "^4.17.11",

+ 1 - 1
src/modules/oe/views/alreadyAudited.vue

@@ -208,7 +208,7 @@
               sortable
               label="审核人"
               prop="auditUserName"
-              width="120"
+              width="180"
             >
             </el-table-column>
           </el-table>

+ 1 - 1
src/modules/oe/views/captureDetail.vue

@@ -157,7 +157,7 @@
                 class="photo-facelivenessPass"
                 v-show="!item.isFacelivenessPass"
               >
-                <i class="el-icon-warning"></i>
+                <i class="el-icon-warning" title="真实性不通过"></i>
               </div>
             </el-col>
           </el-row>

+ 1 - 1
src/modules/questions/directives/directives.js

@@ -12,7 +12,7 @@ function addAudio(el, binding, vnode) {
     var questionAudioId = obj.getAttribute("id");
     if (questionAudioId) {
       console.log("come in");
-      vnode.context.$http
+      vnode.context.$httpWithoutAuth
         .get(QUESTION_API + "/questionAudio/" + questionAudioId)
         .then(response => {
           if (response && response.data) {

+ 6 - 4
src/modules/questions/views/PreviewPaper.vue

@@ -167,10 +167,12 @@ export default {
     //初始化试卷
     initPaper() {
       this.loading = true;
-      this.$http.get(QUESTION_API + "/paper/" + this.paperId).then(response => {
-        this.paper = response.data;
-        this.loading = false;
-      });
+      this.$httpWithoutAuth
+        .get(QUESTION_API + "/paper/" + this.paperId)
+        .then(response => {
+          this.paper = response.data;
+          this.loading = false;
+        });
     },
     back() {
       debugger;

+ 81 - 10
src/plugins/axios.js

@@ -1,6 +1,8 @@
 import Vue from "vue";
 import axios from "axios";
 import router from "../router";
+import { loadProgressBar } from "axios-progress-bar";
+import networkInformationHint from "./networkInformationHint.js";
 
 const ERROR_MSG_CONFIG = require("./errorMsgConfig").default;
 
@@ -15,8 +17,8 @@ let config = {
   withCredentials: true // Check cross-site Access-Control
 };
 
-const _axios = axios.create(config);
-const _axiosWithoutResponseInterceptors = axios.create(config);
+const _$httpWith500Msg = axios.create(config);
+const _$http = axios.create(config); // no auto 500 error UI
 
 /**
  * A. token lifecycle
@@ -37,8 +39,9 @@ function getRootOrgId() {
   }
 }
 
-_axios.interceptors.request.use(
+_$httpWith500Msg.interceptors.request.use(
   function(config) {
+    networkInformationHint();
     // Do something before request is sent
     if (
       config.url.includes("/login") === false &&
@@ -84,8 +87,10 @@ _axios.interceptors.request.use(
   }
 );
 
-_axiosWithoutResponseInterceptors.interceptors.request.use(
+_$http.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) {
@@ -123,9 +128,32 @@ _axiosWithoutResponseInterceptors.interceptors.request.use(
   }
 );
 
+const recordRequest = response => {
+  let matchedRoutePath;
+  try {
+    const matched = router.resolve(location).route.matched;
+    const exactMatched = matched[matched.length - 1];
+    matchedRoutePath = exactMatched.path;
+  } catch (error) {
+    console.log(error);
+    window._hmt.push([
+      "_trackEvent",
+      `页面-${location.pathname}`,
+      "网络请求-响应",
+      "解析出错"
+    ]);
+  }
+  window._hmt.push([
+    "_trackEvent",
+    `页面-${matchedRoutePath || location.pathname}`,
+    "网络请求-响应",
+    new URL(response.config.url, "http://www.qmth.com.cn").pathname
+  ]);
+};
 // Add a response interceptor
-_axios.interceptors.response.use(
+_$httpWith500Msg.interceptors.response.use(
   response => {
+    recordRequest(response);
     return response;
   },
   error => {
@@ -199,8 +227,10 @@ _axios.interceptors.response.use(
 );
 
 // Add a response interceptor
-_axiosWithoutResponseInterceptors.interceptors.response.use(
+_$http.interceptors.response.use(
+  // no auto 500 error UI
   response => {
+    recordRequest(response);
     return response;
   },
   error => {
@@ -246,19 +276,33 @@ _axiosWithoutResponseInterceptors.interceptors.response.use(
 );
 
 Plugin.install = function(Vue) {
-  Vue.$http = _axiosWithoutResponseInterceptors;
+  Vue.$http = _$http; // no auto 500 error UI
   Object.defineProperties(Vue.prototype, {
     $http: {
       get() {
-        return _axiosWithoutResponseInterceptors;
+        return _$http; // no auto 500 error UI
       }
     }
   });
-  Vue.$httpWithMsg = _axios;
+
+  Vue.$httpWithMsg = _$httpWith500Msg;
   Object.defineProperties(Vue.prototype, {
     $httpWithMsg: {
       get() {
-        return _axios;
+        return _$httpWith500Msg;
+      }
+    }
+  });
+
+  // for below request
+  // config.url.includes("/api/ecs_ques/paper/") === false &&
+  // config.url.includes("/api/ecs_ques/questionAudio") === false
+  const _a = axios.create(config);
+  Vue.$httpWithoutAuth = _a;
+  Object.defineProperties(Vue.prototype, {
+    $httpWithoutAuth: {
+      get() {
+        return _a;
       }
     }
   });
@@ -266,4 +310,31 @@ Plugin.install = function(Vue) {
 
 Vue.use(Plugin);
 
+loadProgressBar({}, Vue.$http);
+loadProgressBar({}, Vue.$httpWithMsg);
+loadProgressBar({}, Vue.$httpWithoutAuth);
+
+// const update = (type, e) => {
+//   // debugger;
+//   console.log(type);
+//   console.log(
+//     "e.target.url: ",
+//     e.target.responseURL,
+//     " timeStamp: ",
+//     e.timeStamp.toFixed(2),
+//     " loaded:",
+//     e.loaded,
+//     " total: ",
+//     e.total
+//   );
+//   console.log(e);
+// };
+// Vue.$httpWithMsg.defaults.onDownloadProgress = e => {
+//   update("下载", e);
+// };
+// Vue.$httpWithMsg.defaults.onUploadProgress = e => {
+//   update("上传", e);
+// };
+
+import "axios-progress-bar/dist/nprogress.css";
 export default Plugin;

+ 42 - 0
src/plugins/networkInformationHint.js

@@ -0,0 +1,42 @@
+import Vue from "vue";
+
+let ___networkInformationHintLastTime = Date.now();
+const sessionNoNetworkHint = "networkInformationHint-nohint";
+
+export default function networkInformationHint() {
+  if (navigator.connection && navigator.connection.downlink) {
+    if (navigator.connection.downlink < 2 || navigator.connection.rtt > 1000) {
+      window._hmt.push([
+        "_trackEvent",
+        "网络状况不佳",
+        "下载小于2Mb,延迟大于1000ms"
+      ]);
+
+      if (
+        Date.now() - ___networkInformationHintLastTime > 3000 &&
+        !sessionStorage.getItem(sessionNoNetworkHint)
+      ) {
+        Vue.prototype.$notify({
+          showClose: true,
+          duration: 2000,
+          title: "当前网络状况不佳!",
+          message: `当前网速:下载(${
+            navigator.connection.downlink
+          }Mb) 网络延时(${navigator.connection.rtt}ms) (点击不再提示)`,
+          type: "warning",
+          onClick: () => {
+            Vue.prototype
+              .$alert("不在提示网络状况?", "提示", {
+                confirmButtonText: "确定",
+                cancelButtonText: "取消"
+              })
+              .then(() => {
+                sessionStorage.setItem(sessionNoNetworkHint, true);
+              });
+          }
+        });
+        ___networkInformationHintLastTime = Date.now();
+      }
+    }
+  }
+}

+ 8 - 0
src/router.js

@@ -26,6 +26,14 @@ let router = new Router({
 });
 
 router.beforeEach((to, from, next) => {
+  if (to.path) {
+    window._hmt.push(["_trackPageview", "/admin" + to.fullPath]);
+  }
+
+  if (to.path.includes("/preview_paper/")) {
+    next();
+    return;
+  }
   if (!to.meta.privilegeCodes) {
     next();
   } else {

+ 1 - 0
src/styles/global.css

@@ -1,4 +1,5 @@
 @import "./elementuiCustomize.css";
+@import "./nprogress.css";
 
 body {
   margin: 0;

+ 12 - 0
src/styles/nprogress.css

@@ -0,0 +1,12 @@
+#nprogress .bar {
+  background: yellow !important;
+}
+
+#nprogress .peg {
+  box-shadow: 0 0 10px yellow, 0 0 5px yellow !important;
+}
+
+#nprogress .spinner-icon {
+  border-top-color: yellow !important;
+  border-left-color: yellow !important;
+}

+ 5 - 0
yarn.lock

@@ -1488,6 +1488,11 @@ aws4@^1.8.0:
   resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.8.0.tgz#f0e003d9ca9e7f59c7a508945d7b2ef9a04a542f"
   integrity sha512-ReZxvNHIOv88FlT7rxcXIIC0fPt4KZqZbOlivyWtXLt8ESx84zd3kMC6iK5jVeS2qt+g7ftS7ye4fi06X5rtRQ==
 
+axios-progress-bar@^1.2.0:
+  version "1.2.0"
+  resolved "https://registry.yarnpkg.com/axios-progress-bar/-/axios-progress-bar-1.2.0.tgz#f9ee88dc9af977246be1ef07eedfa4c990c639c5"
+  integrity sha512-PEgWb/b2SMyHnKJ/cxA46OdCuNeVlo8eqL0HxXPtz+6G/Jtpyo49icPbW+jpO1wUeDEjbqpseMoCyWxESxf5pA==
+
 axios@^0.18.0:
   version "0.18.0"
   resolved "https://registry.yarnpkg.com/axios/-/axios-0.18.0.tgz#32d53e4851efdc0a11993b6cd000789d70c05102"