浏览代码

心跳异常跳出

Michael Wang 6 年之前
父节点
当前提交
3ec58af7b1

+ 8 - 7
src/components/FaceRecognition/FaceRecognition.vue

@@ -58,7 +58,7 @@ export default {
         try {
           console.log("启动摄像头");
           const stream = await navigator.mediaDevices.getUserMedia({
-            video: { facingMode: "user", width: 400, height: 300 }
+            video: { facingMode: "user", width: 400, height: 250 }
           });
 
           video.srcObject = stream;
@@ -172,12 +172,13 @@ export default {
     async showSnapResult(fileName, examRecordDataId) {
       try {
         // 获取抓拍结果
-        const snapRes = (await this.$http.get(
-          "/api/ecs_oe_student_face/examCaptureQueue/getExamCaptureResult?fileName=" +
-            fileName +
-            "&examRecordDataId=" +
-            examRecordDataId
-        )).data;
+        const snapRes =
+          (await this.$http.get(
+            "/api/ecs_oe_student_face/examCaptureQueue/getExamCaptureResult?fileName=" +
+              fileName +
+              "&examRecordDataId=" +
+              examRecordDataId
+          )).data || {};
         if (this.$route.name !== "OnlineExamingHome") {
           // 非考试页,不显示结果,也不继续查询
           return;

+ 4 - 0
src/features/Login/Login.vue

@@ -86,6 +86,10 @@ export default {
     };
   },
   async created() {
+    this.$Message.config({
+      duration: 10
+    });
+
     try {
       const res = await this.$http.get(
         "/api/ecs_core/org/getRootOrgByCode?code=" + this.$route.params.domain

+ 2 - 0
src/features/OnlineExam/Examing/ExamingHome.vue

@@ -288,6 +288,8 @@ export default {
               this.$route.params.examId
             }/examRecordData/${this.$route.params.examRecordDataId}/end`
           });
+        } else {
+          this.$Message.error("交卷失败");
         }
       } catch (e) {
         console.log(e);

+ 11 - 9
src/features/OnlineExam/Examing/RemainTime.vue

@@ -16,7 +16,6 @@ export default {
   },
   async mounted() {
     this.heartbeatErrorNum = 0;
-    this.first = true;
     this.getRemainTimeFromServer();
     this.intervalA = setInterval(() => {
       this.getRemainTimeFromServer();
@@ -33,15 +32,18 @@ export default {
   methods: {
     ...mapMutations(["setShouldSubmitPaper"]),
     async getRemainTimeFromServer() {
-      try {
-        const res = await this.$http.get(
-          "/api/ecs_oe_student/examControl/examHeartbeat"
-        );
-        this.remainTime = res.data;
+      const res = await this.$http.get(
+        "/api/ecs_oe_student/examControl/examHeartbeat"
+      );
+      if (/\d+/.test(res.data)) {
+        if (this.remainTime === null) {
+          // 仅当剩余考试时间没有被初始化才使用服务器时间。否则使用本机时间。
+          this.remainTime = res.data;
+        }
         this.heartbeatErrorNum = 0;
-      } catch (e) {
+      } else {
         this.heartbeatErrorNum++;
-        if (this.heartbeatErrorNum === 5) {
+        if (this.heartbeatErrorNum === 10) {
           // 心跳异常5次则退出考试
           this.$Modal.error({
             title: "网络连接异常",
@@ -52,7 +54,7 @@ export default {
           });
           return;
         }
-        this.getRemainTimeFromServer();
+        setTimeout(() => this.getRemainTimeFromServer(), 10 * 1000);
       }
     }
   },

+ 10 - 0
src/utils/axios.js

@@ -53,6 +53,16 @@ qmInstance.interceptors.response.use(
     return response;
   },
   error => {
+    if (!error.response) {
+      // "Network Error" 网络不通,直接返回
+      Message.error({
+        content: "网络连接异常,请检查网络设置。",
+        duration: 6,
+        closable: true
+      });
+
+      return Promise.reject(error);
+    }
     // 这里是返回状态码不为200时候的错误处理
     let status = error.response.status;