|
@@ -29,15 +29,20 @@
|
|
}}
|
|
}}
|
|
</div>
|
|
</div>
|
|
<div class="tw-text-center tw-text-3xl">
|
|
<div class="tw-text-center tw-text-3xl">
|
|
- {{ question.score }}
|
|
|
|
|
|
+ <!-- {{ showScore(question) }} -->
|
|
|
|
+ {{ question.__updateScore }}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<div>
|
|
<div class="tw-text-center">
|
|
<div class="tw-text-center">
|
|
间隔{{ question.intervalScore }}分
|
|
间隔{{ question.intervalScore }}分
|
|
</div>
|
|
</div>
|
|
- <div class="tw-text-3xl">
|
|
|
|
- {{ question.minScore }} ~ {{ question.maxScore }}
|
|
|
|
|
|
+ <div class="tw-flex tw-text-3xl" style="width: 80px">
|
|
|
|
+ <span class="tw-flex-1">{{ question.minScore }}</span>
|
|
|
|
+ <span class="tw-flex-1">~</span>
|
|
|
|
+ <span class="tw-flex-1 tw-text-center">{{
|
|
|
|
+ question.maxScore
|
|
|
|
+ }}</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
@@ -50,7 +55,14 @@
|
|
<script lang="ts">
|
|
<script lang="ts">
|
|
import { Question } from "@/types";
|
|
import { Question } from "@/types";
|
|
import { isNumber } from "lodash";
|
|
import { isNumber } from "lodash";
|
|
-import { computed, defineComponent, onMounted, onUnmounted, watch } from "vue";
|
|
|
|
|
|
+import {
|
|
|
|
+ computed,
|
|
|
|
+ defineComponent,
|
|
|
|
+ onMounted,
|
|
|
|
+ onUnmounted,
|
|
|
|
+ reactive,
|
|
|
|
+ watch,
|
|
|
|
+} from "vue";
|
|
import { store } from "./store";
|
|
import { store } from "./store";
|
|
import { keyMouse } from "./use/keyboardAndMouse";
|
|
import { keyMouse } from "./use/keyboardAndMouse";
|
|
import { autoChooseFirstQuestion } from "./use/autoChooseFirstQuestion";
|
|
import { autoChooseFirstQuestion } from "./use/autoChooseFirstQuestion";
|
|
@@ -68,10 +80,14 @@ export default defineComponent({
|
|
|
|
|
|
const remainScore = question.maxScore - (question.score || 0);
|
|
const remainScore = question.maxScore - (question.score || 0);
|
|
const steps = [];
|
|
const steps = [];
|
|
- for (let i = 0; i <= remainScore; i += question.intervalScore) {
|
|
|
|
|
|
+ for (
|
|
|
|
+ let i = 0;
|
|
|
|
+ i <= remainScore;
|
|
|
|
+ i = (i * 10 + question.intervalScore * 10) / 10
|
|
|
|
+ ) {
|
|
steps.push(i);
|
|
steps.push(i);
|
|
}
|
|
}
|
|
- if (remainScore % question.intervalScore !== 0) {
|
|
|
|
|
|
+ if ((remainScore * 10) % (question.intervalScore * 10) !== 0) {
|
|
steps.push(remainScore);
|
|
steps.push(remainScore);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -86,7 +102,7 @@ export default defineComponent({
|
|
}
|
|
}
|
|
|
|
|
|
let keyPressTimestamp = 0;
|
|
let keyPressTimestamp = 0;
|
|
- let keys: string[] = [];
|
|
|
|
|
|
+ let keys = reactive([] as Array<String>);
|
|
function numberKeyListener(event: KeyboardEvent) {
|
|
function numberKeyListener(event: KeyboardEvent) {
|
|
// console.log(event);
|
|
// console.log(event);
|
|
if (!store.currentQuestion || !store.currentTask) return;
|
|
if (!store.currentQuestion || !store.currentTask) return;
|
|
@@ -100,10 +116,25 @@ export default defineComponent({
|
|
}
|
|
}
|
|
// 处理Enter跳下一题或submit
|
|
// 处理Enter跳下一题或submit
|
|
if (event.key === "Enter") {
|
|
if (event.key === "Enter") {
|
|
- if (!isNumber(store.currentQuestion.score)) {
|
|
|
|
- // 当前题赋分不通过,Enter无效
|
|
|
|
|
|
+ // if (!isNumber(store.currentQuestion.score)) {
|
|
|
|
+ // // 当前题赋分不通过,Enter无效
|
|
|
|
+ // return;
|
|
|
|
+ // }
|
|
|
|
+ // 有bug,移除当前题,再回来就出错了
|
|
|
|
+ if (keys.length === 0) {
|
|
|
|
+ console.log("请输入分数");
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
+ const score = parseFloat(keys.join(""));
|
|
|
|
+ if (!isNumber(score)) {
|
|
|
|
+ console.log("非数字输入");
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ if (!questionScoreSteps.value.includes(score)) {
|
|
|
|
+ console.log("输入的分数不在有效间隔内");
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ store.currentQuestion.score = score;
|
|
const idx = indexOfCurrentQuestion() as number;
|
|
const idx = indexOfCurrentQuestion() as number;
|
|
if (idx + 1 === store.currentTask?.questionList.length) {
|
|
if (idx + 1 === store.currentTask?.questionList.length) {
|
|
submit();
|
|
submit();
|
|
@@ -118,12 +149,16 @@ export default defineComponent({
|
|
if (idx > 0) {
|
|
if (idx > 0) {
|
|
chooseQuestion(store.currentTask.questionList[idx - 1]);
|
|
chooseQuestion(store.currentTask.questionList[idx - 1]);
|
|
}
|
|
}
|
|
|
|
+ keys = [];
|
|
|
|
+ return;
|
|
}
|
|
}
|
|
if (event.key === "ArrowRight") {
|
|
if (event.key === "ArrowRight") {
|
|
const idx = indexOfCurrentQuestion() as number;
|
|
const idx = indexOfCurrentQuestion() as number;
|
|
if (idx < store.currentTask.questionList.length - 1) {
|
|
if (idx < store.currentTask.questionList.length - 1) {
|
|
chooseQuestion(store.currentTask.questionList[idx + 1]);
|
|
chooseQuestion(store.currentTask.questionList[idx + 1]);
|
|
}
|
|
}
|
|
|
|
+ keys = [];
|
|
|
|
+ return;
|
|
}
|
|
}
|
|
// 处理回退删除分数
|
|
// 处理回退删除分数
|
|
if (event.key === "Backspace") {
|
|
if (event.key === "Backspace") {
|
|
@@ -138,10 +173,10 @@ export default defineComponent({
|
|
}
|
|
}
|
|
|
|
|
|
// TODO: 确认数字按键的间隔
|
|
// TODO: 确认数字按键的间隔
|
|
- if (event.timeStamp - keyPressTimestamp > 1.5 * 1000) {
|
|
|
|
- keys = [];
|
|
|
|
- }
|
|
|
|
- keyPressTimestamp = event.timeStamp;
|
|
|
|
|
|
+ // if (event.timeStamp - keyPressTimestamp > 1.5 * 1000) {
|
|
|
|
+ // keys = [];
|
|
|
|
+ // }
|
|
|
|
+ // keyPressTimestamp = event.timeStamp;
|
|
// 此时不再接受任何非数字键
|
|
// 此时不再接受任何非数字键
|
|
if (".0123456789".includes(event.key)) {
|
|
if (".0123456789".includes(event.key)) {
|
|
keys.push(event.key);
|
|
keys.push(event.key);
|
|
@@ -149,13 +184,13 @@ export default defineComponent({
|
|
if (isNaN(parseFloat(keys.join("")))) {
|
|
if (isNaN(parseFloat(keys.join("")))) {
|
|
keys = [];
|
|
keys = [];
|
|
}
|
|
}
|
|
- const score = parseFloat(keys.join(""));
|
|
|
|
- if (isNumber(score) && questionScoreSteps.value.includes(score)) {
|
|
|
|
- store.currentQuestion.score = score;
|
|
|
|
- }
|
|
|
|
- if (keys.length === 0) {
|
|
|
|
- store.currentQuestion.score = null;
|
|
|
|
- }
|
|
|
|
|
|
+ // FIXME: for update. 得想个更好的办法来解决不能更新的问题
|
|
|
|
+ store.currentQuestion.__updateScore = keys.join("");
|
|
|
|
+ // console.log(
|
|
|
|
+ // keys,
|
|
|
|
+ // keys.join(""),
|
|
|
|
+ // isCurrentQuestion(store.currentQuestion) && keys.length > 0
|
|
|
|
+ // );
|
|
}
|
|
}
|
|
onMounted(() => {
|
|
onMounted(() => {
|
|
document.addEventListener("keydown", numberKeyListener);
|
|
document.addEventListener("keydown", numberKeyListener);
|
|
@@ -164,6 +199,12 @@ export default defineComponent({
|
|
document.removeEventListener("keydown", numberKeyListener);
|
|
document.removeEventListener("keydown", numberKeyListener);
|
|
});
|
|
});
|
|
|
|
|
|
|
|
+ const showScore = (question: Question) => {
|
|
|
|
+ return isCurrentQuestion(question) && keys.length > 0
|
|
|
|
+ ? keys.join("")
|
|
|
|
+ : question.score;
|
|
|
|
+ };
|
|
|
|
+
|
|
function submit() {
|
|
function submit() {
|
|
const errors: any = [];
|
|
const errors: any = [];
|
|
store.currentTask?.questionList.forEach((question, index) => {
|
|
store.currentTask?.questionList.forEach((question, index) => {
|
|
@@ -183,6 +224,8 @@ export default defineComponent({
|
|
toggleKeyMouse,
|
|
toggleKeyMouse,
|
|
isCurrentQuestion,
|
|
isCurrentQuestion,
|
|
chooseQuestion,
|
|
chooseQuestion,
|
|
|
|
+ keys,
|
|
|
|
+ showScore,
|
|
questionScoreSteps,
|
|
questionScoreSteps,
|
|
submit,
|
|
submit,
|
|
};
|
|
};
|