OnlinePractice.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <script setup lang="ts">
  2. import {
  3. onlinePracticeCourseListApi,
  4. onlinePracticeExamListApi,
  5. } from "@/api/onlinePractice";
  6. import { WEEKDAY_NAMES } from "@/constants/constants";
  7. import { store } from "@/store/store";
  8. import { PracticeExam } from "@/types/student-client";
  9. import moment from "moment";
  10. import { SelectOption } from "naive-ui";
  11. import { onMounted } from "vue";
  12. import { useRoute, useRouter } from "vue-router";
  13. const route = useRoute();
  14. const router = useRouter();
  15. // exam-list
  16. let examId: number = $ref();
  17. let examList = $ref<SelectOption[]>([]);
  18. async function getExamList() {
  19. const userId = store.user.id;
  20. const res = await onlinePracticeExamListApi(userId);
  21. let exams = res.data || [];
  22. examList = exams.map((item) => {
  23. return {
  24. label: item.name,
  25. value: item.id,
  26. };
  27. });
  28. }
  29. // course-list
  30. let enterButtonClicked = $ref(false);
  31. let courseList = $ref<PracticeExam[]>([]);
  32. async function getCourseList() {
  33. const res = await onlinePracticeCourseListApi(examId);
  34. courseList = res.data || [];
  35. }
  36. async function checkExamInProgress() {
  37. return Promise.resolve(false);
  38. }
  39. async function toEnterPractice(course: PracticeExam) {
  40. if (enterButtonClicked) return;
  41. // 有断点或者异常,停止后续处理
  42. if (await checkExamInProgress().catch(() => true)) return;
  43. void router.push({
  44. name: "OnlineExamOverview",
  45. params: {
  46. examId: course.examId,
  47. },
  48. });
  49. }
  50. function toEnterPracticeList(course: PracticeExam) {
  51. void router.push({
  52. name: "OnlinePracticeRecord",
  53. params: {
  54. examId: course.examId,
  55. },
  56. query: {
  57. examStudentId: course.examStudentId,
  58. examName: encodeURIComponent(course.examName),
  59. courseName: encodeURIComponent(course.courseName),
  60. },
  61. });
  62. }
  63. // transfer
  64. function weekDayNameTransfer(week: number): string {
  65. return WEEKDAY_NAMES[week] ? `周${WEEKDAY_NAMES[week]}` : "";
  66. }
  67. function courseInBetween(course: PracticeExam) {
  68. return moment(store.getTimeStamp).isBetween(
  69. moment(course.startTime),
  70. moment(course.endTime)
  71. );
  72. }
  73. function courseInCycle(course: PracticeExam) {
  74. if (!course.examCycleEnabled) return true;
  75. const weekday = moment(store.getTimeStamp).isoWeekday();
  76. if (!course.examCycleWeek.includes(weekday)) return false;
  77. const HHmm = moment(store.getTimeStamp).format("HH:mm");
  78. return course.examCycleTimeRange.some((range) =>
  79. range.timeRange.some((v) => HHmm >= v[0] && HHmm <= v[1])
  80. );
  81. }
  82. function courseIsDisabled(course: PracticeExam) {
  83. return (
  84. !courseInBetween(course) ||
  85. course.allowExamCount < 1 ||
  86. enterButtonClicked ||
  87. !courseInCycle(course)
  88. );
  89. }
  90. function courseDiableReason(course: PracticeExam) {
  91. if (!courseInBetween(course)) {
  92. return "当前时间不在练习开放时间范围";
  93. } else if (course.allowExamCount < 1) {
  94. return "无剩余练习次数";
  95. } else if (enterButtonClicked) {
  96. return "请稍后点击";
  97. } else if (!courseInCycle(course)) {
  98. return "不在练习时间周期内";
  99. } else {
  100. return "";
  101. }
  102. }
  103. // init
  104. async function initData() {
  105. await getExamList();
  106. if (route.query.examId) {
  107. examId = Number(route.query.examId);
  108. } else {
  109. examId = examList[0] && (examList[0].value as number);
  110. }
  111. void getCourseList();
  112. }
  113. onMounted(() => {
  114. void initData();
  115. });
  116. </script>
  117. <template>
  118. <div class="qm-mb-20">
  119. <span>选择考试批次:</span>
  120. <n-select
  121. v-model:value="examId"
  122. class="qm-select"
  123. :options="examList"
  124. ></n-select>
  125. </div>
  126. <n-table class="n-table-text-center" :singleLine="false">
  127. <colgroup>
  128. <col />
  129. <col />
  130. <col />
  131. <col />
  132. <col />
  133. <col />
  134. <col />
  135. <col width="200px" />
  136. </colgroup>
  137. <thead>
  138. <tr>
  139. <th>课程</th>
  140. <th>考试进入时间</th>
  141. <th>考试时间周期</th>
  142. <th>练习次数</th>
  143. <th>最近正确率</th>
  144. <th>平均正确率</th>
  145. <th>最高正确率</th>
  146. <th>操作</th>
  147. </tr>
  148. </thead>
  149. <tbody>
  150. <tr v-for="course in courseList" :key="course.courseCode">
  151. <td>{{ course.courseName }}</td>
  152. <td>
  153. {{ course.startTime }} <br />
  154. ~ <br />
  155. {{ course.endTime }}
  156. </td>
  157. <td>
  158. <div v-if="course.examCycleEnabled">
  159. <p>
  160. <span
  161. v-for="(week, index) in course.examCycleWeek"
  162. :key="index"
  163. >{{ weekDayNameTransfer(week) }}</span
  164. >
  165. </p>
  166. <p>
  167. <span
  168. v-for="(rang, rindex) in course.examCycleTimeRange"
  169. :key="rindex"
  170. >
  171. {{ rang.timeRange[0] }}~{{ rang.timeRange[1] }}
  172. </span>
  173. </p>
  174. </div>
  175. </td>
  176. <td>{{ course.practiceCount }}</td>
  177. <td>{{ course.recentObjectiveAccuracy }}%</td>
  178. <td>{{ course.aveObjectiveAccuracy }}%</td>
  179. <td>{{ course.maxObjectiveAccuracy }}%</td>
  180. <td>
  181. <n-button
  182. type="success"
  183. block
  184. :disabled="courseIsDisabled(course)"
  185. :title="courseDiableReason(course)"
  186. @click="toEnterPractice(course)"
  187. >进入练习</n-button
  188. >
  189. <n-button type="success" block @click="toEnterPracticeList(course)"
  190. >查看详情</n-button
  191. >
  192. </td>
  193. </tr>
  194. </tbody>
  195. </n-table>
  196. </template>