Mark.vue 14 KB

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