Переглянути джерело

网络错误会重试请求

Michael Wang 5 роки тому
батько
коміт
ca3eb88d56

+ 31 - 8
src/features/OnlineExam/Examing/ExamingHome.vue

@@ -551,15 +551,38 @@ export default {
       {
       {
         const examRecordDataId = this.$route.params.examRecordDataId;
         const examRecordDataId = this.$route.params.examRecordDataId;
 
 
-        const faceBiopsyBaseInfoData = await this.$http.get(
-          "/api/ecs_oe_student/faceBiopsy/getFaceBiopsyBaseInfo?examRecordDataId=" +
-            examRecordDataId
-        );
-        console.log(faceBiopsyBaseInfoData.data);
+        for (let i = 0; i < 5; i++) {
+          try {
+            const faceBiopsyBaseInfoData = await this.$http.get(
+              "/api/ecs_oe_student/faceBiopsy/getFaceBiopsyBaseInfo?examRecordDataId=" +
+                examRecordDataId
+            );
+            console.log(faceBiopsyBaseInfoData.data);
+
+            faceVerifyMinute = faceBiopsyBaseInfoData.data.faceVerifyMinute;
+            identificationOfLivingBodyScheme =
+              faceBiopsyBaseInfoData.data.identificationOfLivingBodyScheme;
+            break;
+          } catch (error) {
+            console.log(error);
+            if (!error.response) {
+              await new Promise(resolve => setTimeout(resolve, 1000));
+              continue; // 网络不通
+            } else {
+              break;
+            }
+          }
+        }
+      }
 
 
-        faceVerifyMinute = faceBiopsyBaseInfoData.data.faceVerifyMinute;
-        identificationOfLivingBodyScheme =
-          faceBiopsyBaseInfoData.data.identificationOfLivingBodyScheme;
+      if (identificationOfLivingBodyScheme === null) {
+        this.$Message.error({
+          content: "获取活体检测信息失败,退出登录",
+          duration: 15,
+          closable: true,
+        });
+        this.logout("?LogoutReason=获取活体检测信息失败");
+        return;
       }
       }
 
 
       // 仅在线上使用活体检测
       // 仅在线上使用活体检测

+ 28 - 3
src/features/OnlineExam/Examing/FaceMotion/FaceMotion.vue

@@ -315,21 +315,44 @@ export default {
   methods: {
   methods: {
     async fetchData() {
     async fetchData() {
       const examRecordDataId = this.$route.params.examRecordDataId;
       const examRecordDataId = this.$route.params.examRecordDataId;
-      // FIXME: 失败了再取
-      const faceBiopsyInfoData = await this.$http.get(
+      // 失败了再取
+      const faceBiopsyInfoData = await this.$httpGetRetry(
         "/api/ecs_oe_student/faceBiopsy/getFaceBiopsyInfo?examRecordDataId=" +
         "/api/ecs_oe_student/faceBiopsy/getFaceBiopsyInfo?examRecordDataId=" +
           examRecordDataId
           examRecordDataId
       );
       );
+      if (typeof faceBiopsyInfoData === undefined) {
+        this.$Message.error({
+          content: "获取活体检测信息失败,退出登录",
+          duration: 15,
+          closable: true,
+        });
+        this.logout("?LogoutReason=获取活体检测信息失败");
+        return;
+      }
+
+      // const faceBiopsyInfoData = await this.$http.get(
+      //   "/api/ecs_oe_student/faceBiopsy/getFaceBiopsyInfo?examRecordDataId=" +
+      //     examRecordDataId
+      // );
 
 
       const faceBiopsyInfo = faceBiopsyInfoData.data;
       const faceBiopsyInfo = faceBiopsyInfoData.data;
       console.log(faceBiopsyInfo);
       console.log(faceBiopsyInfo);
       this.faceBiopsyInfo = faceBiopsyInfo;
       this.faceBiopsyInfo = faceBiopsyInfo;
     },
     },
     async closeMe() {
     async closeMe() {
-      const faceLiveResultData = await this.$http.post(
+      const faceLiveResultData = await this.$httpPostRetry(
         "/api/ecs_oe_student/faceBiopsy/saveFaceBiopsyResult",
         "/api/ecs_oe_student/faceBiopsy/saveFaceBiopsyResult",
         this.finalResult
         this.finalResult
       );
       );
+      if (typeof faceLiveResultData === undefined) {
+        this.$Message.error({
+          content: "保存活体检测信息失败,退出登录",
+          duration: 15,
+          closable: true,
+        });
+        this.logout("?LogoutReason=保存活体检测信息失败");
+        return;
+      }
       const faceLiveResult = faceLiveResultData.data;
       const faceLiveResult = faceLiveResultData.data;
       console.log(faceLiveResult);
       console.log(faceLiveResult);
       this.$emit("closeFaceMotion", faceLiveResult);
       this.$emit("closeFaceMotion", faceLiveResult);
@@ -671,6 +694,8 @@ export default {
               console.log(error);
               console.log(error);
             } finally {
             } finally {
               // this.pauseDetecting = false;
               // this.pauseDetecting = false;
+              // 未完成同步比对,继续进行
+              if (!this.doneCompare) this.pauseDetecting = false;
               this.videoStartPlay();
               this.videoStartPlay();
             }
             }
           }
           }

+ 1 - 0
src/main.js

@@ -15,6 +15,7 @@ import "./styles/global.css";
 // import "qm-tracking/face.js";
 // import "qm-tracking/face.js";
 
 
 import axiosPlugin from "./utils/axios";
 import axiosPlugin from "./utils/axios";
+import "./utils/axiosRetry";
 import "./utils/monitors";
 import "./utils/monitors";
 
 
 import MainLayout from "@/components/MainLayout/MainLayout.vue";
 import MainLayout from "@/components/MainLayout/MainLayout.vue";

+ 37 - 0
src/utils/axiosRetry.js

@@ -0,0 +1,37 @@
+import Vue from "vue";
+
+Vue.prototype.$httpGetRetry = async function(...args) {
+  for (let i = 0; i < 5; i++) {
+    try {
+      const res = await Vue.prototype.$http.get.apply(Vue, args);
+
+      return res;
+    } catch (error) {
+      console.log(error);
+      if (!error.response) {
+        await new Promise(resolve => setTimeout(resolve, 1000));
+        continue; // 网络不通
+      } else {
+        return error; // 其他错误不管
+      }
+    }
+  }
+};
+
+Vue.prototype.$httpPostRetry = async function(...args) {
+  for (let i = 0; i < 5; i++) {
+    try {
+      const res = await Vue.prototype.$http.post.apply(Vue, args);
+
+      return res;
+    } catch (error) {
+      console.log(error);
+      if (!error.response) {
+        await new Promise(resolve => setTimeout(resolve, 1000));
+        continue; // 网络不通
+      } else {
+        return error; // 其他错误不管
+      }
+    }
+  }
+};