store.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import Vue from "vue";
  2. import Vuex from "vuex";
  3. Vue.use(Vuex);
  4. const examHomeModule = {
  5. namespaced: true,
  6. state: { faceCheckModalOpen: false },
  7. mutations: {
  8. toggleFaceCheckModal(state, open) {
  9. if (open === undefined) {
  10. state.faceCheckModalOpen = !state.faceCheckModalOpen;
  11. } else {
  12. state.faceCheckModalOpen = open;
  13. }
  14. }
  15. },
  16. actions: {},
  17. getters: {}
  18. };
  19. const examingHomeModule = {
  20. namespaced: true,
  21. state: {
  22. exam: null,
  23. paperStruct: null,
  24. examQuestionList: null,
  25. questionFilterType: "ALL",
  26. snapNow: false,
  27. snapProcessingCount: 0,
  28. shouldSubmitPaper: false
  29. },
  30. mutations: {
  31. toggleSnapNow(state) {
  32. state.snapNow = !state.snapNow;
  33. if (state.snapNow) {
  34. state.snapProcessingCount = state.snapProcessingCount + 1;
  35. }
  36. },
  37. decreaseSnapCount(state) {
  38. state.snapProcessingCount = state.snapProcessingCount - 1;
  39. },
  40. updateExamState(state, payload) {
  41. state = Object.assign(state, payload);
  42. },
  43. updateExamResult(state, payload) {
  44. state = Object.assign(state, { examResult: payload });
  45. },
  46. updateQuestionFilter(state, type) {
  47. state.questionFilterType = type;
  48. },
  49. updateExamQuestion(
  50. state,
  51. { order, studentAnswer, isSign, audioPlayTimes, getQuestionContent }
  52. ) {
  53. const examQuestionList = state.examQuestionList.map(eq => {
  54. // console.log(eq.order, order);
  55. if (eq.order == order) {
  56. return Object.assign(
  57. {},
  58. eq,
  59. getQuestionContent === undefined && { dirty: true }, // 仅设置getQuestionContent时,不更新dirty
  60. studentAnswer !== undefined && { studentAnswer },
  61. audioPlayTimes !== undefined && { audioPlayTimes },
  62. isSign !== undefined && { isSign },
  63. getQuestionContent !== undefined && { getQuestionContent }
  64. );
  65. }
  66. return eq;
  67. });
  68. state = Object.assign(state, { examQuestionList });
  69. },
  70. resetExamQuestionDirty(state) {
  71. const examQuestionList = state.examQuestionList.map(eq => {
  72. return Object.assign({}, eq, { dirty: false });
  73. });
  74. state = Object.assign(state, { examQuestionList });
  75. },
  76. setShouldSubmitPaper(state) {
  77. state.shouldSubmitPaper = !state.shouldSubmitPaper;
  78. }
  79. },
  80. actions: {},
  81. getters: {
  82. examShouldShowAnswer(state) {
  83. if (state.exam && state.exam.practiceType === "IN_PRACTICE") {
  84. return true;
  85. }
  86. return false;
  87. }
  88. }
  89. };
  90. const userStr = window.localStorage.getItem("user-for-reload");
  91. const initUser = userStr ? JSON.parse(userStr) : {};
  92. export default new Vuex.Store({
  93. state: {
  94. user: initUser
  95. },
  96. mutations: {
  97. updateUser(state, payload) {
  98. state = Object.assign(state, { user: payload });
  99. }
  100. },
  101. actions: {},
  102. modules: {
  103. examHomeModule,
  104. examingHomeModule
  105. }
  106. });