Parcourir la source

feat: 修复考试第二场不会定时抓拍的问题

chenhao il y a 2 ans
Parent
commit
df03868a58

+ 6 - 5
src/features/OnlineExam/Examing/ExamingHome.vue

@@ -42,11 +42,16 @@ const examRecordDataId = +route.params.examRecordDataId;
 store.exam.examId = examId;
 store.exam.examRecordDataId = examRecordDataId;
 
+//#region 人脸抓拍与活体检测
+let { snapId, doSnap, showSnapResult } = useFaceCompare();
+let { showFaceId } = useFaceLive(doSnap);
+
 useScreenTop(examRecordDataId);
 useWXSocket();
 const { userSubmitPaper, realSubmitPaper } = useRealSubmitPaper(
   examId,
-  examRecordDataId
+  examRecordDataId,
+  doSnap
 );
 
 async function userClickSubmit() {
@@ -126,10 +131,6 @@ function onStartAnswer({
   usedExamTimes.startTimestamp = Date.now()
 }
 
-//#region 人脸抓拍与活体检测
-let { snapId, doSnap, showSnapResult } = useFaceCompare();
-let { showFaceId } = useFaceLive(doSnap);
-
 type CompareResult = { hasError: boolean; fileName: string };
 function onCompareResult({ hasError, fileName }: CompareResult) {
   if (hasError) {

+ 6 - 3
src/features/OnlineExam/Examing/setups/useFaceCompare.ts

@@ -15,7 +15,7 @@ type Ret = {
     examRecordDataId: string | number
   ) => Promise<void>;
 };
-let singleton: Ret;
+let singleton: Ret | null;
 /** 人脸后台Face++比对 */
 export function useFaceCompare(): Ret {
   if (singleton) return singleton;
@@ -79,7 +79,7 @@ export function useFaceCompare(): Ret {
   watch(
     () => store.exam.SNAPSHOT_INTERVAL,
     () => {
-      if (store.exam.SNAPSHOT_INTERVAL) {
+      if (store.exam.SNAPSHOT_INTERVAL > 0) {
         // 考务设置抓拍间隔
         addInterval(() => {
           logger({
@@ -100,7 +100,10 @@ export function useFaceCompare(): Ret {
   }
 
   // 离开此页面时,可能还有心跳请求未返回
-  onUnmounted(() => cancelShow && cancelShow.abort());
+  onUnmounted(() => {
+    cancelShow && cancelShow.abort();
+    singleton && (singleton = null);
+  });
 
   let cancelShow: AbortController;
 

+ 5 - 3
src/features/OnlineExam/Examing/setups/useSubmitPaper.tsx

@@ -2,11 +2,13 @@ import router from "@/router";
 import { useTimers } from "@/setups/useTimers";
 import { store } from "@/store/store";
 import { answerAllQuestions } from "./useAnswerQuestions";
-import { useFaceCompare } from "./useFaceCompare";
 
-export function useRealSubmitPaper(examId: number, examRecordDataId: number) {
+export function useRealSubmitPaper(
+  examId: number,
+  examRecordDataId: number,
+  doSnap: () => void
+) {
   const { addTimeout } = useTimers();
-  const { doSnap } = useFaceCompare();
 
   async function userSubmitPaper(usedExamTimes: {
     usedExamSeconds: number;

+ 3 - 2
src/features/OnlineExam/FaceRecognition.vue

@@ -204,7 +204,7 @@ async function getSnapShot(compareSync: boolean): Promise<Blob | unknown> {
       }
       return;
     }
-    video.pause();
+    // video.pause();
     const canvas = document.createElement("canvas");
     canvas.width = 220;
     canvas.height = 165;
@@ -213,7 +213,8 @@ async function getSnapShot(compareSync: boolean): Promise<Blob | unknown> {
     context?.drawImage(video, 0, 0, 220, 165);
 
     canvas.toBlob((blob) => resolve(blob!), "image/png", 0.95);
-  }).finally(() => void videoStartPlay()); // finally 会在返回前执行,满足我们的要求
+  })
+  // .finally(() => void videoStartPlay()); // finally 会在返回前执行,满足我们的要求
 }
 
 // 用来比对两次抓拍照片的md5是否一样