فهرست منبع

fix: 练习列表切换考试列表不更新的问题修复

chenhao 2 سال پیش
والد
کامیت
d32af081a0
2فایلهای تغییر یافته به همراه11 افزوده شده و 3 حذف شده
  1. 1 0
      src/api/onlinePractice.ts
  2. 10 3
      src/features/OnlinePractice/OnlinePractice.vue

+ 1 - 0
src/api/onlinePractice.ts

@@ -12,6 +12,7 @@ import {
 type ExamItem = {
   id: number;
   name: string;
+  enable: boolean
 };
 
 /** 获取在线练习考试列表 */

+ 10 - 3
src/features/OnlinePractice/OnlinePractice.vue

@@ -8,7 +8,7 @@ import { store } from "@/store/store";
 import { PracticeExam } from "@/types/student-client";
 import moment from "moment";
 import { SelectOption } from "naive-ui";
-import { onMounted } from "vue";
+import { onMounted, watch } from "vue";
 import { useRoute, useRouter } from "vue-router";
 import { checkExamInProgress } from "../UserLogin/useExamInProgress";
 
@@ -21,7 +21,7 @@ let examList = $ref<SelectOption[]>([]);
 async function getExamList() {
   const userId = store.user.id;
   const res = await onlinePracticeExamListApi(userId);
-  let exams = res.data || [];
+  let exams = (res.data || []).filter((e) => e.enable);
   examList = exams.map((item) => {
     return {
       label: item.name,
@@ -111,12 +111,19 @@ async function initData() {
   } else {
     examId = examList[0] && (examList[0].value as number);
   }
-  if (typeof examId === "number") void getCourseList();
+  // if (typeof examId === "number") void getCourseList();
 }
 
 onMounted(() => {
   void initData();
 });
+
+watch(
+  () => examId,
+  () => {
+    if (typeof examId === "number") void getCourseList();
+  }
+);
 </script>
 
 <template>