MarkBoardTrack.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. <template>
  2. <div
  3. v-if="store.currentTask"
  4. :style="{ display: store.MarkBoardTrackCollapse ? 'none' : 'block' }"
  5. class="mark-board-track-container"
  6. >
  7. <div>
  8. <h1 class="tw-text-3xl tw-text-center">
  9. 总分:{{ store.currentMarkResult?.markerScore || 0 }}
  10. </h1>
  11. </div>
  12. <div class="tw-mb-2 tw-flex tw-place-content-center">
  13. <qm-button type="primary" shape="round" size="large" @click="submit">
  14. 提交
  15. </qm-button>
  16. </div>
  17. <div
  18. v-if="store.currentTask && store.currentTask.questionList"
  19. class="tw-flex tw-gap-1 tw-flex-wrap tw-justify-between"
  20. >
  21. <template
  22. v-for="(question, index) in store.currentTask?.questionList"
  23. :key="index"
  24. >
  25. <div
  26. @click="chooseQuestion(question)"
  27. class="question tw-rounded tw-p-1"
  28. :class="isCurrentQuestion(question) && 'current-question'"
  29. >
  30. <div style="border-bottom: 1px solid grey">
  31. {{ question.title }} {{ question.mainNumber }}-{{
  32. question.subNumber
  33. }}
  34. </div>
  35. <div class="tw-text-center tw-font-medium tw-text-2xl">
  36. {{ question.score || 0 }}
  37. </div>
  38. </div>
  39. </template>
  40. </div>
  41. <div class="tw-flex tw-gap-1 tw-flex-wrap tw-mt-5">
  42. <div
  43. v-for="(s, i) in questionScoreSteps"
  44. :key="i"
  45. @click="chooseScore(s)"
  46. class="single-score"
  47. :class="isCurrentScore(s) && 'current-score'"
  48. >
  49. {{ s }}
  50. </div>
  51. </div>
  52. <div class="tw-flex tw-justify-between tw-mt-4">
  53. <qm-button
  54. type="primary"
  55. shape="round"
  56. size="large"
  57. @click="clearLatestMarkOfCurrentQuetion"
  58. >
  59. 回退
  60. </qm-button>
  61. <qm-button
  62. type="primary"
  63. shape="round"
  64. size="large"
  65. @click="clearAllMarksOfCurrentQuetion"
  66. >
  67. 清除本题
  68. </qm-button>
  69. </div>
  70. </div>
  71. </template>
  72. <script lang="ts">
  73. import { Question } from "@/types";
  74. import { isNumber } from "lodash";
  75. import { computed, defineComponent, onMounted, onUnmounted, watch } from "vue";
  76. import { store } from "./store";
  77. import { autoChooseFirstQuestion } from "./use/autoChooseFirstQuestion";
  78. import { message } from "ant-design-vue";
  79. export default defineComponent({
  80. name: "MarkBoardTrack",
  81. emits: ["submit"],
  82. setup(props, { emit }) {
  83. const { chooseQuestion } = autoChooseFirstQuestion();
  84. const questionScoreSteps = computed(() => {
  85. const question = store.currentQuestion;
  86. if (!question) return [];
  87. const remainScore =
  88. Math.round(question.maxScore * 100 - (question.score || 0) * 100) / 100;
  89. const steps = [];
  90. for (
  91. let i = 0;
  92. i <= remainScore;
  93. i = Math.round(i * 100 + question.intervalScore * 100) / 100
  94. ) {
  95. steps.push(i);
  96. }
  97. if (
  98. Math.round(remainScore * 100) %
  99. Math.round(question.intervalScore * 100) !==
  100. 0
  101. ) {
  102. steps.push(remainScore);
  103. }
  104. return steps;
  105. });
  106. function isCurrentQuestion(question: Question) {
  107. return (
  108. store.currentQuestion?.mainNumber === question.mainNumber &&
  109. store.currentQuestion?.subNumber === question.subNumber
  110. );
  111. }
  112. watch(
  113. () => store.currentQuestion,
  114. () => {
  115. store.currentScore = undefined;
  116. }
  117. );
  118. function isCurrentScore(score: number) {
  119. return store.currentScore === score;
  120. }
  121. function chooseScore(score: number) {
  122. store.currentScore = score;
  123. }
  124. let keyPressTimestamp = 0;
  125. let keys: string[] = [];
  126. function numberKeyListener(event: KeyboardEvent) {
  127. // console.log(event);
  128. if (!store.currentQuestion) return;
  129. function indexOfCurrentQuestion() {
  130. return store.currentTask?.questionList.findIndex(
  131. (q) =>
  132. q.mainNumber === store.currentQuestion?.mainNumber &&
  133. q.subNumber === store.currentQuestion.subNumber
  134. );
  135. }
  136. // tab 循环答题列表
  137. if (event.key === "Tab") {
  138. const idx = indexOfCurrentQuestion() as number;
  139. if (idx >= 0 && store.currentTask) {
  140. const len = store.currentTask.questionList.length;
  141. chooseQuestion(store.currentTask.questionList[(idx + 1) % len]);
  142. event.preventDefault();
  143. }
  144. return;
  145. }
  146. if (event.timeStamp - keyPressTimestamp > 1.5 * 1000) {
  147. keys = [];
  148. }
  149. keyPressTimestamp = event.timeStamp;
  150. keys.push(event.key);
  151. if (isNaN(parseFloat(keys.join("")))) {
  152. keys = [];
  153. }
  154. if (event.key === "Escape") {
  155. keys = [];
  156. }
  157. const score = parseFloat(keys.join(""));
  158. if (isNumber(score) && questionScoreSteps.value.includes(score)) {
  159. chooseScore(score);
  160. }
  161. }
  162. onMounted(() => {
  163. document.addEventListener("keydown", numberKeyListener);
  164. });
  165. onUnmounted(() => {
  166. document.removeEventListener("keydown", numberKeyListener);
  167. });
  168. function clearLatestMarkOfCurrentQuetion() {
  169. if (!store.currentMarkResult || !store.currentQuestion) return;
  170. const ts = store.currentMarkResult?.trackList.filter(
  171. (q) =>
  172. q.mainNumber === store.currentQuestion?.mainNumber &&
  173. q.subNumber === store.currentQuestion?.subNumber
  174. );
  175. if (ts.length === 0) return;
  176. const maxNumber = Math.max(...ts.map((q) => q.number));
  177. const idx = store.currentMarkResult.trackList.findIndex(
  178. (q) =>
  179. q.mainNumber === store.currentQuestion?.mainNumber &&
  180. q.subNumber === store.currentQuestion?.subNumber &&
  181. q.number === maxNumber
  182. );
  183. store.removeScoreTracks = store.currentMarkResult.trackList.splice(
  184. idx,
  185. 1
  186. );
  187. }
  188. function clearAllMarksOfCurrentQuetion() {
  189. if (!store.currentMarkResult || !store.currentQuestion) return;
  190. store.removeScoreTracks = store.currentMarkResult?.trackList.filter(
  191. (q) =>
  192. q.mainNumber === store.currentQuestion?.mainNumber &&
  193. q.subNumber === store.currentQuestion?.subNumber
  194. );
  195. store.currentMarkResult.trackList = store.currentMarkResult?.trackList.filter(
  196. (q) =>
  197. !(
  198. q.mainNumber === store.currentQuestion?.mainNumber &&
  199. q.subNumber === store.currentQuestion?.subNumber
  200. )
  201. );
  202. }
  203. function submit() {
  204. const errors: any = [];
  205. store.currentTask?.questionList.forEach((question, index) => {
  206. if (!isNumber(question.score)) {
  207. errors.push({ question, index, error: "没有赋分不能提交" });
  208. }
  209. });
  210. if (errors.length === 0) {
  211. emit("submit");
  212. } else {
  213. console.log(errors);
  214. message.error({
  215. content: errors
  216. .map((e: any) => `${e.index + 1}、${e.error}`)
  217. .join("\n"),
  218. duration: 10,
  219. });
  220. }
  221. }
  222. return {
  223. store,
  224. isCurrentQuestion,
  225. chooseQuestion,
  226. isCurrentScore,
  227. chooseScore,
  228. questionScoreSteps,
  229. clearLatestMarkOfCurrentQuetion,
  230. clearAllMarksOfCurrentQuetion,
  231. submit,
  232. };
  233. },
  234. });
  235. </script>
  236. <style scoped>
  237. .mark-board-track-container {
  238. max-width: 250px;
  239. min-width: 250px;
  240. border-left: 1px solid grey;
  241. padding-left: 6px;
  242. padding-right: 6px;
  243. max-height: calc(100vh - 41px);
  244. overflow: scroll;
  245. }
  246. .question {
  247. min-width: 100px;
  248. border: 1px solid grey;
  249. }
  250. .current-question {
  251. border: 1px solid yellowgreen;
  252. background-color: lightblue;
  253. }
  254. .single-score {
  255. width: 30px;
  256. height: 30px;
  257. display: grid;
  258. place-content: center;
  259. border: 1px solid black;
  260. border-radius: 5px;
  261. }
  262. .current-score {
  263. border: 1px solid yellowgreen;
  264. background-color: lightblue;
  265. }
  266. </style>