index.ts 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. export const useDataCheckStore = defineStore("dataCheck", {
  26. state: (): DataCheckState => ({
  27. imageType: "ORIGIN",
  28. curPage: null,
  29. curPageIndex: -1,
  30. curStudent: null,
  31. }),
  32. getters: {
  33. dataInfo(state: DataCheckState): DataCheckState {
  34. return { ...state };
  35. },
  36. },
  37. actions: {
  38. setInfo(partial: Partial<DataCheckState>) {
  39. this.$patch(partial);
  40. },
  41. resetInfo() {
  42. this.$reset();
  43. },
  44. async updateField(data: UpdateFieldParams) {
  45. if (!this.curPage || !this.curStudent) return;
  46. const params = {
  47. examId: this.curPage.examId,
  48. examNumber: this.curStudent.examNumber,
  49. paperNumber: this.curPage.paperIndex,
  50. pageIndex: this.curPage.pagePageIndex,
  51. ...data,
  52. };
  53. await dataCheckOmrFieldEdit(params).catch(() => {});
  54. },
  55. modifySliceUri(data: UpdateSliceData) {
  56. if (!this.curStudent) return;
  57. const { uri, pageIndex, index, paperIndex } = data;
  58. this.curStudent.papers[paperIndex].pages[pageIndex].sliceUri[index] = uri;
  59. },
  60. modifySheetUri(data: UpdateSheetData) {
  61. if (!this.curStudent) return;
  62. const { uri, pageIndex, paperIndex } = data;
  63. this.curStudent.papers[paperIndex].pages[pageIndex].sheetUri = uri;
  64. },
  65. },
  66. persist: {
  67. storage: sessionStorage,
  68. },
  69. });