Przeglądaj źródła

Backspace键删除分数

Michael Wang 4 lat temu
rodzic
commit
d6f35e1cca
1 zmienionych plików z 19 dodań i 4 usunięć
  1. 19 4
      src/components/mark/MarkBoardKeyBoard.vue

+ 19 - 4
src/components/mark/MarkBoardKeyBoard.vue

@@ -125,22 +125,37 @@ export default defineComponent({
           chooseQuestion(store.currentTask.questionList[idx + 1]);
           chooseQuestion(store.currentTask.questionList[idx + 1]);
         }
         }
       }
       }
+      // 处理回退删除分数
+      if (event.key === "Backspace") {
+        if (keys.length > 0) {
+          keys.splice(keys.length - 1, 1);
+        } else {
+          return;
+        }
+      }
+      if (event.key === "Escape") {
+        keys = [];
+      }
+
       // TODO: 确认数字按键的间隔
       // TODO: 确认数字按键的间隔
       if (event.timeStamp - keyPressTimestamp > 1.5 * 1000) {
       if (event.timeStamp - keyPressTimestamp > 1.5 * 1000) {
         keys = [];
         keys = [];
       }
       }
       keyPressTimestamp = event.timeStamp;
       keyPressTimestamp = event.timeStamp;
-      keys.push(event.key);
-      if (isNaN(parseFloat(keys.join("")))) {
-        keys = [];
+      // 此时不再接受任何非数字键
+      if (".0123456789".includes(event.key)) {
+        keys.push(event.key);
       }
       }
-      if (event.key === "Escape") {
+      if (isNaN(parseFloat(keys.join("")))) {
         keys = [];
         keys = [];
       }
       }
       const score = parseFloat(keys.join(""));
       const score = parseFloat(keys.join(""));
       if (isNumber(score) && questionScoreSteps.value.includes(score)) {
       if (isNumber(score) && questionScoreSteps.value.includes(score)) {
         store.currentQuestion.score = score;
         store.currentQuestion.score = score;
       }
       }
+      if (keys.length === 0) {
+        store.currentQuestion.score = null;
+      }
     }
     }
     onMounted(() => {
     onMounted(() => {
       document.addEventListener("keydown", numberKeyListener);
       document.addEventListener("keydown", numberKeyListener);