store.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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. remainTime: null,
  28. snapProcessingCount: 0,
  29. shouldSubmitPaper: false,
  30. allAudioPlayTimes: [],
  31. questionQrCode: null,
  32. questionQrCodeScanned: null,
  33. questionAudioFileUrl: [],
  34. },
  35. mutations: {
  36. updateRemainTime(state, remainTime) {
  37. state = Object.assign(state, { remainTime });
  38. },
  39. toggleSnapNow(state) {
  40. state.snapNow = !state.snapNow;
  41. if (state.snapNow) {
  42. state.snapProcessingCount = state.snapProcessingCount + 1;
  43. }
  44. },
  45. decreaseSnapCount(state) {
  46. state.snapProcessingCount = state.snapProcessingCount - 1;
  47. },
  48. updateExamState(state, payload) {
  49. state = Object.assign(state, payload);
  50. },
  51. updateExamResult(state, payload) {
  52. state = Object.assign(state, { examResult: payload });
  53. },
  54. updateQuestionFilter(state, type) {
  55. window._hmt.push(["_trackEvent", "正在考试页面", "筛选问题"]);
  56. state.questionFilterType = type;
  57. },
  58. updateQuestionAudioPlayTimes(state, payload) {
  59. // const cAudio = state.allAudioPlayTimes.find(
  60. // audio => audio.name === payload
  61. // ) || { name: payload, times: 1 };
  62. // console.log(cAudio);
  63. // console.log(
  64. // state.allAudioPlayTimes.find(audio => audio.name === payload)
  65. // );
  66. let alreayHas = false;
  67. let allAudioPlayTimes = state.allAudioPlayTimes.map(audio => {
  68. if (audio.name === payload) {
  69. alreayHas = true;
  70. const times = audio.times + 1;
  71. return { name: payload, times: times };
  72. }
  73. return audio;
  74. });
  75. // console.log(allAudioPlayTimes);
  76. if (!alreayHas) {
  77. // let o = {};
  78. // o.name = payload;
  79. // o.times = 1;
  80. allAudioPlayTimes.push({ name: payload, times: 1 });
  81. // allAudioPlayTimes.push(o);
  82. }
  83. // console.log(allAudioPlayTimes);
  84. const examQuestionList = state.examQuestionList.map(eq => {
  85. // console.log(eq.order, order);
  86. if (eq.order == 1) {
  87. return Object.assign(
  88. {},
  89. eq,
  90. { dirty: true },
  91. { getQuestionContent: true }, // 第一题总是获取
  92. { audioPlayTimes: JSON.stringify(allAudioPlayTimes) }
  93. );
  94. }
  95. return eq;
  96. });
  97. state = Object.assign(state, { allAudioPlayTimes, examQuestionList });
  98. },
  99. updateExamQuestion(
  100. state,
  101. { order, studentAnswer, isSign, audioPlayTimes, getQuestionContent }
  102. ) {
  103. const examQuestionList = state.examQuestionList.map(eq => {
  104. // console.log(eq.order, order);
  105. if (eq.order == order) {
  106. return Object.assign(
  107. {},
  108. eq,
  109. getQuestionContent === undefined && { dirty: true }, // 仅设置getQuestionContent时,不更新dirty
  110. studentAnswer !== undefined && { studentAnswer },
  111. audioPlayTimes !== undefined && { audioPlayTimes },
  112. isSign !== undefined && { isSign },
  113. getQuestionContent !== undefined && { getQuestionContent }
  114. );
  115. }
  116. return eq;
  117. });
  118. // if (audioPlayTimes) {
  119. // const cq = state.examQuestionList[order - 1];
  120. // examQuestionList = examQuestionList.map(eq => {
  121. // if (cq.questionId == eq.questionId) {
  122. // // 保存套题的音频播放次数
  123. // return Object.assign(
  124. // {},
  125. // eq,
  126. // { dirty: true },
  127. // audioPlayTimes !== undefined && { audioPlayTimes }
  128. // );
  129. // }
  130. // return eq;
  131. // });
  132. // }
  133. state = Object.assign(state, { examQuestionList });
  134. },
  135. resetExamQuestionDirty(state) {
  136. const examQuestionList = state.examQuestionList.map(eq => {
  137. return Object.assign({}, eq, { dirty: false });
  138. });
  139. state = Object.assign(state, { examQuestionList });
  140. },
  141. setShouldSubmitPaper(state) {
  142. state.shouldSubmitPaper = !state.shouldSubmitPaper;
  143. },
  144. setQuestionQrCode(state, payload) {
  145. state.questionQrCode = payload;
  146. },
  147. setQuestionQrCodeScanned(state, payload) {
  148. state.questionQrCodeScanned = payload;
  149. },
  150. setQuestionAudioFileUrl(state, payload) {
  151. state.questionAudioFileUrl = state.questionAudioFileUrl.filter(
  152. v => !v.saved
  153. );
  154. let ary = state.questionAudioFileUrl;
  155. let found = false;
  156. for (const i of ary) {
  157. if (i.order === payload.order) {
  158. i.audioFileUrl = payload.audioFileUrl;
  159. found = true;
  160. break;
  161. }
  162. }
  163. if (found) {
  164. state.questionAudioFileUrl = [...ary];
  165. } else {
  166. state.questionAudioFileUrl.push(payload);
  167. }
  168. },
  169. },
  170. actions: {},
  171. getters: {
  172. examShouldShowAnswer(state) {
  173. if (state.exam && state.exam.practiceType === "IN_PRACTICE") {
  174. return true;
  175. }
  176. return false;
  177. },
  178. },
  179. };
  180. const userStr = window.localStorage.getItem("user-for-reload");
  181. const initUser = userStr ? JSON.parse(userStr) : {};
  182. export default new Vuex.Store({
  183. state: {
  184. user: initUser,
  185. timeDifference: 0,
  186. },
  187. mutations: {
  188. updateUser(state, payload) {
  189. state = Object.assign(state, { user: payload });
  190. },
  191. updateTimeDifference(state, payload) {
  192. state = Object.assign(state, { timeDifference: payload });
  193. },
  194. },
  195. actions: {},
  196. modules: {
  197. examHomeModule,
  198. examingHomeModule,
  199. },
  200. });