12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- 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<DataCheckOmrFieldEditParams, "field" | "value">;
- interface UpdateSheetData {
- paperIndex: number;
- paperId?: number;
- pageIndex: number;
- uri: string;
- }
- interface UpdateSliceData extends UpdateSheetData {
- index: number;
- }
- 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<DataCheckState>) {
- 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.paperIndex,
- pageIndex: this.curPage.pagePageIndex,
- ...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;
- },
- },
- persist: {
- storage: sessionStorage,
- },
- });
|