MarkBoardTrack.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  1. <template>
  2. <div
  3. v-if="store.currentTask"
  4. class="mark-board-track-container tw-flex tw-flex-col"
  5. :class="[
  6. {
  7. hide: store.isScoreBoardCollapsed && !props.modal,
  8. 'mark-board-track-container-in-dialog':
  9. store.isScoreBoardCollapsed && !props.modal,
  10. show: !store.isScoreBoardCollapsed,
  11. },
  12. ]"
  13. :style="{
  14. height: props.modal ? '100%' : 'auto',
  15. }"
  16. >
  17. <div
  18. class="tw-flex tw-rounded tw-justify-between tw-p-2 tw-pl-5 top-container tw-mb-4"
  19. >
  20. <div class="tw-flex tw-flex-col">
  21. <div class="tw-flex tw-items-center tw-gap-2">
  22. <img
  23. src="./images/totalscore.png"
  24. style="width: 13px; height: 16px"
  25. />
  26. 总分
  27. </div>
  28. <div class="total-score tw-ml-5 tw-font-bold" style="height: 50px">
  29. <transition-group name="score-number-animation" tag="span">
  30. <span
  31. :key="store.currentTask.markResult.markerScore || 0"
  32. class="tw-inline-block"
  33. >{{ store.currentTask.markResult.markerScore }}</span
  34. >
  35. </transition-group>
  36. </div>
  37. </div>
  38. <div class="tw-flex tw-place-content-center tw-items-center tw-gap-2">
  39. <div class="tw-flex tw-flex-col tw-gap-1">
  40. <a-popconfirm
  41. v-if="store.setting.enableAllZero && !store.setting.forceSpecialTag"
  42. title="确定给全零分?"
  43. :overlayStyle="{ width: '200px' }"
  44. @confirm="$emit('allZeroSubmit')"
  45. >
  46. <a-button
  47. type="primary"
  48. size="middle"
  49. class="all-zero-unselective-button"
  50. >
  51. <span>全零分</span>
  52. </a-button>
  53. </a-popconfirm>
  54. <a-popconfirm
  55. v-if="store.setting.selective"
  56. title="确定是未选做?"
  57. :overlayStyle="{ width: '200px' }"
  58. @confirm="$emit('unselectiveSubmit')"
  59. >
  60. <a-button
  61. type="primary"
  62. size="middle"
  63. class="all-zero-unselective-button"
  64. >
  65. <span>未选做</span>
  66. </a-button>
  67. </a-popconfirm>
  68. </div>
  69. <qm-button
  70. type="primary"
  71. shape="round"
  72. size="middle"
  73. style="height: 76px; border-radius: 10px; padding: 12px"
  74. @click="submit"
  75. >
  76. 提交
  77. </qm-button>
  78. </div>
  79. </div>
  80. <div
  81. style="
  82. height: calc(100% - 56px);
  83. overflow: hidden;
  84. user-select: none;
  85. position: relative;
  86. "
  87. >
  88. <div
  89. v-if="store.currentTask && store.currentTask.questionList"
  90. class="tw-flex tw-gap-2 tw-flex-wrap tw-justify-between tw-overflow-auto tw-content-start"
  91. :style="{ height: `${topPercent}%` }"
  92. >
  93. <template
  94. v-for="(question, index) in store.currentTask.questionList"
  95. :key="index"
  96. >
  97. <div
  98. :id="
  99. store.isScoreBoardCollapsed
  100. ? props.modal
  101. ? ['bq', question.mainNumber, question.subNumber].join('-')
  102. : ''
  103. : ['bq', question.mainNumber, question.subNumber].join('-')
  104. "
  105. class="question tw-rounded tw-cursor-pointer tw-relative tw-mb-2"
  106. :class="isCurrentQuestion(question) && 'current-question'"
  107. @click="chooseQuestion(question)"
  108. @mouseover="
  109. addFocusTrack(
  110. undefined,
  111. question.mainNumber,
  112. question.subNumber,
  113. true
  114. )
  115. "
  116. @mouseleave="removeFocusTrack"
  117. >
  118. <div>
  119. {{ question.title }} {{ question.mainNumber }}-{{
  120. question.subNumber
  121. }}
  122. </div>
  123. <!-- 设置高度 避免动画跳动 -->
  124. <div style="height: 32px">
  125. <transition-group name="score-number-animation" tag="span">
  126. <span
  127. :key="store.currentTask?.markResult.scoreList[index] || 0"
  128. class="tw-font-medium tw-text-2xl score tw-inline-block"
  129. >
  130. <!-- 特殊的空格符号 -->
  131. <!-- eslint-disable-next-line no-irregular-whitespace -->
  132. {{ store.currentTask?.markResult.scoreList[index] ?? " " }}
  133. </span>
  134. </transition-group>
  135. </div>
  136. </div>
  137. </template>
  138. </div>
  139. <div
  140. ref="dragSpliter"
  141. style="
  142. width: 100%;
  143. height: 4px;
  144. border: 2px solid grey;
  145. background-color: grey;
  146. cursor: row-resize;
  147. "
  148. class="split-pane tw-flex tw-justify-evenly"
  149. >
  150. <div
  151. style="
  152. margin-top: -14px;
  153. width: 20px;
  154. height: 16px;
  155. text-align: center;
  156. clip-path: polygon(0 100%, 100% 100%, 50% 0);
  157. background-color: lightskyblue;
  158. cursor: pointer;
  159. "
  160. @click="topPercent = 20"
  161. ></div>
  162. <div
  163. style="
  164. margin-top: -3px;
  165. width: 20px;
  166. height: 16px;
  167. text-align: center;
  168. clip-path: polygon(0 0, 100% 0, 50% 100%);
  169. background-color: lightskyblue;
  170. cursor: pointer;
  171. "
  172. @click="topPercent = 90"
  173. ></div>
  174. </div>
  175. <div
  176. class="tw-flex tw-flex-wrap tw-mt-5 tw-overflow-auto tw-content-start"
  177. style="padding-bottom: 40px; gap: 8px"
  178. :style="{ height: `${100 - topPercent}%` }"
  179. >
  180. <div
  181. v-for="(s, i) in questionScoreSteps.slice(1)"
  182. :key="i"
  183. class="single-score tw-cursor-pointer tw-font-bold"
  184. :class="isCurrentScore(s) && 'current-score'"
  185. @click="chooseScore(s)"
  186. >
  187. {{ s }}
  188. </div>
  189. <div
  190. class="single-score tw-cursor-pointer tw-font-bold"
  191. :class="Object.is(store.currentScore, 0) && 'current-score'"
  192. @click="chooseScore(0)"
  193. >
  194. 0
  195. </div>
  196. <div
  197. class="single-score tw-cursor-pointer tw-font-bold"
  198. :class="Object.is(store.currentScore, -0) && 'current-score'"
  199. title="按 # 可以选中"
  200. @click="chooseScore(-0)"
  201. >
  202. </div>
  203. </div>
  204. </div>
  205. <div
  206. class="tw-flex tw-justify-between tw-mt-4"
  207. style="position: relative; bottom: 0px; right: 0px; width: 230px"
  208. >
  209. <qm-button
  210. type="primary"
  211. shape="round"
  212. size="large"
  213. style="
  214. background-color: var(--app-undo-button-bg-color);
  215. border-color: var(--app-undo-button-bg-color);
  216. "
  217. :clickTimeout="300"
  218. @click="clearLatestMarkOfCurrentQuetion"
  219. >
  220. 回退
  221. </qm-button>
  222. <qm-button
  223. type="primary"
  224. shape="round"
  225. size="large"
  226. :clickTimeout="300"
  227. data-test="clear-score"
  228. @click="clearAllMarksOfCurrentQuetion"
  229. >
  230. 清除本题
  231. </qm-button>
  232. </div>
  233. </div>
  234. </template>
  235. <script setup lang="ts">
  236. import type { Question } from "@/types";
  237. import { isNumber } from "lodash-es";
  238. import { onMounted, onUnmounted, watch } from "vue";
  239. import { store } from "@/store/store";
  240. import { autoChooseFirstQuestion } from "./use/autoChooseFirstQuestion";
  241. import { dragSplitPane } from "./use/splitPane";
  242. import { addFocusTrack, removeFocusTrack } from "./use/focusTracks";
  243. const props = defineProps<{ modal?: boolean }>();
  244. const emit = defineEmits(["submit", "allZeroSubmit", "unselectiveSubmit"]);
  245. const { dragSpliter, topPercent } = dragSplitPane();
  246. watch(topPercent, () => {
  247. if (topPercent.value < 10) {
  248. topPercent.value = 10;
  249. }
  250. if (topPercent.value > 90) {
  251. topPercent.value = 90;
  252. }
  253. });
  254. const { chooseQuestion } = autoChooseFirstQuestion();
  255. // 切换题目是清空上一题的分数
  256. watch(
  257. () => store.currentQuestion,
  258. () => (store.currentScore = undefined)
  259. );
  260. const questionScore = $computed(
  261. () =>
  262. store.currentTask &&
  263. store.currentQuestion &&
  264. store.currentTask.markResult.scoreList[store.currentQuestion.__index]
  265. );
  266. const questionScoreSteps = $computed(() => {
  267. const question = store.currentQuestion;
  268. if (!question) return [];
  269. const remainScore =
  270. Math.round(question.maxScore * 100 - (questionScore || 0) * 100) / 100;
  271. const steps = [];
  272. if (question.intervalScore <= 0) {
  273. console.warn(`question.intervalScore got: ${question.intervalScore}`);
  274. }
  275. for (
  276. let i = 0;
  277. i <= remainScore && question.intervalScore > 0;
  278. i = Math.round(i * 100 + question.intervalScore * 100) / 100
  279. ) {
  280. steps.push(i);
  281. }
  282. if (
  283. Math.round(remainScore * 100) % Math.round(question.intervalScore * 100) !==
  284. 0
  285. ) {
  286. steps.push(remainScore);
  287. }
  288. return steps;
  289. });
  290. function isCurrentQuestion(question: Question) {
  291. return (
  292. store.currentQuestion?.mainNumber === question.mainNumber &&
  293. store.currentQuestion?.subNumber === question.subNumber
  294. );
  295. }
  296. function isCurrentScore(score: number) {
  297. return store.currentScore === score;
  298. }
  299. function chooseScore(score: number) {
  300. if (store.currentScore === score) {
  301. store.currentScore = undefined;
  302. } else {
  303. store.currentScore = score;
  304. store.currentSpecialTag = undefined;
  305. }
  306. }
  307. let keyPressTimestamp = 0;
  308. let keys: string[] = [];
  309. function numberKeyListener(event: KeyboardEvent) {
  310. if (!store.currentQuestion) return;
  311. if (" jiklc".includes(event.key)) return;
  312. if (event.key === "#") {
  313. keys = [];
  314. store.currentScore = -0;
  315. return;
  316. }
  317. function indexOfCurrentQuestion() {
  318. return (
  319. store.currentTask?.questionList.findIndex(
  320. (q) =>
  321. q.mainNumber === store.currentQuestion?.mainNumber &&
  322. q.subNumber === store.currentQuestion.subNumber
  323. ) ?? -1
  324. );
  325. }
  326. // tab 循环答题列表
  327. if (event.key === "Tab") {
  328. const idx = indexOfCurrentQuestion();
  329. if (idx >= 0 && store.currentTask) {
  330. const len = store.currentTask.questionList.length;
  331. chooseQuestion(store.currentTask.questionList[(idx + 1) % len]);
  332. event.preventDefault();
  333. }
  334. return;
  335. }
  336. // 为了cypress可以加速时间
  337. if (Date.now() - keyPressTimestamp > 1 * 1000) {
  338. keys = [];
  339. }
  340. keyPressTimestamp = Date.now();
  341. keys.push(event.key);
  342. if (isNaN(parseFloat(keys.join("")))) {
  343. keys = [];
  344. }
  345. if (event.key === "Escape") {
  346. keys = [];
  347. store.currentScore = undefined;
  348. store.currentSpecialTag = undefined;
  349. return;
  350. }
  351. const score = parseFloat(keys.join(""));
  352. if (isNumber(score) && questionScoreSteps.includes(score)) {
  353. chooseScore(score);
  354. }
  355. }
  356. function submitListener(e: KeyboardEvent) {
  357. // if (import.meta.env.DEV && e.ctrlKey && e.key === "Enter") {
  358. if (e.ctrlKey && e.key === "Enter") {
  359. submit();
  360. }
  361. }
  362. onMounted(() => {
  363. document.addEventListener("keydown", numberKeyListener);
  364. document.addEventListener("keydown", submitListener);
  365. });
  366. onUnmounted(() => {
  367. document.removeEventListener("keydown", numberKeyListener);
  368. document.removeEventListener("keydown", submitListener);
  369. });
  370. watch(
  371. () => store.isScoreBoardCollapsed,
  372. () => {
  373. // 此处的逻辑是 MarkBoardTrackDialog 带来的,不然 numberKeyListener 在两个组件中多次触发有问题
  374. if (store.isScoreBoardCollapsed) {
  375. document.removeEventListener("keydown", numberKeyListener);
  376. document.removeEventListener("keydown", submitListener);
  377. } else {
  378. // 重复添加相同的function是没问题,不会重复触发
  379. document.addEventListener("keydown", numberKeyListener);
  380. document.addEventListener("keydown", submitListener);
  381. }
  382. },
  383. { immediate: true }
  384. );
  385. function clearLatestMarkOfCurrentQuetion() {
  386. if (!store.currentTask?.markResult || !store.currentQuestion) return;
  387. const { __index, mainNumber, subNumber } = store.currentQuestion;
  388. const markResult = store.currentTask.markResult;
  389. const ts = markResult.trackList.filter(
  390. (q) => q.mainNumber === mainNumber && q.subNumber === subNumber
  391. );
  392. if (ts.length === 0) {
  393. return;
  394. }
  395. const lastMark = ts.splice(-1)[0];
  396. store.removeScoreTracks = [lastMark];
  397. markResult.trackList = markResult.trackList.filter((t) => t !== lastMark);
  398. markResult.scoreList[__index] =
  399. ts.length === 0
  400. ? null
  401. : ts
  402. .map((t) => t.score)
  403. .reduce((acc, v) => (acc += Math.round(v * 100)), 0) / 100;
  404. }
  405. function clearAllMarksOfCurrentQuetion() {
  406. if (!store.currentTask?.markResult || !store.currentQuestion) return;
  407. const markResult = store.currentTask.markResult;
  408. store.removeScoreTracks = markResult.trackList.filter(
  409. (q) =>
  410. q.mainNumber === store.currentQuestion?.mainNumber &&
  411. q.subNumber === store.currentQuestion?.subNumber
  412. );
  413. markResult.trackList = markResult.trackList.filter(
  414. (q) => !store.removeScoreTracks.includes(q)
  415. );
  416. const { __index } = store.currentQuestion;
  417. markResult.scoreList[__index] = null;
  418. }
  419. function submit() {
  420. emit("submit");
  421. }
  422. const buttonHeightForSelective = $computed(() =>
  423. store.setting.selective &&
  424. store.setting.enableAllZero &&
  425. !store.setting.forceSpecialTag
  426. ? "36px"
  427. : "76px"
  428. );
  429. </script>
  430. <style scoped>
  431. .mark-board-track-container {
  432. max-width: 290px;
  433. min-width: 290px;
  434. padding: 20px;
  435. max-height: calc(100vh - 56px - 0px);
  436. overflow: auto;
  437. z-index: 1001;
  438. transition: margin-right 0.5s;
  439. color: var(--app-small-header-text-color);
  440. background-color: var(--app-main-bg-color);
  441. }
  442. .mark-board-track-container-in-dialog {
  443. max-width: 100%;
  444. min-width: 100%;
  445. height: 100%;
  446. }
  447. .mark-board-track-container.show {
  448. margin-right: 0;
  449. }
  450. .mark-board-track-container.hide {
  451. margin-right: -100%;
  452. }
  453. .top-container {
  454. background-color: var(--app-container-bg-color);
  455. }
  456. .total-score {
  457. color: var(--app-main-text-color);
  458. font-size: 32px;
  459. }
  460. .question {
  461. min-width: 110px;
  462. max-width: 110px;
  463. min-height: 72px;
  464. padding: 10px;
  465. background-color: var(--app-container-bg-color);
  466. }
  467. .current-question {
  468. color: white;
  469. background-color: var(--app-score-color);
  470. }
  471. .single-score {
  472. position: relative;
  473. width: 32px;
  474. height: 32px;
  475. font-size: var(--app-secondary-font-size);
  476. display: grid;
  477. place-content: center;
  478. background-color: var(--app-container-bg-color);
  479. border-radius: 30px;
  480. }
  481. .current-score {
  482. background-color: var(--app-score-color);
  483. color: white;
  484. }
  485. .all-zero-unselective-button {
  486. height: v-bind(buttonHeightForSelective);
  487. border-radius: 10px;
  488. padding: 7px;
  489. background-color: #4db9ff;
  490. border: none;
  491. }
  492. </style>