Michael Wang 6 년 전
부모
커밋
1e7234db9e

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

@@ -12,12 +12,7 @@
 import { mapState as globalMapState } from "vuex";
 import { createNamespacedHelpers } from "vuex";
 const { mapState, mapMutations } = createNamespacedHelpers("examingHomeModule");
-import {
-  UPYUN_URL,
-  FACEPP_API,
-  FACEPP_KEY,
-  FACEPP_SECRET
-} from "../../constants/constants.js";
+import { UPYUN_URL } from "../../constants/constants.js";
 
 export default {
   name: "FaceRecognition",
@@ -93,7 +88,7 @@ export default {
       video && video.play();
     },
     async getSnapShot() {
-      return new Promise((resolve, reject) => {
+      return new Promise(resolve => {
         const video = this.$refs.video;
         video.pause();
         var canvas = document.createElement("canvas");
@@ -145,7 +140,7 @@ export default {
     },
     async faceCompare(captureFilePath) {
       try {
-        const res = await this.$http.post(
+        await this.$http.post(
           "/api/ecs_oe_student_face/examCaptureQueue/uploadExamCapture?fileUrl=" +
             UPYUN_URL +
             captureFilePath +

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

@@ -44,7 +44,7 @@ export default {
 
     setInterval(() => {
       this.toggleSnapNow();
-    }, 30000);
+    }, 10 * 60 * 1000);
   },
   // beforeRouteUpdate(to, from, next) {
   //   this.updateQuestion(next);
@@ -99,7 +99,13 @@ export default {
     }
   },
   computed: {
-    ...mapState(["exam", "paperStruct", "examQuestionList", "snapNow"]),
+    ...mapState([
+      "exam",
+      "paperStruct",
+      "examQuestionList",
+      "snapNow",
+      "shouldSumbitPaper"
+    ]),
     previousQuestionOrder: vm => {
       if (vm.examQuestion().order > 1) {
         return vm.examQuestion().order - 1;
@@ -118,6 +124,11 @@ export default {
   watch: {
     $route: function() {
       this.examQuestion();
+    },
+    shouldSumbitPaper(val) {
+      if (val) {
+        this.submitPaper();
+      }
     }
   },
   components: {

+ 37 - 2
src/features/OnlineExam/Examing/RemainTime.vue

@@ -4,6 +4,8 @@
 
 <script>
 import moment from "moment";
+import { createNamespacedHelpers } from "vuex";
+const { mapMutations } = createNamespacedHelpers("examingHomeModule");
 
 export default {
   name: "RemainTime",
@@ -13,13 +15,46 @@ export default {
     };
   },
   async mounted() {
-    // const res = await this.$http.get("/api/ecs_oe_student/examControl/examHeartbeat");
-    // this.remainTime = res.data.leftTime;
+    this.getRemainTimeFromServer();
+    this.first = true;
+    this.remainTime += 60 * 1000; //补偿心跳
+    this.intervalA = setInterval(() => {
+      if (this.first) {
+        // 跳过第一次
+        this.first = false;
+        return;
+      }
+      this.getRemainTimeFromServer();
+    }, 60 * 1000);
+    this.intervalB = setInterval(
+      () => (this.remainTime = this.remainTime - 1000),
+      1000
+    );
+  },
+  beforeDestroy() {
+    clearInterval(this.intervalA);
+    clearInterval(this.intervalB);
+  },
+  methods: {
+    ...mapMutations(["shouldSumbitPaper"]),
+    async getRemainTimeFromServer() {
+      const res = await this.$http.get(
+        "/api/ecs_oe_student/examControl/examHeartbeat"
+      );
+      this.remainTime = res.data;
+    }
   },
   computed: {
     remainTimeFormatted: function() {
       return moment.utc(this.remainTime).format("HH:mm:ss");
     }
+  },
+  watch: {
+    remainTime(val, oldVal) {
+      if (oldVal && val === 0) {
+        this.shouldSumbitPaper();
+      }
+    }
   }
 };
 </script>

+ 5 - 1
src/store.js

@@ -26,7 +26,8 @@ const examingHomeModule = {
     paperStruct: null,
     examQuestionList: null,
     questionFilterType: "ALL",
-    snapNow: false
+    snapNow: false,
+    shouldSubmitPaper: false
   },
   mutations: {
     toggleSnapNow(state) {
@@ -45,6 +46,9 @@ const examingHomeModule = {
         }
         return eq;
       });
+    },
+    shouldSubmitPaper(state) {
+      state.shouldSubmitPaper = !state.shouldSubmitPaper;
     }
   },
   actions: {},