2
0

Mark.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509
  1. <template>
  2. <div class="my-container">
  3. <mark-header :showTotalScore="store.isMultiMedia" />
  4. <div class="tw-flex tw-gap-1">
  5. <mark-history showSearch showOrder :getHistory="getHistoryTask" />
  6. <mark-body @error="removeBrokenTask" />
  7. <mark-board-track
  8. v-if="store.isTrackMode"
  9. @submit="saveTaskToServer"
  10. @allZeroSubmit="allZeroSubmit"
  11. @unselectiveSubmit="unselectiveSubmit"
  12. />
  13. <mark-board-key-board
  14. v-if="store.shouldShowMarkBoardKeyBoard"
  15. @submit="saveTaskToServer"
  16. @allZeroSubmit="allZeroSubmit"
  17. @unselectiveSubmit="unselectiveSubmit"
  18. />
  19. <mark-board-mouse
  20. v-if="store.shouldShowMarkBoardMouse"
  21. @submit="saveTaskToServer"
  22. @allZeroSubmit="allZeroSubmit"
  23. @unselectiveSubmit="unselectiveSubmit"
  24. />
  25. </div>
  26. </div>
  27. <AnswerModal />
  28. <PaperModal />
  29. <MinimapModal />
  30. <AllPaperModal />
  31. <SheetViewModal />
  32. <SpecialTagModal />
  33. <ShortCutModal />
  34. <MarkBoardTrackDialog
  35. v-if="store.isTrackMode"
  36. @submit="saveTaskToServer"
  37. @allZeroSubmit="allZeroSubmit"
  38. @unselectiveSubmit="unselectiveSubmit"
  39. />
  40. <a-spin
  41. v-if="statusSpinning"
  42. wrapperClassName="status-spin"
  43. size="large"
  44. :spinning="loadingStatusSpinning"
  45. >
  46. <div
  47. style="height: 100vh"
  48. class="tw-text-8xl tw-flex tw-items-center tw-justify-center tw-text-red-500"
  49. data-test="status-spin"
  50. >
  51. {{ store.getStatusValueName }}
  52. </div>
  53. </a-spin>
  54. </template>
  55. <script setup lang="ts">
  56. import { onMounted, watch, h, nextTick } from "vue";
  57. import {
  58. clearMarkTask,
  59. getGroup,
  60. getSetting,
  61. getStatus,
  62. getTask,
  63. saveTask,
  64. updateUISetting,
  65. doUnselectiveType,
  66. } from "@/api/markPage";
  67. import { store } from "@/store/store";
  68. import MarkHeader from "./MarkHeader.vue";
  69. import MarkBody from "./MarkBody.vue";
  70. import { useTimers } from "@/setups/useTimers";
  71. import MarkHistory from "./MarkHistory.vue";
  72. import MarkBoardTrack from "./MarkBoardTrack.vue";
  73. import type { Question, Task } from "@/types";
  74. import MarkBoardKeyBoard from "./MarkBoardKeyBoard.vue";
  75. import MarkBoardMouse from "./MarkBoardMouse.vue";
  76. import { debounce, isEmpty, isNumber } from "lodash-es";
  77. import { message, Modal } from "ant-design-vue";
  78. import AnswerModal from "./AnswerModal.vue";
  79. import PaperModal from "./PaperModal.vue";
  80. import MinimapModal from "./MinimapModal.vue";
  81. import AllPaperModal from "./AllPaperModal.vue";
  82. import SheetViewModal from "./SheetViewModal.vue";
  83. import SpecialTagModal from "./SpecialTagModal.vue";
  84. import ShortCutModal from "./ShortCutModal.vue";
  85. import { addFileServerPrefixToTask, preDrawImage } from "@/utils/utils";
  86. import { getPaper } from "@/api/jsonMark";
  87. import EventBus from "@/plugins/eventBus";
  88. import { getHistoryTask } from "@/api/markPage";
  89. import MarkBoardTrackDialog from "./MarkBoardTrackDialog.vue";
  90. const { addInterval, addTimeout } = useTimers();
  91. //#region status spinning
  92. /** 试评、正评的页面提示 */
  93. let statusSpinning = $ref(true);
  94. /** 是否还在加载statusValue */
  95. let loadingStatusSpinning = $ref(true);
  96. watch(
  97. () => store.setting.statusValue,
  98. () => {
  99. if (store.setting.statusValue) {
  100. loadingStatusSpinning = false;
  101. addTimeout(() => (statusSpinning = false), 3000);
  102. }
  103. }
  104. );
  105. //#endregion
  106. async function updateMarkTask() {
  107. await clearMarkTask();
  108. }
  109. async function updateSetting() {
  110. const settingRes = await getSetting();
  111. // 初次使用时,重置并初始化uisetting
  112. if (isEmpty(settingRes.data.uiSetting)) {
  113. settingRes.data.uiSetting = {
  114. "answer.paper.scale": 1,
  115. "score.board.collapse": false,
  116. "normal.mode": "keyboard",
  117. "score.fontSize.scale": 1,
  118. "paper.modal": false,
  119. "answer.modal": false,
  120. "minimap.modal": false,
  121. "specialTag.modal": false,
  122. "shortCut.modal": false,
  123. };
  124. }
  125. store.setting = settingRes.data;
  126. if (store.setting.subject?.answerUrl) {
  127. store.setting.subject.answerUrl =
  128. store.setting.fileServer + store.setting.subject?.answerUrl;
  129. }
  130. if (store.setting.subject?.paperUrl) {
  131. store.setting.subject.paperUrl =
  132. store.setting.fileServer + store.setting.subject?.paperUrl;
  133. }
  134. if (store.setting.subject?.paperUrl && store.isMultiMedia) {
  135. await getPaper(store);
  136. }
  137. }
  138. async function updateStatus() {
  139. const res = await getStatus();
  140. if (res.data.valid) Object.assign(store.status, res.data);
  141. }
  142. async function updateGroups() {
  143. const res = await getGroup();
  144. store.groups = res.data;
  145. }
  146. let preDrawing = false;
  147. async function updateTask() {
  148. const res = await getTask();
  149. if (res.data.libraryId) {
  150. let rawTask = res.data;
  151. const newTask = addFileServerPrefixToTask(rawTask);
  152. try {
  153. preDrawing = true;
  154. if (store.isScanImage) {
  155. await preDrawImage(newTask);
  156. }
  157. } finally {
  158. // console.log("preDrawing失败")
  159. preDrawing = false;
  160. }
  161. store.tasks.push(newTask);
  162. if (!store.historyOpen) {
  163. // 在正评中,才能替换task
  164. if (store.currentTask?.studentId !== store.tasks[0].studentId)
  165. store.currentTask = store.tasks[0];
  166. }
  167. // 如果是评完后,再取到的任务,则此时要更新一下status
  168. if (store.status.totalCount - store.status.markedCount === 0) {
  169. await updateStatus();
  170. }
  171. // prefetch sliceUrls image
  172. if (store.tasks.length > 1) {
  173. // 如果不是当前任务,则先等3秒再去取任务,以免和其他请求争夺网络资源
  174. await new Promise((resolve) => setTimeout(resolve, 3000));
  175. }
  176. } else {
  177. store.message = res.data.message;
  178. }
  179. }
  180. function nextTask() {
  181. // 正在预绘制中,则不要再取任务,以免拖慢当前任务的绘制
  182. if (!preDrawing) {
  183. if (store.tasks.length < (store.setting.prefetchCount ?? 3)) {
  184. // 回看打开时,停止取任务
  185. if (!store.historyOpen)
  186. return updateTask().catch((e) => console.log("定时获取任务出错", e));
  187. }
  188. }
  189. }
  190. // 5秒更新一次tasks
  191. addInterval(nextTask, 5 * 1000);
  192. // 不需要
  193. // addInterval(() => {
  194. // updateStatus();
  195. // }, 5 * 60 * 1000);
  196. onMounted(async () => {
  197. await updateMarkTask();
  198. await updateSetting();
  199. await updateStatus();
  200. await updateGroups();
  201. await nextTask();
  202. });
  203. const __debounceUpdate = debounce(() => {
  204. updateUISetting(store.setting.mode, store.setting.uiSetting).catch((e) =>
  205. console.log("保存设置出错", e)
  206. );
  207. }, 3000);
  208. watch(
  209. () => [store.setting.uiSetting, store.setting.mode],
  210. () => {
  211. __debounceUpdate();
  212. },
  213. { deep: true }
  214. );
  215. const showRejectedReason = (task: Task) => {
  216. // const rejectShowedTasksString = sessionStorage.getItem("reject-task-showed");
  217. // let rejectShowedTasks: string[] = [];
  218. // if (rejectShowedTasksString) {
  219. // rejectShowedTasks = JSON.parse(rejectShowedTasksString);
  220. // }
  221. if (
  222. // !rejectShowedTasks.includes(task.secretNumber) &&
  223. task.rejected &&
  224. task.rejectReason
  225. ) {
  226. // rejectShowedTasks.push(task.secretNumber);
  227. // sessionStorage.setItem(
  228. // "reject-task-showed",
  229. // JSON.stringify(rejectShowedTasks)
  230. // );
  231. const [reasonType, reasonDesc] = task.rejectReason.split(":");
  232. Modal.info({
  233. title: null,
  234. closable: false,
  235. maskClosable: false,
  236. centered: true,
  237. icon: null,
  238. okText: "知道了",
  239. wrapClassName: "custom-modal-info",
  240. zIndex: 9999,
  241. bodyStyle: {
  242. padding: "15px",
  243. },
  244. content: () =>
  245. h(
  246. "div",
  247. {
  248. style: {
  249. fontSize: "14px",
  250. color: "var(--app-main-text-color)",
  251. },
  252. },
  253. [
  254. h("div", { style: { marginBottom: "8px" } }, [
  255. h(
  256. "span",
  257. { style: { fontWeight: "bold", marginRight: "0.5em" } },
  258. "打回原因: "
  259. ),
  260. h("span", reasonType),
  261. ]),
  262. h("div", { style: { fontWeight: "bold" } }, "详情描述: "),
  263. h("div", { style: { padding: "4px 2px" } }, reasonDesc),
  264. h("div", { style: { marginBottom: "8px" } }, [
  265. h(
  266. "span",
  267. { style: { fontWeight: "bold", marginRight: "0.5em" } },
  268. "给分记录: "
  269. ),
  270. h("span", task.rejectScoreList),
  271. ]),
  272. ]
  273. ),
  274. });
  275. }
  276. };
  277. // 切换currentTask
  278. watch(
  279. () => store.currentTask,
  280. () => {
  281. // 重置当前选择的quesiton和score
  282. store.currentQuestion = undefined;
  283. store.currentScore = undefined;
  284. void nextTick(() => {
  285. if (store.currentTask) {
  286. showRejectedReason(store.currentTask);
  287. }
  288. });
  289. }
  290. );
  291. const removeBrokenTask = () => {
  292. store.currentTask = undefined;
  293. if (store.historyOpen) {
  294. // store.currentTask = store.historyTasks[0];
  295. // 避免无限加载
  296. store.message = "加载失败,请重新选择。";
  297. } else {
  298. store.tasks.shift();
  299. }
  300. };
  301. const allZeroSubmit = async () => {
  302. const markResult = store.currentTask?.markResult;
  303. if (!markResult) return;
  304. const { markerScore, scoreList, trackList, specialTagList } = markResult;
  305. markResult.markerScore = 0;
  306. const ss = new Array(store.currentTaskEnsured.questionList.length);
  307. markResult.scoreList = ss.fill(0);
  308. markResult.trackList = [];
  309. try {
  310. await saveTaskToServer();
  311. } catch (error) {
  312. console.log("error restore");
  313. } finally {
  314. // console.log({ markerScore, scoreList, trackList });
  315. markResult.markerScore = markerScore;
  316. markResult.scoreList = scoreList;
  317. markResult.trackList = trackList;
  318. markResult.specialTagList = specialTagList;
  319. }
  320. };
  321. const unselectiveSubmit = async () => {
  322. const markResult = store.currentTask?.markResult;
  323. if (!markResult) return;
  324. try {
  325. const res = await doUnselectiveType();
  326. if (res?.data.success) {
  327. void message.success({ content: "未选做处理成功", duration: 3 });
  328. if (!store.historyOpen) {
  329. store.currentTask = undefined;
  330. store.tasks.shift();
  331. store.currentTask = store.tasks[0];
  332. }
  333. if (store.historyOpen) {
  334. EventBus.emit("should-reload-history");
  335. }
  336. await updateStatus();
  337. } else {
  338. void message.error({ content: res?.data.message || "错误", duration: 5 });
  339. }
  340. } catch (error) {
  341. console.log("未选做处理失败", error);
  342. void message.error({ content: "网络异常", duration: 5 });
  343. await new Promise((res) => setTimeout(res, 1500));
  344. window.location.reload();
  345. }
  346. };
  347. const saveTaskToServer = async () => {
  348. if (!store.currentTask) return;
  349. const markResult = store.currentTask.markResult;
  350. if (!markResult) return;
  351. const mkey = "save_task_key";
  352. type SubmitError = {
  353. question: Question;
  354. index: number;
  355. error: string;
  356. };
  357. const errors: SubmitError[] = [];
  358. markResult.scoreList.forEach((score, index) => {
  359. if (!store.currentTask) return;
  360. const question = store.currentTask.questionList[index]!;
  361. let error;
  362. if (!isNumber(score)) {
  363. error = `${question.mainNumber}-${question.subNumber}${
  364. question.questionName ? "(" + question.questionName + ")" : ""
  365. } 没有赋分不能提交。`;
  366. } else if (isNumber(question.maxScore) && score > question.maxScore) {
  367. error = `${question.mainNumber}-${question.subNumber}${
  368. question.questionName ? "(" + question.questionName + ")" : ""
  369. } 赋分大于最高分不能提交。`;
  370. } else if (isNumber(question.minScore) && score < question.minScore) {
  371. error = `${question.mainNumber}-${question.subNumber}${
  372. question.questionName ? "(" + question.questionName + ")" : ""
  373. } 赋分小于最低分不能提交。`;
  374. }
  375. if (error) {
  376. errors.push({ question, index, error });
  377. }
  378. });
  379. if (errors.length !== 0) {
  380. console.log(errors);
  381. const msg = errors.map((v) => h("div", `${v.error}`));
  382. void message.warning({
  383. content: h("span", ["校验失败", ...msg]),
  384. duration: 10,
  385. key: mkey,
  386. });
  387. return;
  388. }
  389. if (
  390. markResult.scoreList.length !== store.currentTask.questionList.length ||
  391. !markResult.scoreList.every((s) => isNumber(s))
  392. ) {
  393. console.error({ content: "markResult格式不正确,缺少分数", key: mkey });
  394. return;
  395. }
  396. if (!store.isTrackMode) {
  397. markResult.trackList = [];
  398. } else {
  399. const trackScores =
  400. markResult.trackList
  401. .map((t) => Math.round((t.score || 0) * 100))
  402. .reduce((acc, s) => acc + s, 0) / 100;
  403. if (trackScores !== markResult.markerScore) {
  404. void message.error({
  405. content: "轨迹分与总分不一致,请检查。",
  406. duration: 3,
  407. key: mkey,
  408. });
  409. return;
  410. }
  411. }
  412. if (store.setting.forceSpecialTag) {
  413. if (
  414. markResult.trackList.length === 0 &&
  415. markResult.specialTagList.length === 0
  416. ) {
  417. void message.error({
  418. content: "强制标记已开启,请至少使用一个标记。",
  419. duration: 5,
  420. key: mkey,
  421. });
  422. return;
  423. }
  424. }
  425. console.log("save task to server");
  426. void message.loading({ content: "保存评卷任务...", key: mkey });
  427. const res = await saveTask();
  428. if (!res) return;
  429. // 故意不在此处同步等待,因为不必等待
  430. updateStatus().catch((e) => console.log("保存任务后获取status出错", e));
  431. if (res.data.success && store.currentTask) {
  432. void message.success({ content: "保存成功", key: mkey, duration: 2 });
  433. if (!store.historyOpen) {
  434. store.currentTask = undefined;
  435. store.tasks.shift();
  436. store.currentTask = store.tasks[0];
  437. } else {
  438. EventBus.emit("should-reload-history");
  439. }
  440. } else if (res.data.message) {
  441. console.log(res.data.message);
  442. void message.error({ content: res.data.message, key: mkey, duration: 10 });
  443. } else if (!store.currentTask) {
  444. void message.warn({ content: "暂无新任务", key: mkey, duration: 10 });
  445. }
  446. // 获取下一个任务
  447. void nextTask();
  448. };
  449. </script>
  450. <style>
  451. .custom-modal-info .ant-modal-content {
  452. border-radius: 4px;
  453. }
  454. </style>
  455. <style scoped>
  456. .my-container {
  457. width: 100%;
  458. overflow: clip;
  459. }
  460. .status-spin {
  461. position: absolute;
  462. top: 0;
  463. left: 0;
  464. min-width: max(var(--app-min-width), 100%);
  465. height: 100vh;
  466. z-index: 6000;
  467. background-color: rgba(200, 200, 200, 0.7);
  468. }
  469. </style>