12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- import { useDataCheckStore, useAppStore } from "@/store";
- import { StudentPage, TaskItem } from "./types";
- export default function useTask() {
- const dataCheckStore = useDataCheckStore();
- function updatePageTasks(curPage: StudentPage) {
- if (!curPage || !dataCheckStore.curStudent) {
- dataCheckStore.setInfo({
- taskList: [],
- curTask: null,
- });
- return;
- }
- const taskList = [] as TaskItem[];
- const examNumber = dataCheckStore.curStudent.examNumber;
- if (!checkExamNumber(examNumber)) {
- taskList.push({
- id: `examNumber_${curPage.studentId}`,
- type: "examNumber",
- questionIndex: 0,
- paperIndex: 0,
- pageIndex: 0,
- studentId: curPage.studentId,
- finished: false,
- });
- }
- curPage.question?.result.map((item, index) => {
- if (checkQuestionError(item)) {
- taskList.push({
- id: `question_${curPage.studentId}_${curPage.paperIndex}_${curPage.pageIndex}_${index}`,
- type: "question",
- questionIndex: index,
- paperIndex: curPage.paperIndex,
- pageIndex: curPage.pageIndex,
- studentId: curPage.studentId,
- finished: false,
- });
- }
- });
- dataCheckStore.setInfo({
- taskList,
- curTask: taskList[0],
- });
- if (taskList.length === 0) {
- dataCheckStore.curStudent.checked = true;
- }
- }
- function updateNextUnfinishTask() {
- const task = dataCheckStore.taskList.find((item) => !item.finished);
- dataCheckStore.curTask = task || null;
- }
- function taskFinisheHandle() {
- const curTask = dataCheckStore.curTask;
- if (!curTask) {
- return;
- }
- curTask.finished = true;
- updateNextUnfinishTask();
- }
- function checkExamNumber(examNumber: string) {
- if (!examNumber) return false;
- return /^\d{15}$/.test(examNumber);
- }
- function checkQuestionError(cont: string) {
- if (!cont || cont.length > 1 || cont.includes("#")) return true;
- return false;
- }
- function checkPageFinished(questions: string[], examNumber: string) {
- if (!questions.length || !examNumber) return false;
- const examNumberFinished = checkExamNumber(examNumber);
- if (!examNumberFinished) return false;
- const questionFinished = !questions.some((item) =>
- checkQuestionError(item)
- );
- return questionFinished;
- }
- return {
- updatePageTasks,
- updateNextUnfinishTask,
- taskFinisheHandle,
- checkExamNumber,
- checkQuestionError,
- checkPageFinished,
- };
- }
|