import { defineStore } from "pinia"; import { StudentPage } from "@/views/DataCheck/types"; import { ImageType } from "@/constants/enumerate"; import { DataCheckListItem, DataCheckOmrFieldEditParams, } from "@/ap/types/dataCheck"; import { dataCheckOmrFieldEdit } from "@/ap/dataCheck"; interface DataCheckState { imageType: ImageType; curPage: StudentPage | null; curPageIndex: number; curStudent: DataCheckListItem | null; } type UpdateFieldParams = Pick; interface UpdateSheetData { paperIndex: number; paperId?: number; pageIndex: number; uri: string; } interface UpdateSliceData extends UpdateSheetData { index: number; } interface UpdatePaperType { paperIndex: number; pageIndex: number; paperType: string; } export const useDataCheckStore = defineStore("dataCheck", { state: (): DataCheckState => ({ imageType: "ORIGIN", curPage: null, curPageIndex: -1, curStudent: null, }), getters: { dataInfo(state: DataCheckState): DataCheckState { return { ...state }; }, }, actions: { setInfo(partial: Partial) { this.$patch(partial); }, resetInfo() { this.$reset(); }, async updateField(data: UpdateFieldParams) { if (!this.curPage || !this.curStudent) return; const params = { examId: this.curPage.examId, examNumber: this.curStudent.examNumber, paperNumber: this.curPage.paperNumber, pageIndex: this.curPage.pageIndex + 1, subjectCode: this.curStudent.subjectCode, ...data, }; await dataCheckOmrFieldEdit(params).catch(() => {}); }, modifySliceUri(data: UpdateSliceData) { if (!this.curStudent) return; const { uri, pageIndex, index, paperIndex } = data; this.curStudent.papers[paperIndex].pages[pageIndex].sliceUri[index] = uri; }, modifySheetUri(data: UpdateSheetData) { if (!this.curStudent) return; const { uri, pageIndex, paperIndex } = data; this.curStudent.papers[paperIndex].pages[pageIndex].sheetUri = uri; }, modifyPaperType(data: UpdatePaperType) { if (!this.curStudent) return; const { paperType, pageIndex, paperIndex } = data; this.curStudent.paperType = paperType; this.curStudent.papers[paperIndex].pages[pageIndex].paperType.result = paperType; }, }, persist: { storage: sessionStorage, }, });