Michael Wang 3 anni fa
parent
commit
b2e0336d07

+ 50 - 87
src/features/OnlineExam/Examing/ExamingHome.vue

@@ -25,6 +25,7 @@ import { initExamData } from "./setups/useInitExamData";
 import { useWXSocket } from "./setups/useWXSocket";
 import { answerAllQuestions } from "./setups/useAnswerQuestions";
 import { useRealSubmitPaper } from "./setups/useSubmitPaper";
+import { Store } from "@/types/student-client";
 
 const { addTimeout, addInterval } = useTimers();
 
@@ -48,44 +49,36 @@ onBeforeUpdate(() => {
 });
 
 watch(
-  () => store.exam.isExceededSwitchCount,
+  () => [route.params, store.exam.examQuestionList],
   () => {
-    logger({ cnl: ["server"], act: "切屏超出次数自动交卷" });
-    void realSubmitPaper();
+    const q = store.exam.examQuestionList.find(
+      (eq) => eq.order === +route.params.order
+    );
+    store.exam.currentQuestion = q!;
   }
 );
 
 // computed: {
 //   ...mapState([
-//     "exam",
-//     "paperStruct",
-//     "examQuestionList",
-//     "snapNow",
-//     "snapProcessingCount",
-//     "remainTime",
-//     "questionAnswerFileUrl",
 //     "uploadModalVisible",
 //   ]),
-//   previousQuestionOrder: (vm) => {
-//     if (vm.examQuestion().order > 1) {
-//       return vm.examQuestion().order - 1;
-//     } else {
-//       return null;
-//     }
-//   },
-//   nextQuestionOrder: (vm) => {
-//     if (vm.examQuestion().order < vm.examQuestionList.length) {
-//       return vm.examQuestion().order + 1;
-//     } else {
-//       return null;
-//     }
-//   },
 // },
 
+// beforeDestroy() {
+//   this.updateExamState({
+//     pictureAnswer: {},
+//   });
+//   // 避免macos上下塘动。避免产生滚动条。
+//   document.body.classList.toggle("hide-body-scroll", false);
+// },
+
+// methods: {
+//   ...mapMutations([
+//     "updateExamQuestion",
+//     "updatePicture",
+//   ]),
+
 // watch: {
-//   $route: function () {
-//     this.examQuestion();
-//   },
 //   questionAnswerFileUrl(value) {
 //     // console.log(this.examQuestion.studentAnswer);
 //     // console.log("watch", value);
@@ -143,24 +136,6 @@ watch(
 //     }
 //   },
 
-//   },
-//   // examQuestionList(val, oldVal) {
-//   //   // console.log(val, oldVal);
-//   // }
-// },
-
-// 10秒检查是否有更改需要提交答案
-addInterval(() => answerAllQuestions(), 5 * 1000);
-
-addTimeout(() => {
-  if (STRICT_CHECK_HOSTS.includes(window.location.hostname)) {
-    if (!checkMainExe()) {
-      void httpApp.post("/api/ecs_oe_student/client/exam/process/discipline");
-      logger({ cnl: ["server"], act: "答题页面discipline" });
-    }
-  }
-}, 60 * 1000);
-
 onMounted(async () => {
   logger({
     cnl: ["server", "local"],
@@ -190,28 +165,7 @@ onMounted(async () => {
   });
 });
 
-// beforeDestroy() {
-//   this.updateExamState({
-//     exam: null,
-//     paperStruct: null,
-//     examQuestionList: null,
-//     questionAnswerFileUrl: [],
-//     pictureAnswer: {},
-//   });
-//   // 避免macos上下塘动。避免产生滚动条。
-//   document.body.classList.toggle("hide-body-scroll", false);
-// },
-
-// methods: {
-//   ...mapMutations([
-//     "updateExamState",
-//     "updateExamQuestion",
-//     "toggleSnapNow",
-//     "updateExamResult",
-//     "resetExamQuestionDirty",
-//     "updatePicture",
-//   ]),
-
+//#region 人脸抓拍与活体检测
 let { snapId, doSnap, showSnapResult } = useFaceCompare();
 let { showFaceId } = useFaceLive(doSnap);
 
@@ -226,6 +180,7 @@ function onCompareResult({ hasError, fileName }: CompareResult) {
     void showSnapResult(fileName, examRecordDataId, cmpResMap);
   }
 }
+//#endregion 人脸抓拍与活体检测
 
 onUnmounted(() => {
   const allFinished = [...cmpResMap].every((v) => v[1]);
@@ -238,34 +193,22 @@ onUnmounted(() => {
       remainCount: remained.length,
     },
   });
+
+  // 清除考试中间数据
+  store.exam = {} as Store["exam"];
 });
 
-// async function updateQuestion(next) {
-//   // 初始化套题的答案,为回填部分选项做准备
-//   // for (let q of this.examQuestionList) {
-//   //   if (q.subQuestionList.length > 0) {
-//   //     q.studentAnswer = [];
-//   //     for (let sq of q.subQuestionList) {
-//   //       q.studentAnswer.push(sq.studentAnswer);
-//   //     }
-//   //   }
-//   // }
-
-//   next && next();
-//   if (!this.exam) return;
-// }
+//#region 提交答案与交卷
+// 10秒检查是否有更改需要提交答案
+addInterval(() => answerAllQuestions(), 5 * 1000);
 
 function shouldSubmitPaper() {
   logger({ cnl: ["server"], act: "时间到自动交卷" });
   void realSubmitPaper();
 }
+//#endregion 提交答案与交卷
 
-// const examQuestion = $computed(() =>
-//   store.exam.examQuestionList?.find(
-//     (eq) => eq.order == route.params.order /*number == string*/
-//   )
-// );
-
+//#region 页面加载失败
 let pageLoadTimeout = $ref(false);
 addTimeout(() => (pageLoadTimeout = true), 30 * 1000);
 
@@ -278,6 +221,25 @@ function reloadPage() {
   });
   window.location.reload();
 }
+//#endregion 页面加载失败
+
+//#region 防作弊检查
+watch(
+  () => store.exam.isExceededSwitchCount,
+  () => {
+    logger({ cnl: ["server"], act: "切屏超出次数自动交卷" });
+    void realSubmitPaper();
+  }
+);
+
+addTimeout(() => {
+  if (STRICT_CHECK_HOSTS.includes(window.location.hostname)) {
+    if (!checkMainExe()) {
+      void httpApp.post("/api/ecs_oe_student/client/exam/process/discipline");
+      logger({ cnl: ["server"], act: "答题页面discipline" });
+    }
+  }
+}, 60 * 1000);
 
 const {
   disableLoginBtnBecauseRemoteApp: disableExamingBecauseRemoteApp,
@@ -291,6 +253,7 @@ function checkRemoteAppClicked() {
 
 // 3分钟检测是否有远程桌面软件在运行
 addInterval(() => checkRemoteApp(), 3 * 60 * 1000);
+//#endregion 防作弊检查
 </script>
 
 <template>

+ 2 - 0
src/types/student-client.d.ts

@@ -166,6 +166,8 @@ export type Store = {
     paperStruct: PaperStruct;
     /** 试题结构 */
     examQuestionList: ExamQuestion[];
+    /** 当前题目 */
+    currentQuestion: ExamQuestion;
     /** 试题过滤类型 */
     questionFilterType: "ALL" | "ANSWERED" | "SIGNED" | "UNANSWERED";
     allAudioPlayTimes: { audioName: string; times: number }[];