OnlineExamHome.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <script setup lang="ts">
  2. import { httpApp } from "@/plugins/axiosApp";
  3. import { ExamType, OnlineExam } from "@/types/student-client";
  4. import { closeMediaStream } from "@/utils/camera";
  5. import { onMounted, watch } from "vue";
  6. import OnlineExamList from "./OnlineExamList.vue";
  7. const { examType = "ONLINE" } = defineProps<{ examType?: ExamType }>();
  8. let courses: OnlineExam[] = $ref([]);
  9. let endCourses: OnlineExam[] = $ref([]);
  10. let loading = $ref(true);
  11. onMounted(async () => {
  12. // router.back 时关闭摄像头
  13. closeMediaStream();
  14. logger({
  15. cnl: ["local", "server"],
  16. pgu: "AUTO",
  17. act: "进入页面",
  18. });
  19. await getData().finally(() => (loading = false));
  20. });
  21. watch(
  22. () => examType,
  23. async () => {
  24. loading = true;
  25. await getData().finally(() => (loading = false));
  26. }
  27. );
  28. async function getData() {
  29. courses = [];
  30. let examListRes: { data: OnlineExam[]; status: number } = {
  31. data: [],
  32. status: 0,
  33. };
  34. let url = "";
  35. if (examType === "ONLINE") {
  36. url = "/api/branch_ecs_oe_admin/examControl/queryExamList";
  37. } else if (examType === "ONLINE_HOMEWORK") {
  38. url = "/api/branch_ecs_oe_admin/examControl/queryHomeworkList";
  39. }
  40. let tried = 0;
  41. while (tried < 5) {
  42. examListRes = await httpApp.get(url, {
  43. noErrorMessage: true,
  44. "axios-retry": {
  45. retries: 4,
  46. retryCondition(error) {
  47. // console.log(error);
  48. if (error.response?.status === 503) {
  49. tried++;
  50. return true;
  51. } else {
  52. return false;
  53. }
  54. },
  55. retryDelay: () => 10 * 1000,
  56. shouldResetTimeout: true,
  57. },
  58. });
  59. tried = 5;
  60. }
  61. if (examListRes.status !== 200) {
  62. logger({
  63. cnl: ["server"],
  64. act: "待考列表获取失败",
  65. dtl: "调用待考列表获取接口超过失败次数",
  66. });
  67. $message.error("服务器繁忙(503)!请稍后重试。", {
  68. duration: 15,
  69. closable: true,
  70. });
  71. return;
  72. } else {
  73. courses = examListRes.data || [];
  74. if (examType === "ONLINE") {
  75. let url = "/api/branch_ecs_oe_admin/examControl/queryExamEndList";
  76. endCourses = (await httpApp.get(url)).data || [];
  77. }
  78. }
  79. }
  80. async function refresh() {
  81. loading = true;
  82. await getData().finally(() => (loading = false));
  83. }
  84. </script>
  85. <template>
  86. <div class="part-box">
  87. <div v-if="loading">loading</div>
  88. <OnlineExamList
  89. v-else
  90. :courses="courses"
  91. :endCourses="endCourses"
  92. :examType="examType"
  93. @refresh="refresh"
  94. />
  95. </div>
  96. </template>
  97. <style scoped></style>