index.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import { defineStore } from "pinia";
  2. import { StudentPage } from "@/views/DataCheck/types";
  3. import { ImageType } from "@/constants/enumerate";
  4. import {
  5. DataCheckListItem,
  6. DataCheckOmrFieldEditParams,
  7. } from "@/ap/types/dataCheck";
  8. import { dataCheckOmrFieldEdit } from "@/ap/dataCheck";
  9. interface DataCheckState {
  10. imageType: ImageType;
  11. curPage: StudentPage | null;
  12. curPageIndex: number;
  13. curStudent: DataCheckListItem | null;
  14. }
  15. type UpdateFieldParams = Pick<DataCheckOmrFieldEditParams, "field" | "value">;
  16. interface UpdateSheetData {
  17. paperIndex: number;
  18. paperId?: number;
  19. pageIndex: number;
  20. uri: string;
  21. }
  22. interface UpdateSliceData extends UpdateSheetData {
  23. index: number;
  24. }
  25. interface UpdatePaperType {
  26. paperIndex: number;
  27. pageIndex: number;
  28. paperType: string;
  29. }
  30. export const useDataCheckStore = defineStore("dataCheck", {
  31. state: (): DataCheckState => ({
  32. imageType: "ORIGIN",
  33. curPage: null,
  34. curPageIndex: -1,
  35. curStudent: null,
  36. }),
  37. getters: {
  38. dataInfo(state: DataCheckState): DataCheckState {
  39. return { ...state };
  40. },
  41. },
  42. actions: {
  43. setInfo(partial: Partial<DataCheckState>) {
  44. this.$patch(partial);
  45. },
  46. resetInfo() {
  47. this.$reset();
  48. },
  49. async updateField(data: UpdateFieldParams) {
  50. if (!this.curPage || !this.curStudent) return;
  51. const params = {
  52. examId: this.curPage.examId,
  53. examNumber: this.curStudent.examNumber,
  54. paperNumber: this.curPage.paperNumber,
  55. pageIndex: this.curPage.pageIndex + 1,
  56. subjectCode: this.curStudent.subjectCode,
  57. ...data,
  58. };
  59. await dataCheckOmrFieldEdit(params).catch(() => {});
  60. },
  61. modifySliceUri(data: UpdateSliceData) {
  62. if (!this.curStudent) return;
  63. const { uri, pageIndex, index, paperIndex } = data;
  64. this.curStudent.papers[paperIndex].pages[pageIndex].sliceUri[index] = uri;
  65. },
  66. modifySheetUri(data: UpdateSheetData) {
  67. if (!this.curStudent) return;
  68. const { uri, pageIndex, paperIndex } = data;
  69. this.curStudent.papers[paperIndex].pages[pageIndex].sheetUri = uri;
  70. },
  71. modifyPaperType(data: UpdatePaperType) {
  72. if (!this.curStudent) return;
  73. const { paperType, pageIndex, paperIndex } = data;
  74. this.curStudent.paperType = paperType;
  75. this.curStudent.papers[paperIndex].pages[pageIndex].paperType.result =
  76. paperType;
  77. },
  78. },
  79. persist: {
  80. storage: sessionStorage,
  81. },
  82. });