zhangjie преди 4 години
родител
ревизия
683f444a1a

+ 6 - 2
src/features/invigilation/ExamInvigilation/ExamInvigilation.vue

@@ -285,6 +285,7 @@ export default {
         type: "light",
       },
       setT: null,
+      loopRunning: false,
       students: [],
       messages: [],
     };
@@ -300,11 +301,13 @@ export default {
     },
   },
   mounted() {
+    this.loopRunning = true;
     this.initData();
   },
   methods: {
     async initData() {
       if (this.setT) clearTimeout(this.setT);
+      if (!this.loopRunning) return;
 
       const fetchAll = [
         this.getCount(),
@@ -315,8 +318,8 @@ export default {
 
       this.fullScreenChange(this.checkDocIsFullscreen());
 
-      this.getVideoList();
-      this.getMessageList();
+      await this.getVideoList();
+      await this.getMessageList();
 
       this.setT = setTimeout(() => {
         this.initData();
@@ -404,6 +407,7 @@ export default {
     },
   },
   beforeDestroy() {
+    this.loopRunning = false;
     if (this.setT) clearTimeout(this.setT);
   },
 };

+ 7 - 1
src/features/invigilation/RealtimeMonitoring/ExamBatchDialog.vue

@@ -47,12 +47,14 @@ export default {
         pageNumber: 1,
         pageSize: 100,
       });
+      const dnow = Date.now();
       this.examBatchs = res.data.data.records.map((item) => {
         return {
           ...item,
           label: `${item.name}【${dateFormatForAPI(
             item.startTime
           )} - ${dateFormatForAPI(item.endTime)}】`,
+          isExaming: dnow > item.startTime && dnow < item.endTime,
         };
       });
 
@@ -62,7 +64,9 @@ export default {
           (item) => item.id === this.initExamid
         );
       } else {
-        selectedExam = this.examBatchs[0];
+        // 优先取当前第一个正在考试的考试,没有则取记录第一条数据
+        selectedExam = this.examBatchs.find((item) => item.isExaming);
+        selectedExam = selectedExam || this.examBatchs[0];
       }
 
       this.examBatchId = selectedExam && selectedExam.id;
@@ -81,6 +85,8 @@ export default {
         return;
       }
       const exam = this.examBatchs.find((item) => item.id === this.examBatchId);
+      const dnow = Date.now();
+      exam.isExaming = dnow > exam.startTime && dnow < exam.endTime;
       this.$emit("confirm", exam);
       this.cancel();
     },

+ 24 - 5
src/features/invigilation/RealtimeMonitoring/RealtimeMonitoring.vue

@@ -356,6 +356,7 @@ export default {
     };
   },
   created() {
+    this.loopRunning = true;
     const user = this.$store.state.user;
     this.IS_INSPECTION =
       user.roleCodes.includes("INSPECTION") &&
@@ -380,12 +381,14 @@ export default {
       this.clearLoopSetTs();
       if (!this.loopRunning) return;
 
-      await this.getList().catch(() => {});
-      await this.$refs.SummaryLine.initData().catch(() => {});
+      let fetchAll = [this.getList()];
+      if (this.$refs.SummaryLine)
+        fetchAll.push(this.$refs.SummaryLine.initData());
       if (!this.IS_INSPECTION) {
-        await this.getMonitorCallCount().catch(() => {});
-        await this.fetchWarningNotice().catch(() => {});
+        fetchAll.push(this.getMonitorCallCount());
+        fetchAll.push(this.fetchWarningNotice());
       }
+      await Promise.all(fetchAll).catch(() => {});
 
       this.loopSetTs.push(
         setTimeout(() => {
@@ -399,7 +402,23 @@ export default {
       this.curExamBatch = examBatch;
       this.toSearch();
 
-      this.timerUpdatePage();
+      if (!this.IS_INSPECTION) {
+        this.getMonitorCallCount();
+        this.fetchWarningNotice();
+      }
+      // 正在考试的考试,开启定时更新;
+      if (examBatch.isExaming) {
+        this.loopRunning = true;
+        this.clearLoopSetTs();
+        this.loopSetTs.push(
+          setTimeout(() => {
+            this.timerUpdatePage();
+          }, 10 * 1000)
+        );
+      } else {
+        this.loopRunning = false;
+        this.clearLoopSetTs();
+      }
     },
     pageTypeChange(pageType) {
       this.pageType = pageType;

+ 4 - 0
src/features/invigilation/RealtimeMonitoring/VideoCommunication.vue

@@ -102,6 +102,7 @@ export default {
       total: 0,
       size: 100,
       setT: null,
+      loopRunning: false,
       appId: "1400411036",
       userMonitor: {},
       client: null,
@@ -109,11 +110,13 @@ export default {
     };
   },
   mounted() {
+    this.loopRunning = true;
     this.getCommunicationList();
   },
   methods: {
     async getCommunicationList() {
       if (this.setT) clearTimeout(this.setT);
+      if (!this.loopRunning) return;
 
       const res = await communicationList({
         examId: this.examId,
@@ -248,6 +251,7 @@ export default {
     },
   },
   beforeDestroy() {
+    this.loopRunning = false;
     if (this.setT) clearTimeout(this.setT);
     if (this.client) {
       this.client.leave();

+ 1 - 1
src/features/invigilation/common/SecondTimer.vue

@@ -27,7 +27,7 @@ export default {
       this.recordSecondCount = 0;
     },
     pause() {
-      clearTimeout(this.setT);
+      clearInterval(this.setT);
       this.$emit("on-duration", this.recordSecondCount, this.duration);
     },
     timeToText(timeNumber) {

+ 8 - 3
src/features/invigilation/common/TextClock.vue

@@ -16,6 +16,7 @@ export default {
   },
   mounted() {
     this.parseDate();
+    this.start();
   },
   methods: {
     parseDate() {
@@ -28,14 +29,18 @@ export default {
       const hour = ("00" + val).substr(("" + val).length);
       const apm = hourNum < 12 ? "上午" : "下午";
       this.text = `${timeStr[0]} ${weekDay} ${apm} ${hour}:${timeStr[1]}`;
-
-      this.setT = setTimeout(() => {
+    },
+    start() {
+      this.setT = setInterval(() => {
         this.parseDate();
       }, 1000);
     },
+    end() {
+      clearInterval(this.setT);
+    },
   },
   beforeDestroy() {
-    if (this.setT) clearTimeout(this.setT);
+    clearInterval(this.setT);
   },
 };
 </script>