123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294 |
- <template>
- <div
- v-if="store.currentTask"
- :style="{ display: store.MarkBoardTrackCollapse ? 'none' : 'block' }"
- class="mark-board-track-container"
- >
- <div>
- <h1 class="tw-text-3xl tw-text-center">
- 总分:{{ store.currentMarkResult?.markerScore || 0 }}
- </h1>
- </div>
- <div class="tw-mb-2 tw-flex tw-place-content-center">
- <qm-button type="primary" shape="round" size="large" @click="submit">
- 提交
- </qm-button>
- </div>
- <div
- v-if="store.currentTask && store.currentTask.questionList"
- class="tw-flex tw-gap-1 tw-flex-wrap tw-justify-between"
- >
- <template
- v-for="(question, index) in store.currentTask?.questionList"
- :key="index"
- >
- <div
- @click="chooseQuestion(question)"
- class="question tw-rounded tw-p-1"
- :class="isCurrentQuestion(question) && 'current-question'"
- >
- <div style="border-bottom: 1px solid grey">
- {{ question.title }} {{ question.mainNumber }}-{{
- question.subNumber
- }}
- </div>
- <div class="tw-text-center tw-font-medium tw-text-2xl">
- <!-- 特殊的空格符号 -->
- {{ question.score ?? " " }}
- </div>
- </div>
- </template>
- </div>
- <div class="tw-flex tw-gap-1 tw-flex-wrap tw-mt-5">
- <div
- v-for="(s, i) in questionScoreSteps"
- :key="i"
- @click="chooseScore(s)"
- class="single-score"
- :class="isCurrentScore(s) && 'current-score'"
- >
- {{ s }}
- </div>
- </div>
- <div class="tw-flex tw-justify-between tw-mt-4">
- <qm-button
- type="primary"
- shape="round"
- size="large"
- :clickTimeout="300"
- @click="clearLatestMarkOfCurrentQuetion"
- >
- 回退
- </qm-button>
- <qm-button
- type="primary"
- shape="round"
- size="large"
- :clickTimeout="300"
- @click="clearAllMarksOfCurrentQuetion"
- >
- 清除本题
- </qm-button>
- </div>
- </div>
- </template>
- <script lang="ts">
- import { Question } from "@/types";
- import { isNumber } from "lodash";
- import { computed, defineComponent, onMounted, onUnmounted, watch } from "vue";
- import { store } from "./store";
- import { autoChooseFirstQuestion } from "./use/autoChooseFirstQuestion";
- import { message } from "ant-design-vue";
- export default defineComponent({
- name: "MarkBoardTrack",
- emits: ["submit"],
- setup(props, { emit }) {
- const { chooseQuestion } = autoChooseFirstQuestion();
- const questionScoreSteps = computed(() => {
- const question = store.currentQuestion;
- if (!question) return [];
- const remainScore =
- Math.round(question.maxScore * 100 - (question.score || 0) * 100) / 100;
- const steps = [];
- for (
- let i = 0;
- i <= remainScore;
- i = Math.round(i * 100 + question.intervalScore * 100) / 100
- ) {
- steps.push(i);
- }
- if (
- Math.round(remainScore * 100) %
- Math.round(question.intervalScore * 100) !==
- 0
- ) {
- steps.push(remainScore);
- }
- return steps;
- });
- function isCurrentQuestion(question: Question) {
- return (
- store.currentQuestion?.mainNumber === question.mainNumber &&
- store.currentQuestion?.subNumber === question.subNumber
- );
- }
- watch(
- () => store.currentQuestion,
- () => {
- store.currentScore = undefined;
- }
- );
- function isCurrentScore(score: number) {
- return store.currentScore === score;
- }
- function chooseScore(score: number) {
- store.currentScore = score;
- }
- let keyPressTimestamp = 0;
- let keys: string[] = [];
- function numberKeyListener(event: KeyboardEvent) {
- // console.log(event);
- if (!store.currentQuestion) return;
- function indexOfCurrentQuestion() {
- return store.currentTask?.questionList.findIndex(
- (q) =>
- q.mainNumber === store.currentQuestion?.mainNumber &&
- q.subNumber === store.currentQuestion.subNumber
- );
- }
- // tab 循环答题列表
- if (event.key === "Tab") {
- const idx = indexOfCurrentQuestion() as number;
- if (idx >= 0 && store.currentTask) {
- const len = store.currentTask.questionList.length;
- chooseQuestion(store.currentTask.questionList[(idx + 1) % len]);
- event.preventDefault();
- }
- return;
- }
- if (event.timeStamp - keyPressTimestamp > 1 * 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 clearLatestMarkOfCurrentQuetion() {
- if (!store.currentMarkResult || !store.currentQuestion) return;
- const ts = store.currentMarkResult?.trackList.filter(
- (q) =>
- q.mainNumber === store.currentQuestion?.mainNumber &&
- q.subNumber === store.currentQuestion?.subNumber
- );
- if (ts.length === 0) return;
- const maxNumber = Math.max(...ts.map((q) => q.number));
- const idx = store.currentMarkResult.trackList.findIndex(
- (q) =>
- q.mainNumber === store.currentQuestion?.mainNumber &&
- q.subNumber === store.currentQuestion?.subNumber &&
- q.number === maxNumber
- );
- store.removeScoreTracks = store.currentMarkResult.trackList.splice(
- idx,
- 1
- );
- }
- function clearAllMarksOfCurrentQuetion() {
- if (!store.currentMarkResult || !store.currentQuestion) return;
- store.removeScoreTracks = store.currentMarkResult?.trackList.filter(
- (q) =>
- q.mainNumber === store.currentQuestion?.mainNumber &&
- q.subNumber === store.currentQuestion?.subNumber
- );
- store.currentMarkResult.trackList = store.currentMarkResult?.trackList.filter(
- (q) =>
- !(
- q.mainNumber === store.currentQuestion?.mainNumber &&
- q.subNumber === store.currentQuestion?.subNumber
- )
- );
- }
- function submit() {
- const errors: any = [];
- store.currentTask?.questionList.forEach((question, index) => {
- if (!isNumber(question.score)) {
- errors.push({
- question,
- index,
- error: `${question.mainNumber}-${question.subNumber} 没有赋分不能提交。`,
- });
- }
- });
- if (errors.length === 0) {
- emit("submit");
- } else {
- console.log(errors);
- message.error({
- content: errors.map((e: any) => `${e.error}`).join("\n"),
- duration: 10,
- });
- }
- }
- return {
- store,
- isCurrentQuestion,
- chooseQuestion,
- isCurrentScore,
- chooseScore,
- questionScoreSteps,
- clearLatestMarkOfCurrentQuetion,
- clearAllMarksOfCurrentQuetion,
- submit,
- };
- },
- });
- </script>
- <style scoped>
- .mark-board-track-container {
- max-width: 250px;
- min-width: 250px;
- border-left: 1px solid grey;
- padding-left: 6px;
- padding-right: 6px;
- max-height: calc(100vh - 41px);
- overflow: scroll;
- }
- .question {
- min-width: 100px;
- border: 1px solid grey;
- }
- .current-question {
- border: 1px solid yellowgreen;
- background-color: lightblue;
- }
- .single-score {
- width: 30px;
- height: 30px;
- display: grid;
- place-content: center;
- border: 1px solid black;
- border-radius: 5px;
- }
- .current-score {
- border: 1px solid yellowgreen;
- background-color: lightblue;
- }
- </style>
|