OnlinePractice.vue 5.4 KB

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