123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- import { StudentObjectiveInfo } from "@/types";
- import { studentObjectiveConfirmData } from "@/api/checkPage";
- import { message } from "ant-design-vue";
- import { onMounted } from "vue";
- import { useCheckObjectiveStore } from "@/store";
- export default function useStudent() {
- const checkObjectiveStore = useCheckObjectiveStore();
- const currentIndex = $computed(() =>
- checkObjectiveStore.studentIds.indexOf(checkObjectiveStore.currentStudentId)
- );
- const isFirst = $computed(() => currentIndex === 0);
- const isLast = $computed(
- () => currentIndex === checkObjectiveStore.studentIds.length - 1
- );
- const isMultiStudent = $computed(
- () => checkObjectiveStore.studentIds.length > 1
- );
- const totalScore = $computed(() => {
- if (!checkObjectiveStore.student) return 0;
- return checkObjectiveStore.student.objectiveScore || 0;
- });
- const curImageUrl = $computed(() =>
- checkObjectiveStore.student
- ? checkObjectiveStore.student.sheetUrls[checkObjectiveStore.currentImage]
- ?.url
- : ""
- );
- const answersComputed = $computed(() => {
- let mains = checkObjectiveStore.student?.answers.map((v) => ({
- mainTitle: "",
- mainNumber: v.mainNumber,
- subs: [v],
- }));
- const mSet = new Set();
- mains = mains?.filter((v) => {
- if (!mSet.has(v.mainNumber)) {
- mSet.add(v.mainNumber);
- v.subs = [];
- return true;
- }
- });
- mains?.forEach((v) => {
- v.mainTitle = checkObjectiveStore.student?.titles[v.mainNumber] ?? "";
- v.subs =
- checkObjectiveStore.student?.answers.filter(
- (v2) => v2.mainNumber === v.mainNumber
- ) ?? [];
- });
- return mains;
- });
- async function getNextStudent() {
- if (isLast) {
- void message.warning("已经是最后一份!");
- return;
- }
- await getStudent(checkObjectiveStore.studentIds[currentIndex + 1]);
- }
- async function getPreviousStudent() {
- if (isFirst) {
- void message.warning("已经是第一份!");
- return;
- }
- await getStudent(checkObjectiveStore.studentIds[currentIndex - 1]);
- }
- async function getStudent(studentId: string) {
- let dataError = false;
- const res = await studentObjectiveConfirmData(studentId).catch(() => {
- dataError = true;
- });
- if (dataError) {
- void message.error(res.message, 24 * 60 * 60);
- throw new Error("取学生信息出错: " + res.message);
- }
- checkObjectiveStore.student = res.data as StudentObjectiveInfo;
- checkObjectiveStore.currentStudentId = studentId;
- checkObjectiveStore.currentImage = 0;
- checkObjectiveStore.browsedImageIndexes = [0];
- checkObjectiveStore.answerMap = {};
- checkObjectiveStore.student?.answers.forEach((item) => {
- checkObjectiveStore.answerMap[`${item.mainNumber}_${item.subNumber}`] = {
- answer: item.answer,
- isRight: item.answer === item.standardAnswer,
- };
- });
- }
- async function updateCurStudent() {
- await getStudent(checkObjectiveStore.studentIds[currentIndex]);
- }
- onMounted(async () => {
- if (checkObjectiveStore.studentIds.length === 0) {
- void message.info("没有需要处理的考生,请返回。");
- return;
- }
- await getNextStudent();
- });
- return {
- currentIndex,
- isFirst,
- isLast,
- isMultiStudent,
- totalScore,
- curImageUrl,
- answersComputed,
- getNextStudent,
- getPreviousStudent,
- updateCurStudent,
- };
- }
|