瀏覽代碼

add OnlineExamHome

Michael Wang 3 年之前
父節點
當前提交
d8bf6ad11c
共有 2 個文件被更改,包括 92 次插入3 次删除
  1. 89 2
      src/features/OnlineExam/OnlineExamHome.vue
  2. 3 1
      src/types/student-client.d.ts

+ 89 - 2
src/features/OnlineExam/OnlineExamHome.vue

@@ -1,7 +1,94 @@
-<script setup lang="ts"></script>
+<script setup lang="ts">
+// import EcsOnlineList from "./OnlineExamList.vue";
+
+import { httpApp } from "@/plugins/axiosApp";
+import { ExamType, OnlineExam } from "@/types/student-client";
+import { onMounted } from "vue";
+
+// TODO: https://github.com/vuejs/rfcs/discussions/369  defineProps deconstructure retain reactivity
+// eslint-disable-next-line vue/no-setup-props-destructure
+const { examType = "ONLINE" } = defineProps<{
+  examType?: ExamType;
+}>();
+
+let courses: OnlineExam[] = $ref([]);
+let endCourses: OnlineExam[] = $ref([]);
+
+onMounted(async () => {
+  logger({
+    cnl: ["local", "server"],
+    pgu: "AUTO",
+    act: "进入页面",
+  });
+
+  await getData();
+});
+
+async function getData() {
+  courses = [];
+  let examListRes: { data: OnlineExam[]; status: number } = {
+    data: [],
+    status: 0,
+  };
+  let url = "";
+  if (examType === "ONLINE") {
+    url = "/api/branch_ecs_oe_admin/examControl/queryExamList";
+  } else if (examType === "ONLINE_HOMEWORK") {
+    url = "/api/branch_ecs_oe_admin/examControl/queryHomeworkList";
+  }
+  let tried = 0;
+  while (tried < 5) {
+    examListRes = await httpApp.get(url, {
+      noErrorMessage: true,
+      "axios-retry": {
+        retries: 4,
+        retryCondition(error) {
+          // console.log(error);
+          if (error.response?.status === 503) {
+            tried++;
+            return true;
+          } else {
+            return false;
+          }
+        },
+        retryDelay() {
+          return 10 * 1000;
+        },
+      },
+    });
+    tried = 5;
+  }
+
+  if (examListRes.status !== 200) {
+    logger({
+      cnl: ["server"],
+      act: "待考列表获取失败",
+      dtl: "调用待考列表获取接口超过失败次数",
+    });
+    $message.error("服务器繁忙(503)!请稍后重试。", {
+      duration: 15,
+      closable: true,
+    });
+    return;
+  } else {
+    courses = examListRes.data || [];
+    if (examType === "ONLINE") {
+      let url = "/api/branch_ecs_oe_admin/examControl/queryExamEndList";
+      endCourses = (await httpApp.get(url)).data || [];
+    }
+  }
+}
+</script>
 
 <template>
-  <div>在线考试</div>
+  <!-- <div class="home">
+    <ecs-online-list
+      :courses="courses"
+      :endCourses="endCourses"
+      :examType="examType"
+    ></ecs-online-list>
+  </div>  -->
+  <div>{{ courses }} {{ endCourses }}</div>
 </template>
 
 <style scoped>

+ 3 - 1
src/types/student-client.d.ts

@@ -174,6 +174,8 @@ export type SiteMessage = {
   publishTime: string;
 };
 
+export type ExamType = "ONLINE" | "ONLINE_HOMEWORK" | "PRACTICE";
+
 type BaseExam = {
   /** 考试批次id */
   examId: number;
@@ -182,7 +184,7 @@ type BaseExam = {
   /** 考生的考试记录id */
   examRecordDataId: number;
   /** 考试类型 */
-  examType: "ONLINE" | "ONLINE_HOMEWORK" | "PRACTICE";
+  examType: ExamType;
   /** 课程id */
   courseId: number;
   /** 课程名称 */