瀏覽代碼

自动选择第一题

Michael Wang 4 年之前
父節點
當前提交
7b0d31b201

+ 1 - 0
src/components/inspect/store.ts

@@ -38,6 +38,7 @@ const obj = {
   historyOpen: false,
   MarkBoardTrackCollapse: false,
   historyTasks: [],
+  removeScoreTracks: [],
 } as MarkStore;
 
 export const store = reactive(obj);

+ 2 - 3
src/components/mark/MarkBoardKeyBoard.vue

@@ -53,12 +53,14 @@ import { isNumber } from "lodash";
 import { computed, defineComponent, onMounted, onUnmounted, watch } from "vue";
 import { store } from "./store";
 import { keyMouse } from "./use/keyboardAndMouse";
+import { autoChooseFirstQuestion } from "./use/autoChooseFirstQuestion";
 
 export default defineComponent({
   name: "MarkBoardKeyBoard",
   emits: ["submit"],
   setup(props, { emit }) {
     const { toggleKeyMouse } = keyMouse();
+    const { chooseQuestion } = autoChooseFirstQuestion();
 
     const questionScoreSteps = computed(() => {
       const question = store.currentQuestion;
@@ -95,9 +97,6 @@ export default defineComponent({
         store.currentScore = undefined;
       }
     );
-    function chooseQuestion(question: Question) {
-      store.currentQuestion = question;
-    }
 
     let keyPressTimestamp = 0;
     let keys: string[] = [];

+ 5 - 3
src/components/mark/MarkBoardTrack.vue

@@ -62,11 +62,14 @@ import { Question } from "@/types";
 import { isNumber } from "lodash";
 import { computed, defineComponent, onMounted, onUnmounted, watch } from "vue";
 import { store } from "./store";
+import { autoChooseFirstQuestion } from "./use/autoChooseFirstQuestion";
 
 export default defineComponent({
   name: "MarkBoardTrack",
   emits: ["submit"],
   setup(props, { emit }) {
+    const { chooseQuestion } = autoChooseFirstQuestion();
+
     const questionScoreSteps = computed(() => {
       const question = store.currentQuestion;
       if (!question) return [];
@@ -95,9 +98,7 @@ export default defineComponent({
         store.currentScore = undefined;
       }
     );
-    function chooseQuestion(question: Question) {
-      store.currentQuestion = question;
-    }
+
     function isCurrentScore(score: number) {
       return store.currentScore === score;
     }
@@ -126,6 +127,7 @@ export default defineComponent({
         chooseScore(score);
       }
     }
+
     onMounted(() => {
       document.addEventListener("keydown", numberKeyListener);
     });

+ 20 - 0
src/components/mark/use/autoChooseFirstQuestion.ts

@@ -0,0 +1,20 @@
+import { Question } from "@/types";
+import { store } from "../store";
+import { watch } from "vue";
+
+export function chooseQuestion(question: Question) {
+  store.currentQuestion = question;
+}
+
+/** chooseQuestion 当currentTask改变是,自动选择第一题 */
+export function autoChooseFirstQuestion() {
+  watch(
+    () => store.currentTask,
+    () => {
+      const firstQuetion = store.currentTask?.questionList[0];
+      firstQuetion && chooseQuestion(firstQuetion);
+    }
+  );
+
+  return { chooseQuestion };
+}