MarkBoardTrack.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  1. <template>
  2. <div
  3. v-if="store.currentTask"
  4. class="mark-board-track-container"
  5. :class="[store.setting.uiSetting['score.board.collapse'] ? 'hide' : 'show']"
  6. >
  7. <div
  8. class="
  9. tw-flex tw-rounded tw-justify-between tw-p-2 tw-pl-5
  10. top-container
  11. tw-mb-4
  12. "
  13. >
  14. <div class="tw-flex tw-flex-col">
  15. <div>总分</div>
  16. <div class="total-score">
  17. {{ store.currentMarkResult?.markerScore }}
  18. </div>
  19. </div>
  20. <div
  21. class="
  22. tw-flex tw-flex-col tw-place-content-center tw-items-center tw-gap-1
  23. "
  24. >
  25. <a-popconfirm
  26. v-if="store.setting.enableAllZero && !store.setting.forceSpecialTag"
  27. title="确定给全零分?"
  28. ok-text="确定"
  29. cancel-text="取消"
  30. @confirm="$emit('allZeroSubmit')"
  31. >
  32. <a-button type="primary" shape="round" size="medium">
  33. 全零分
  34. </a-button>
  35. </a-popconfirm>
  36. <qm-button type="primary" shape="round" size="medium" @click="submit">
  37. 提交
  38. </qm-button>
  39. </div>
  40. </div>
  41. <div
  42. style="
  43. height: calc(100vh - 56px - 200px);
  44. overflow: hidden;
  45. user-select: none;
  46. position: relative;
  47. "
  48. >
  49. <div
  50. v-if="store.currentTask && store.currentTask.questionList"
  51. class="
  52. tw-flex
  53. tw-gap-2
  54. tw-flex-wrap
  55. tw-justify-between
  56. tw-overflow-auto
  57. tw-content-start
  58. "
  59. style="min-height: 20% !important; max-height: 80% !important"
  60. :style="{ height: `${topPercent}%` }"
  61. >
  62. <template
  63. v-for="(question, index) in store.currentTask?.questionList"
  64. :key="index"
  65. >
  66. <div
  67. @click="chooseQuestion(question)"
  68. class="question tw-rounded tw-cursor-pointer tw-relative"
  69. :class="isCurrentQuestion(question) && 'current-question'"
  70. >
  71. <div>
  72. {{ question.title }} {{ question.mainNumber }}-{{
  73. question.subNumber
  74. }}
  75. </div>
  76. <div class="tw-font-medium tw-text-2xl score">
  77. <!-- 特殊的空格符号 -->
  78. {{ question.score ?? " " }}
  79. </div>
  80. <div
  81. v-if="isCurrentQuestion(question)"
  82. class="current-score-indicator"
  83. ></div>
  84. </div>
  85. </template>
  86. </div>
  87. <div
  88. style="
  89. width: 100%;
  90. height: 4px;
  91. border: 2px solid grey;
  92. cursor: row-resize;
  93. "
  94. ref="dragSpliter"
  95. ></div>
  96. <div
  97. class="tw-flex tw-flex-wrap tw-mt-5 tw-overflow-auto tw-content-start"
  98. style="padding-bottom: 40px; gap: 8px"
  99. :style="{ height: `${100 - topPercent}%` }"
  100. >
  101. <div
  102. v-for="(s, i) in questionScoreSteps"
  103. :key="i"
  104. @click="chooseScore(s)"
  105. class="single-score tw-cursor-pointer tw-font-bold"
  106. :class="isCurrentScore(s) && 'current-score'"
  107. >
  108. {{ s }}
  109. <div v-if="isCurrentScore(s)" class="current-score-indicator"></div>
  110. </div>
  111. </div>
  112. </div>
  113. <div
  114. class="tw-flex tw-justify-between tw-mt-4"
  115. style="position: relative; bottom: 0px; right: 0px; width: 230px"
  116. >
  117. <qm-button
  118. type="primary"
  119. shape="round"
  120. size="large"
  121. :clickTimeout="300"
  122. @click="clearLatestMarkOfCurrentQuetion"
  123. >
  124. 回退
  125. </qm-button>
  126. <qm-button
  127. type="primary"
  128. shape="round"
  129. size="large"
  130. :clickTimeout="300"
  131. @click="clearAllMarksOfCurrentQuetion"
  132. >
  133. 清除本题
  134. </qm-button>
  135. </div>
  136. </div>
  137. </template>
  138. <script setup lang="ts">
  139. import type { Question } from "@/types";
  140. import { isNumber } from "lodash";
  141. import { computed, onMounted, onUnmounted, watch } from "vue";
  142. import { store } from "./store";
  143. import { autoChooseFirstQuestion } from "./use/autoChooseFirstQuestion";
  144. import { message } from "ant-design-vue";
  145. import { dragSplitPane } from "./use/splitPane";
  146. const emit = defineEmits(["submit", "allZeroSubmit"]);
  147. const { dragSpliter, topPercent } = dragSplitPane();
  148. const { chooseQuestion } = autoChooseFirstQuestion();
  149. const questionScoreSteps = computed(() => {
  150. const question = store.currentQuestion;
  151. if (!question) return [];
  152. const remainScore =
  153. Math.round(question.maxScore * 100 - (question.score || 0) * 100) / 100;
  154. const steps = [];
  155. for (
  156. let i = 0;
  157. i <= remainScore;
  158. i = Math.round(i * 100 + question.intervalScore * 100) / 100
  159. ) {
  160. steps.push(i);
  161. }
  162. if (
  163. Math.round(remainScore * 100) % Math.round(question.intervalScore * 100) !==
  164. 0
  165. ) {
  166. steps.push(remainScore);
  167. }
  168. return steps;
  169. });
  170. function isCurrentQuestion(question: Question) {
  171. return (
  172. store.currentQuestion?.mainNumber === question.mainNumber &&
  173. store.currentQuestion?.subNumber === question.subNumber
  174. );
  175. }
  176. watch(
  177. () => store.currentQuestion,
  178. () => {
  179. store.currentScore = undefined;
  180. }
  181. );
  182. function isCurrentScore(score: number) {
  183. return store.currentScore === score;
  184. }
  185. function chooseScore(score: number) {
  186. if (store.currentScore === score) {
  187. store.currentScore = undefined;
  188. } else {
  189. store.currentScore = score;
  190. store.currentSpecialTag = undefined;
  191. }
  192. }
  193. let keyPressTimestamp = 0;
  194. let keys: string[] = [];
  195. function numberKeyListener(event: KeyboardEvent) {
  196. // console.log(event);
  197. if (!store.currentQuestion) return;
  198. function indexOfCurrentQuestion() {
  199. return store.currentTask?.questionList.findIndex(
  200. (q) =>
  201. q.mainNumber === store.currentQuestion?.mainNumber &&
  202. q.subNumber === store.currentQuestion.subNumber
  203. );
  204. }
  205. // tab 循环答题列表
  206. if (event.key === "Tab") {
  207. const idx = indexOfCurrentQuestion() as number;
  208. if (idx >= 0 && store.currentTask) {
  209. const len = store.currentTask.questionList.length;
  210. chooseQuestion(store.currentTask.questionList[(idx + 1) % len]);
  211. event.preventDefault();
  212. }
  213. return;
  214. }
  215. if (event.timeStamp - keyPressTimestamp > 1 * 1000) {
  216. keys = [];
  217. }
  218. keyPressTimestamp = event.timeStamp;
  219. keys.push(event.key);
  220. if (isNaN(parseFloat(keys.join("")))) {
  221. keys = [];
  222. }
  223. if (event.key === "Escape") {
  224. keys = [];
  225. store.currentScore = undefined;
  226. store.currentSpecialTag = undefined;
  227. return;
  228. }
  229. const score = parseFloat(keys.join(""));
  230. if (isNumber(score) && questionScoreSteps.value.includes(score)) {
  231. chooseScore(score);
  232. }
  233. }
  234. function submitListener(e: KeyboardEvent) {
  235. if (import.meta.env.DEV && e.ctrlKey && e.key === "Enter") {
  236. submit();
  237. }
  238. }
  239. onMounted(() => {
  240. document.addEventListener("keydown", numberKeyListener);
  241. document.addEventListener("keydown", submitListener);
  242. });
  243. onUnmounted(() => {
  244. document.removeEventListener("keydown", numberKeyListener);
  245. document.removeEventListener("keydown", submitListener);
  246. });
  247. const handleMouseOverWithBoard = () => {
  248. if (store.setting.uiSetting["score.board.collapse"]) {
  249. const container = document.querySelector(".mark-board-track-container");
  250. if (container) {
  251. container.classList.add("show-board");
  252. }
  253. }
  254. };
  255. const handleMouseOutWithBoard = () => {
  256. if (store.setting.uiSetting["score.board.collapse"]) {
  257. const container = document.querySelector(".mark-board-track-container");
  258. if (container) {
  259. container.classList.remove("show-board");
  260. }
  261. }
  262. };
  263. function clearLatestMarkOfCurrentQuetion() {
  264. if (!store.currentMarkResult || !store.currentQuestion) return;
  265. const ts = store.currentMarkResult?.trackList.filter(
  266. (q) =>
  267. q.mainNumber === store.currentQuestion?.mainNumber &&
  268. q.subNumber === store.currentQuestion?.subNumber
  269. );
  270. if (ts.length === 0) {
  271. return;
  272. }
  273. if (ts.length === 1) {
  274. // 即将清除最后一条记录,置为0,因为watch trackList 算分要考虑不同模式的回评,无法自动
  275. store.currentQuestion.score = null;
  276. }
  277. const maxNumber = Math.max(...ts.map((q) => q.number));
  278. const idx = store.currentMarkResult.trackList.findIndex(
  279. (q) =>
  280. q.mainNumber === store.currentQuestion?.mainNumber &&
  281. q.subNumber === store.currentQuestion?.subNumber &&
  282. q.number === maxNumber
  283. );
  284. if (idx >= 0) {
  285. store.removeScoreTracks = store.currentMarkResult.trackList.splice(idx, 1);
  286. }
  287. }
  288. function clearAllMarksOfCurrentQuetion() {
  289. if (!store.currentMarkResult || !store.currentQuestion) return;
  290. store.removeScoreTracks = store.currentMarkResult?.trackList.filter(
  291. (q) =>
  292. q.mainNumber === store.currentQuestion?.mainNumber &&
  293. q.subNumber === store.currentQuestion?.subNumber
  294. );
  295. store.currentMarkResult.trackList = store.currentMarkResult?.trackList.filter(
  296. (q) =>
  297. !(
  298. q.mainNumber === store.currentQuestion?.mainNumber &&
  299. q.subNumber === store.currentQuestion?.subNumber
  300. )
  301. );
  302. store.currentQuestion.score = null;
  303. }
  304. function submit() {
  305. const errors: any = [];
  306. store.currentTask?.questionList.forEach((question, index) => {
  307. if (!isNumber(question.score)) {
  308. errors.push({
  309. question,
  310. index,
  311. error: `${question.mainNumber}-${question.subNumber} 没有赋分不能提交。`,
  312. });
  313. }
  314. });
  315. if (errors.length === 0) {
  316. emit("submit");
  317. } else {
  318. console.log(errors);
  319. message.error({
  320. content: errors.map((e: any) => `${e.error}`).join("\n"),
  321. duration: 10,
  322. });
  323. }
  324. }
  325. </script>
  326. <style scoped>
  327. .mark-board-track-container {
  328. max-width: 290px;
  329. min-width: 290px;
  330. padding: 20px;
  331. max-height: calc(100vh - 56px - 0px);
  332. overflow: auto;
  333. z-index: 1001;
  334. transition: margin-right 0.5s;
  335. --big-score-color: #283e76;
  336. --high-light-score-color: #5d65ff;
  337. --the-color: #7584ac;
  338. color: var(--the-color);
  339. }
  340. .mark-board-track-container.show {
  341. margin-right: 0;
  342. }
  343. .mark-board-track-container.hide {
  344. margin-right: -290px;
  345. }
  346. /* .hide-board {
  347. display: none;
  348. } */
  349. /* .show-board {
  350. position: absolute;
  351. background-color: white;
  352. right: 0px;
  353. display: block;
  354. } */
  355. .top-container {
  356. background-color: white;
  357. }
  358. .total-score {
  359. color: var(--big-score-color);
  360. font-size: 32px;
  361. }
  362. .question {
  363. min-width: 110px;
  364. max-width: 110px;
  365. min-height: 72px;
  366. padding: 10px;
  367. /* border: 1px solid grey; */
  368. background-color: white;
  369. }
  370. .current-question .score {
  371. /* border: 1px solid yellowgreen;
  372. background-color: lightblue; */
  373. color: var(--high-light-score-color);
  374. }
  375. .single-score {
  376. position: relative;
  377. width: 32px;
  378. height: 32px;
  379. font-size: 12px;
  380. display: grid;
  381. place-content: center;
  382. background-color: white;
  383. border-radius: 30px;
  384. }
  385. .current-score {
  386. /* border: 1px solid yellowgreen; */
  387. color: #5d65ff;
  388. }
  389. .current-score-indicator {
  390. position: absolute;
  391. top: 0;
  392. left: 0;
  393. width: 5px;
  394. height: 5px;
  395. background-color: #5c69f6;
  396. }
  397. </style>