浏览代码

考试时间周期控制

Michael Wang 4 年之前
父节点
当前提交
eb964fcbb3
共有 2 个文件被更改,包括 128 次插入18 次删除
  1. 44 1
      src/features/OnlineExam/OnlineExamList.vue
  2. 84 17
      src/features/OnlinePractice/OnlinePracticeList.vue

+ 44 - 1
src/features/OnlineExam/OnlineExamList.vue

@@ -7,6 +7,7 @@
           <td v-if="!isEpcc" key="cc">层次</td>
           <td v-if="!isEpcc" key="cc">层次</td>
           <td v-if="!isEpcc" key="zy">专业</td>
           <td v-if="!isEpcc" key="zy">专业</td>
           <td>考试进入时间</td>
           <td>考试进入时间</td>
+          <td>考试时间周期</td>
           <td>剩余考试次数</td>
           <td>剩余考试次数</td>
           <td style="max-width: 200px">操作</td>
           <td style="max-width: 200px">操作</td>
         </tr>
         </tr>
@@ -20,6 +21,9 @@
             ~ <br />
             ~ <br />
             {{ course.endTime }}
             {{ course.endTime }}
           </td>
           </td>
+          <td>
+            <span v-html="cycleDesc(course)" />
+          </td>
           <td>{{ course.allowExamCount }}</td>
           <td>{{ course.allowExamCount }}</td>
           <td style="min-width: 180px">
           <td style="min-width: 180px">
             <div
             <div
@@ -145,6 +149,26 @@ export default {
   },
   },
   methods: {
   methods: {
     ...mapMutations(["toggleFaceCheckModal"]),
     ...mapMutations(["toggleFaceCheckModal"]),
+    cycleDesc(course) {
+      if (!course.examCycleEnabled) {
+        return "";
+      }
+      const weekdayNames = {
+        1: "一",
+        2: "二",
+        3: "三",
+        4: "四",
+        5: "五",
+        6: "六",
+        7: "日",
+      };
+      const weekDesc = course.examCycleWeek.map((v) => "周" + weekdayNames[v]);
+      const timeRangeDesc = course.examCycleTimeRange
+        .map((v) => v.timeRange)
+        .map((v) => v[0] + "~" + v[1])
+        .join("<br>");
+      return weekDesc + "<br>" + timeRangeDesc;
+    },
     getNow() {
     getNow() {
       this.now = Date.now() + this.timeDifference;
       this.now = Date.now() + this.timeDifference;
     },
     },
@@ -161,15 +185,34 @@ export default {
         return "无剩余考试次数";
         return "无剩余考试次数";
       } else if (this.countdown > 0) {
       } else if (this.countdown > 0) {
         return "请稍后点击";
         return "请稍后点击";
+      } else if (!this.courseInCycle(course)) {
+        return "不在考试时间周期内";
       } else {
       } else {
         return "";
         return "";
       }
       }
     },
     },
+    courseInCycle(course) {
+      if (!course.examCycleEnabled) {
+        return true;
+      }
+      const weekday = moment().isoWeekday();
+      if (!course.examCycleWeek.includes(weekday)) {
+        return false;
+      }
+      const HHmm = moment().format("HH:mm");
+      const ranges = course.examCycleTimeRange.map((v) => v.timeRange);
+      // console.log(HHmm, ranges);
+      // console.log(HHmm > "11:00" && HHmm < "23:00");
+      const inRange = ranges.some((v) => HHmm > v[0] && HHmm < v[1]);
+      // console.log(inRange);
+      return inRange;
+    },
     disableTheCourse(course) {
     disableTheCourse(course) {
       return (
       return (
         !this.courseInBetween(course) ||
         !this.courseInBetween(course) ||
         course.allowExamCount < 1 ||
         course.allowExamCount < 1 ||
-        this.countdown > 0
+        this.countdown > 0 ||
+        !this.courseInCycle(course)
       );
       );
     },
     },
     async raceEnter(course) {
     async raceEnter(course) {

+ 84 - 17
src/features/OnlinePractice/OnlinePracticeList.vue

@@ -5,6 +5,7 @@
         <tr class="list-header qm-primary-strong-text">
         <tr class="list-header qm-primary-strong-text">
           <td>课程</td>
           <td>课程</td>
           <td>考试进入时间</td>
           <td>考试进入时间</td>
+          <td>考试时间周期</td>
           <td>练习次数</td>
           <td>练习次数</td>
           <td>最近正确率</td>
           <td>最近正确率</td>
           <td>平均正确率</td>
           <td>平均正确率</td>
@@ -19,6 +20,9 @@
             ~ <br />
             ~ <br />
             {{ course.endTime }}
             {{ course.endTime }}
           </td>
           </td>
+          <td>
+            <span v-html="cycleDesc(course)" />
+          </td>
           <td>{{ course.practiceCount }}</td>
           <td>{{ course.practiceCount }}</td>
           <td>{{ course.recentObjectiveAccuracy }}%</td>
           <td>{{ course.recentObjectiveAccuracy }}%</td>
           <td>{{ course.aveObjectiveAccuracy }}%</td>
           <td>{{ course.aveObjectiveAccuracy }}%</td>
@@ -33,7 +37,8 @@
             >
             >
               <i-button
               <i-button
                 class="qm-primary-button qm-primary-button-padding-fix"
                 class="qm-primary-button qm-primary-button-padding-fix"
-                :disabled="!courseInBetween(course)"
+                :disabled="disableTheCourse(course) || enterButtonClicked"
+                :title="disableTheCourse(course) ? disableReason(course) : ''"
                 @click="enterPractice(course)"
                 @click="enterPractice(course)"
               >
               >
                 进入练习
                 进入练习
@@ -69,7 +74,7 @@ export default {
     },
     },
   },
   },
   data() {
   data() {
-    return { now: new Date(), selectedCourse: null };
+    return { now: new Date(), selectedCourse: null, enterButtonClicked: false };
   },
   },
   computed: {
   computed: {
     ...globalMapState(["user", "timeDifference"]),
     ...globalMapState(["user", "timeDifference"]),
@@ -83,6 +88,26 @@ export default {
   },
   },
   methods: {
   methods: {
     ...mapMutations(["toggleFaceCheckModal"]),
     ...mapMutations(["toggleFaceCheckModal"]),
+    cycleDesc(course) {
+      if (!course.examCycleEnabled) {
+        return "";
+      }
+      const weekdayNames = {
+        1: "一",
+        2: "二",
+        3: "三",
+        4: "四",
+        5: "五",
+        6: "六",
+        7: "日",
+      };
+      const weekDesc = course.examCycleWeek.map((v) => "周" + weekdayNames[v]);
+      const timeRangeDesc = course.examCycleTimeRange
+        .map((v) => v.timeRange)
+        .map((v) => v[0] + "~" + v[1])
+        .join("<br>");
+      return weekDesc + "<br>" + timeRangeDesc;
+    },
     getNow() {
     getNow() {
       this.now = Date.now() + this.timeDifference;
       this.now = Date.now() + this.timeDifference;
     },
     },
@@ -92,24 +117,66 @@ export default {
         moment(course.endTime)
         moment(course.endTime)
       );
       );
     },
     },
-    async enterPractice(course) {
-      this.logger({
-        page: "在线练习页面",
-        button: "进入练习按钮",
-        action: "点击",
-      });
-      const alreadyInExam = await this.checkExamInProgress();
-      if (alreadyInExam) {
-        window._hmt.push(["_trackEvent", "在线练习页面", "断点续考", "进入"]);
-        this.logger({ action: "断点续考", detail: "在线练习页面" });
-        return;
+    disableReason(course) {
+      if (!this.courseInBetween(course)) {
+        return "当前时间不在练习开放时间范围";
+      } else if (course.allowExamCount < 1) {
+        return "无剩余练习次数";
+      } else if (this.countdown > 0) {
+        return "请稍后点击";
+      } else if (!this.courseInCycle(course)) {
+        return "不在练习时间周期内";
+      } else {
+        return "";
       }
       }
-
-      window._hmt.push(["_trackEvent", "在线练习页面", "进入练习"]);
-      this.$router.push(
-        `/online-exam/exam/${course.examId}/overview?examStudentId=${course.examStudentId}`
+    },
+    courseInCycle(course) {
+      if (!course.examCycleEnabled) {
+        return true;
+      }
+      const weekday = moment().isoWeekday();
+      if (!course.examCycleWeek.includes(weekday)) {
+        return false;
+      }
+      const HHmm = moment().format("HH:mm");
+      const ranges = course.examCycleTimeRange.map((v) => v.timeRange);
+      // console.log(HHmm, ranges);
+      // console.log(HHmm > "11:00" && HHmm < "23:00");
+      const inRange = ranges.some((v) => HHmm > v[0] && HHmm < v[1]);
+      // console.log(inRange);
+      return inRange;
+    },
+    disableTheCourse(course) {
+      return (
+        !this.courseInBetween(course) ||
+        course.allowExamCount < 1 ||
+        this.countdown > 0 ||
+        !this.courseInCycle(course)
       );
       );
     },
     },
+    async enterPractice(course) {
+      this.enterButtonClicked = true;
+      try {
+        this.logger({
+          page: "在线练习页面",
+          button: "进入练习按钮",
+          action: "点击",
+        });
+        const alreadyInExam = await this.checkExamInProgress();
+        if (alreadyInExam) {
+          window._hmt.push(["_trackEvent", "在线练习页面", "断点续考", "进入"]);
+          this.logger({ action: "断点续考", detail: "在线练习页面" });
+          return;
+        }
+
+        window._hmt.push(["_trackEvent", "在线练习页面", "进入练习"]);
+        this.$router.push(
+          `/online-exam/exam/${course.examId}/overview?examStudentId=${course.examStudentId}`
+        );
+      } finally {
+        this.enterButtonClicked = false;
+      }
+    },
     async enterPracticeList(course) {
     async enterPracticeList(course) {
       this.logger({
       this.logger({
         page: "在线练习页面",
         page: "在线练习页面",