Browse Source

fix bug keyboard bug

Michael Wang 4 years ago
parent
commit
22a99deab1
2 changed files with 24 additions and 12 deletions
  1. 14 6
      src/features/mark/MarkBoardKeyBoard.vue
  2. 10 6
      src/features/mark/use/keyboardAndMouse.ts

+ 14 - 6
src/features/mark/MarkBoardKeyBoard.vue

@@ -159,26 +159,34 @@ export default defineComponent({
         }
 
         if (scoreStr.value.length === 0) {
-          message.error({ content: "请输入分数", duration: 10 });
+          message.error({ content: "请输入分数", duration: 5 });
           console.log("请输入分数");
           return;
         }
+
+        // 0 分
+        // 整数分 (开始不为0)
+        // 小数分 (开始和结束不为0,结束必须为1-9
         if (
-          !(/^\d+$/.test(scoreStr.value) || /^\d+\.\d+$/.test(scoreStr.value))
+          !(
+            scoreStr.value === "0" ||
+            /^[1-9]\d*$/.test(scoreStr.value) ||
+            /^[1-9]\d*\.\d*[1-9]$/.test(scoreStr.value)
+          )
         ) {
-          message.error({ content: "分数格式不正确", duration: 10 });
+          message.error({ content: "分数格式不正确", duration: 5 });
           console.log("分数格式不正确");
           return;
         }
         const score = parseFloat(scoreStr.value);
         // console.log(score);
         if (!isNumber(score)) {
-          message.error({ content: "非数字输入", duration: 10 });
+          message.error({ content: "非数字输入", duration: 5 });
           console.log("非数字输入");
           return;
         }
         if (!questionScoreSteps.value.includes(score)) {
-          message.error({ content: "输入的分数不在有效间隔内", duration: 10 });
+          message.error({ content: "输入的分数不在有效间隔内", duration: 5 });
           return;
         }
         store.currentQuestion.score = score;
@@ -208,7 +216,7 @@ export default defineComponent({
       // 处理回退删除分数
       if (event.key === "Backspace") {
         if (scoreStr.value.length > 0) {
-          scoreStr.value = scoreStr.value.slice(0, scoreStr.value.length - 2);
+          scoreStr.value = scoreStr.value.slice(0, -1);
         } else {
           return;
         }

+ 10 - 6
src/features/mark/use/keyboardAndMouse.ts

@@ -1,4 +1,5 @@
 import { ModeEnum } from "@/types";
+import { isNumber } from "lodash";
 import { watch } from "vue";
 import { findCurrentTaskMarkResult, store } from "../store";
 
@@ -13,18 +14,21 @@ export function keyMouse() {
 
   // 普通模式更新分数时
   watch(
-    () => store.currentQuestion?.score,
+    () => store.currentQuestion,
     () => {
       if (store.setting.mode === ModeEnum.COMMON) {
         // TODO: findCurrentTaskMarkResult => store.currentMarkResult
         const markResult = findCurrentTaskMarkResult();
         if (markResult && store.currentTask) {
-          const scoreList = store.currentTask.questionList.map(
-            (q) => q.score || 0
-          );
-          markResult.scoreList = scoreList as number[];
+          const scoreList = store.currentTask.questionList.map((q) => q.score);
+          if (scoreList.every((s) => isNumber(s))) {
+            markResult.scoreList = scoreList as number[];
+          }
           markResult.markerScore =
-            scoreList.reduce((acc, v) => (acc += Math.round(v * 100)), 0) / 100;
+            (scoreList.filter((s) => isNumber(s)) as number[]).reduce(
+              (acc, v) => (acc += Math.round(v * 100)),
+              0
+            ) / 100;
         }
       }
     }