Browse Source

方向键选择上下题

Michael Wang 4 năm trước cách đây
mục cha
commit
65c8ac9c64
1 tập tin đã thay đổi với 20 bổ sung5 xóa
  1. 20 5
      src/components/mark/MarkBoardKeyBoard.vue

+ 20 - 5
src/components/mark/MarkBoardKeyBoard.vue

@@ -104,17 +104,20 @@ export default defineComponent({
       // console.log(event);
       if (!store.currentQuestion || !store.currentTask) return;
 
+      function indexOfCurrentQuestion() {
+        return store.currentTask?.questionList.findIndex(
+          (q) =>
+            q.mainNumber === store.currentQuestion?.mainNumber &&
+            q.subNumber === store.currentQuestion.subNumber
+        );
+      }
       // 处理Enter跳下一题或submit
       if (event.key === "Enter") {
         if (!isNumber(store.currentQuestion.score)) {
           // 当前题赋分不通过,Enter无效
           return;
         }
-        const idx = store.currentTask?.questionList.findIndex(
-          (q) =>
-            q.mainNumber === store.currentQuestion?.mainNumber &&
-            q.subNumber === store.currentQuestion.subNumber
-        );
+        const idx = indexOfCurrentQuestion() as number;
         if (idx + 1 === store.currentTask?.questionList.length) {
           submit();
         } else {
@@ -123,6 +126,18 @@ export default defineComponent({
         keys = [];
         return;
       }
+      if (event.key === "ArrowLeft") {
+        const idx = indexOfCurrentQuestion() as number;
+        if (idx > 0) {
+          chooseQuestion(store.currentTask.questionList[idx - 1]);
+        }
+      }
+      if (event.key === "ArrowRight") {
+        const idx = indexOfCurrentQuestion() as number;
+        if (idx < store.currentTask.questionList.length - 1) {
+          chooseQuestion(store.currentTask.questionList[idx + 1]);
+        }
+      }
       // TODO: 确认数字按键的间隔
       if (event.timeStamp - keyPressTimestamp > 1.5 * 1000) {
         keys = [];