ScoreVerify.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <template>
  2. <div class="my-container">
  3. <mark-header />
  4. <div class="tw-flex tw-gap-1">
  5. <mark-body origImageUrls="sheetUrls" @error="renderError" />
  6. <MarkBoardInspect
  7. :tagged="isCurrentTagged"
  8. :isFirst="isFirst"
  9. :isLast="isLast"
  10. @makeTag="saveTaskToServer"
  11. @fetchTask="fetchTask"
  12. />
  13. </div>
  14. </div>
  15. <MinimapModal />
  16. </template>
  17. <script setup lang="ts">
  18. import { onMounted } from "vue";
  19. // import {
  20. // getInspectedSettingOfImportInspect,
  21. // getSingleInspectedTaskOfImportInspect,
  22. // saveInspectedTaskOfImportInspect,
  23. // } from "@/api/importInspectPage";
  24. import {
  25. getInspectedSettingOfImportInspect,
  26. getSingleInspectedTaskOfImportInspect,
  27. saveInspectedTaskOfImportInspect,
  28. } from "@/api/scoreVerify";
  29. import { store } from "@/store/store";
  30. import MarkHeader from "./MarkHeader.vue";
  31. import MinimapModal from "@/features/mark/MinimapModal.vue";
  32. import { useRoute } from "vue-router";
  33. // import MarkBody from "../studentInspect/MarkBody.vue";
  34. import MarkBody from "./markBody.vue";
  35. import MarkBoardInspect from "./MarkBoardInspect.vue";
  36. import type { AdminPageSetting } from "@/types";
  37. import { message } from "ant-design-vue";
  38. import { addFileServerPrefixToTask } from "@/utils/utils";
  39. const route = useRoute();
  40. const { studentId } = route.query as {
  41. studentId: string | number;
  42. };
  43. let studentIds: (number | string)[] = $ref([]);
  44. // let tagIds: number[] = $ref([]);
  45. let currentStudentId = $ref<string | number>(0);
  46. async function updateSetting() {
  47. const settingRes = await getInspectedSettingOfImportInspect(
  48. studentId as string
  49. );
  50. const { examType, fileServer, doubleTrack } = settingRes.data;
  51. store.initSetting({ examType, fileServer, doubleTrack } as AdminPageSetting);
  52. // store.status.totalCount = settingRes.data.inspectCount;
  53. // store.status.markedCount = 0;
  54. // if (!settingRes.data.inspectCount) {
  55. // store.message = settingRes.data.message;
  56. // } else {
  57. if (studentId) {
  58. studentIds = [studentId];
  59. } else {
  60. studentIds = settingRes.data.studentIds || [];
  61. }
  62. // tagIds = settingRes.data.tagIds;
  63. // }
  64. }
  65. // 要通过fetchTask调用
  66. async function updateTask() {
  67. if (!currentStudentId) {
  68. return;
  69. }
  70. const mkey = "fetch_task_key";
  71. void message.info({ content: "获取任务中...", duration: 1.5, key: mkey });
  72. let res = await getSingleInspectedTaskOfImportInspect("" + currentStudentId);
  73. void message.success({
  74. content: res.data.task?.studentId ? "获取成功" : "无任务",
  75. key: mkey,
  76. });
  77. isCurrentTagged = !!res.data.flagged;
  78. if (res.data.task?.studentId) {
  79. let rawTask = res.data.task;
  80. store.currentTask = addFileServerPrefixToTask(rawTask);
  81. } else {
  82. store.message = res.data.message;
  83. }
  84. }
  85. let isCurrentTagged = $ref(false);
  86. // const isCurrentTagged = $computed(() => tagIds.includes(currentStudentId));
  87. const isFirst = $computed(() => studentIds.indexOf(currentStudentId) === 0);
  88. const isLast = $computed(
  89. () => studentIds.indexOf(currentStudentId) === studentIds.length - 1
  90. );
  91. async function fetchTask(next: boolean, init?: boolean) {
  92. if (init) {
  93. currentStudentId = studentIds[0];
  94. } else if (isLast && next) {
  95. return; // currentStudentId是最后一个不调用
  96. } else if (isFirst && !next) {
  97. return; // currentStudentId是第一个不调用
  98. } else {
  99. currentStudentId =
  100. studentIds[studentIds.indexOf(currentStudentId) + (next ? 1 : -1)];
  101. }
  102. if (!currentStudentId) return; // 无currentStudentId不调用
  103. store.status.totalCount = studentIds.length;
  104. store.status.markedCount = studentIds.indexOf(currentStudentId) + 1;
  105. await updateTask();
  106. }
  107. onMounted(async () => {
  108. await updateSetting();
  109. await fetchTask(true, true);
  110. });
  111. const saveTaskToServer = async () => {
  112. const mkey = "save_task_key";
  113. void message.loading({ content: "标记评卷任务...", key: mkey });
  114. const res = await saveInspectedTaskOfImportInspect(
  115. currentStudentId + "",
  116. !isCurrentTagged + ""
  117. );
  118. if (res.data.success) {
  119. void message.success({
  120. content: isCurrentTagged ? "取消标记成功" : "标记成功",
  121. key: mkey,
  122. duration: 2,
  123. });
  124. isCurrentTagged = !isCurrentTagged;
  125. // if (isCurrentTagged) {
  126. // tagIds.splice(tagIds.indexOf(currentStudentId), 1);
  127. // } else {
  128. // tagIds.push(currentStudentId);
  129. // }
  130. } else {
  131. console.log(res.data.message);
  132. void message.error({ content: res.data.message, key: mkey, duration: 10 });
  133. }
  134. };
  135. const renderError = () => {
  136. store.currentTask = undefined;
  137. store.message = "加载失败,请重新加载。";
  138. };
  139. </script>
  140. <style scoped>
  141. .my-container {
  142. width: 100%;
  143. overflow: clip;
  144. }
  145. </style>