MarkBoardMouse.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <template>
  2. <div
  3. v-if="store.currentTask"
  4. style="
  5. max-width: 250px;
  6. min-width: 250px;
  7. border: 1px solid grey;
  8. padding-left: 6px;
  9. padding-right: 6px;
  10. "
  11. >
  12. <div>
  13. <h1 class="text-3xl text-center" @click="toggleKeyMouse">鼠标给分</h1>
  14. </div>
  15. <div>
  16. <h1 class="text-3xl text-center">
  17. 总分:{{ store.currentMarkResult?.markerScore || 0 }}
  18. </h1>
  19. </div>
  20. <div>
  21. <div class="text-2xl text-center" @click="submit">提交</div>
  22. </div>
  23. <div v-if="store.currentTask && store.currentTask.questionList">
  24. <template
  25. v-for="(question, index) in store.currentTask?.questionList"
  26. :key="index"
  27. >
  28. <div class="question rounded p-1 mb-2">
  29. <div>
  30. <div>
  31. {{ question.title }} {{ question.mainNumber }}-{{
  32. question.subNumber
  33. }}
  34. </div>
  35. <div class="flex flex-wrap gap-1">
  36. <div
  37. v-for="(s, i) in question.maxScore + 1"
  38. :key="i"
  39. @click="chooseScore(question, s - 1)"
  40. class="single-score"
  41. :class="isCurrentScore(question, s - 1) && 'current-score'"
  42. >
  43. {{ s - 1 }}
  44. </div>
  45. </div>
  46. </div>
  47. </div>
  48. </template>
  49. </div>
  50. </div>
  51. </template>
  52. <script lang="ts">
  53. import { Question } from "@/types";
  54. import { isNumber } from "lodash";
  55. import { defineComponent, watch } from "vue";
  56. import { findCurrentTaskMarkResult, store } from "./store";
  57. export default defineComponent({
  58. name: "MarkBoardMouse",
  59. emits: ["submit"],
  60. setup(props, { emit }) {
  61. function toggleKeyMouse() {
  62. if (store.setting.uiSetting["normal.mode"] === "keyboard") {
  63. store.setting.uiSetting["normal.mode"] = "mouse";
  64. } else {
  65. store.setting.uiSetting["normal.mode"] = "keyboard";
  66. }
  67. }
  68. const markResult = findCurrentTaskMarkResult();
  69. watch(
  70. () => store.currentTask,
  71. () => {
  72. store.currentQuestion = undefined;
  73. store.currentScore = undefined;
  74. }
  75. );
  76. function chooseScore(question: Question, score: number) {
  77. store.currentQuestion = question;
  78. store.currentQuestion.score = score;
  79. }
  80. function isCurrentScore(question: Question, score: number) {
  81. return question.score === score;
  82. }
  83. function submit() {
  84. const errors: any = [];
  85. store.currentTask?.questionList.forEach((question, index) => {
  86. if (!isNumber(question.score)) {
  87. errors.push({ question, index, error: "没有赋分不能提交" });
  88. }
  89. });
  90. if (errors.length === 0) {
  91. emit("submit");
  92. } else {
  93. console.log(errors);
  94. }
  95. }
  96. return {
  97. store,
  98. toggleKeyMouse,
  99. markResult,
  100. chooseScore,
  101. isCurrentScore,
  102. submit,
  103. };
  104. },
  105. });
  106. </script>
  107. <style scoped>
  108. .question {
  109. min-width: 80px;
  110. border: 1px solid grey;
  111. }
  112. .current-question {
  113. border: 1px solid yellowgreen;
  114. background-color: lightblue;
  115. }
  116. .single-score {
  117. width: 30px;
  118. height: 30px;
  119. display: grid;
  120. place-content: center;
  121. border: 1px solid black;
  122. border-radius: 5px;
  123. }
  124. .current-score {
  125. border: 1px solid yellowgreen;
  126. background-color: lightblue;
  127. }
  128. </style>