|
@@ -60,7 +60,8 @@
|
|
|
|
|
|
<script lang="ts">
|
|
<script lang="ts">
|
|
import { Question } from "@/types";
|
|
import { Question } from "@/types";
|
|
-import { computed, defineComponent, watch } from "vue";
|
|
|
|
|
|
+import { isNumber } from "lodash";
|
|
|
|
+import { computed, defineComponent, onMounted, onUnmounted, watch } from "vue";
|
|
import { findCurrentTaskMarkResult, store } from "./store";
|
|
import { findCurrentTaskMarkResult, store } from "./store";
|
|
|
|
|
|
export default defineComponent({
|
|
export default defineComponent({
|
|
@@ -117,6 +118,34 @@ export default defineComponent({
|
|
store.currentScore = score;
|
|
store.currentScore = score;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ let keyPressTimestamp = 0;
|
|
|
|
+ let keys: string[] = [];
|
|
|
|
+ function numberKeyListener(event: KeyboardEvent) {
|
|
|
|
+ // console.log(event);
|
|
|
|
+ if (!store.currentQuestion) return;
|
|
|
|
+ if (event.timeStamp - keyPressTimestamp > 1.5 * 1000) {
|
|
|
|
+ keys = [];
|
|
|
|
+ }
|
|
|
|
+ keyPressTimestamp = event.timeStamp;
|
|
|
|
+ keys.push(event.key);
|
|
|
|
+ if (isNaN(parseFloat(keys.join("")))) {
|
|
|
|
+ keys = [];
|
|
|
|
+ }
|
|
|
|
+ if (event.key === "Escape") {
|
|
|
|
+ keys = [];
|
|
|
|
+ }
|
|
|
|
+ const score = parseFloat(keys.join(""));
|
|
|
|
+ if (isNumber(score) && questionScoreSteps.value.includes(score)) {
|
|
|
|
+ chooseScore(score);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ onMounted(() => {
|
|
|
|
+ document.addEventListener("keydown", numberKeyListener);
|
|
|
|
+ });
|
|
|
|
+ onUnmounted(() => {
|
|
|
|
+ document.removeEventListener("keydown", numberKeyListener);
|
|
|
|
+ });
|
|
|
|
+
|
|
function submit() {
|
|
function submit() {
|
|
emit("submit");
|
|
emit("submit");
|
|
}
|
|
}
|