Browse Source

fix setInterval and setTimeout

Michael Wang 6 years ago
parent
commit
207a1219a1

+ 4 - 2
src/features/OnlineExam/Examing/ExamingEnd.vue

@@ -44,7 +44,8 @@ export default {
     return {
       afterExamRemark: null,
       showObjectScore: null,
-      paperTotalScore: null
+      paperTotalScore: null,
+      cheatingRemark: null
     };
   },
   async mounted() {
@@ -67,7 +68,7 @@ export default {
           this.$route.params.examId +
           `/CHEATING_REMARK`
       );
-      this.cheatingRemark = cheatingRemark.data || false;
+      this.cheatingRemark = cheatingRemark.data || "";
     }
 
     // this.paperTotalScore = this.paperStruct.defaultPaper.questionGroupList
@@ -85,6 +86,7 @@ export default {
 <style scoped>
 .container {
   display: grid;
+  justify-items: center;
   grid-template-columns: 1fr;
   width: 80vw;
   /* height: 100vh; */

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

@@ -53,7 +53,7 @@ export default {
 
     setTimeout(() => {
       this.toggleSnapNow();
-    }, 5 * 1000); // 一分钟后抓拍
+    }, 5 * 1000); // 5秒钟后抓拍
 
     // 仅在线上使用活体检测
     if (
@@ -102,7 +102,7 @@ export default {
         // console.log(res);
         if (res.data) {
           // 考务设置抓拍间隔
-          setInterval(() => {
+          this.snapInterval = setInterval(() => {
             this.toggleSnapNow();
           }, res.data * 60 * 1000);
         }
@@ -127,6 +127,7 @@ export default {
   },
   destroyed() {
     clearInterval(this.submitInterval);
+    clearInterval(this.snapInterval);
   },
   // beforeRouteUpdate(to, from, next) {
   //   this.updateQuestion(next);

+ 4 - 1
src/features/OnlineExam/Examing/FaceId.vue

@@ -97,8 +97,11 @@ export default {
       const examRecordId = this.$route.params.examRecordDataId;
 
       this.timeCount = 60; //人脸检测倒计时60秒
-      setInterval(() => {
+      var timeInterval = setInterval(() => {
         --this.timeCount;
+        if (this.timeCount === 0) {
+          clearInterval(timeInterval);
+        }
       }, 1000);
 
       this.logout = () => {

+ 0 - 8
src/features/OnlineExam/Examing/RemainTime.vue

@@ -19,11 +19,6 @@ export default {
     this.first = true;
     this.getRemainTimeFromServer();
     this.intervalA = setInterval(() => {
-      // if (this.first) {
-      //   // 跳过第一次
-      //   this.first = false;
-      //   return;
-      // }
       this.getRemainTimeFromServer();
     }, 60 * 1000);
     this.intervalB = setInterval(
@@ -43,9 +38,6 @@ export default {
           "/api/ecs_oe_student/examControl/examHeartbeat"
         );
         this.remainTime = res.data;
-        // if (this.first) {
-        //   this.remainTime += 60 * 1000; //补偿心跳
-        // }
         this.heartbeatErrorNum = 0;
       } catch (e) {
         this.heartbeatErrorNum++;

+ 1 - 1
src/features/OnlineExam/OnlineExamList.vue

@@ -52,7 +52,7 @@ export default {
   },
   created() {
     this.getNow();
-    this.intervalID = setInterval(this.getNow, 1000);
+    this.intervalID = setInterval(() => this.getNow(), 1000);
   },
   beforeDestroy() {
     clearInterval(this.intervalID);

+ 1 - 2
src/features/OnlineExam/OnlineExamOverview.vue

@@ -54,7 +54,7 @@ export default {
   },
   async mounted() {
     this.intervalId = setInterval(() => {
-      this.remainTime = this.remainTime - 1; // 为了界面更新,不能写 this.remainTime--
+      this.remainTime -= 1;
       this.isForceRead = TOTAL_READ_TIME - this.remainTime < FORCE_READ_TIME;
       if (this.remainTime === 0) {
         this.goToPaper();
@@ -133,7 +133,6 @@ export default {
             ? `?faceVerifyMinute=${this.startInfo.faceVerifyMinute}`
             : "")
       );
-      window.clearInterval(this.intervalId);
     }
   }
 };