浏览代码

fix message bug

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

+ 6 - 0
src/features/OnlineExam/ExamEnd/ExamEnd.vue

@@ -2,6 +2,7 @@
 import { onlineExamDataApi } from "@/api/onlinePractice";
 import { httpApp } from "@/plugins/axiosApp";
 import router from "@/router";
+import { useUnmounted } from "@/setups/useUnmouted";
 import { store } from "@/store/store";
 import { Store } from "@/types/student-client";
 import { onMounted, onUnmounted } from "vue";
@@ -11,6 +12,8 @@ const route = useRoute();
 const examId = +route.params.examId;
 const examRecordDataId = +route.params.examRecordDataId;
 
+const { isUnmounted } = useUnmounted();
+
 let loading = $ref(true);
 let afterExamRemark = $ref("");
 let cheatingRemark = $ref("");
@@ -69,6 +72,9 @@ async function getExamResult() {
   try {
     const startTime = Date.now();
     for (let i = 0; i < 20; i++) {
+      if (isUnmounted) {
+        return;
+      }
       examResult = (
         await httpApp.get(
           "/api/ecs_oe_student/examControl/getEndExamInfo?examRecordDataId=" +

+ 2 - 1
src/features/OnlineExam/Examing/setups/useFaceCompare.ts

@@ -132,7 +132,8 @@ export function useFaceCompare(): Ret {
         } else if (!snapRes.isPass) {
           $message.error("请调整坐姿,诚信考试");
         }
-        store.exam.compareResultMap.set(fileName, true);
+        // 可能此时已经退出考试了,所以compareResultMap可能为空
+        store.exam.compareResultMap?.set(fileName, true);
       } else {
         addTimeout(
           showSnapResult.bind(null, fileName, examRecordDataId),

+ 9 - 0
src/setups/useUnmouted.ts

@@ -0,0 +1,9 @@
+import { onUnmounted } from "vue";
+
+export function useUnmounted() {
+  let isUnmounted = $ref(false);
+
+  onUnmounted(() => (isUnmounted = true));
+
+  return { isUnmounted: $$(isUnmounted) };
+}