store.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. import Vue from "vue";
  2. import Vuex from "vuex";
  3. import { EPCC_DOMAIN } from "@/constants/constants";
  4. Vue.use(Vuex);
  5. const examHomeModule = {
  6. namespaced: true,
  7. state: { faceCheckModalOpen: false },
  8. mutations: {
  9. toggleFaceCheckModal(state, open) {
  10. if (open === undefined) {
  11. state.faceCheckModalOpen = !state.faceCheckModalOpen;
  12. } else {
  13. state.faceCheckModalOpen = open;
  14. }
  15. },
  16. },
  17. actions: {},
  18. getters: {},
  19. };
  20. const examingHomeModule = {
  21. namespaced: true,
  22. state: {
  23. exam: null,
  24. paperStruct: null,
  25. examQuestionList: null,
  26. questionFilterType: "ALL",
  27. snapNow: false,
  28. remainTime: null,
  29. snapProcessingCount: 0,
  30. shouldSubmitPaper: false,
  31. allAudioPlayTimes: [],
  32. questionQrCode: null,
  33. questionQrCodeScanned: null,
  34. questionAnswerFileUrl: [],
  35. pictureAnswer: {},
  36. uploadModalVisible: false,
  37. isDoingFaceLiveness: false,
  38. },
  39. mutations: {
  40. updateRemainTime(state, remainTime) {
  41. state = Object.assign(state, { remainTime });
  42. },
  43. toggleSnapNow(state) {
  44. // FIXME: 这里对多次调用不够严谨,比如,下次调用时本意是要抓拍,但别处的watch不知道是否已经执行。最好改成event的形式。
  45. state.snapNow = !state.snapNow;
  46. if (state.snapNow) {
  47. state.snapProcessingCount = state.snapProcessingCount + 1;
  48. }
  49. },
  50. decreaseSnapCount(state) {
  51. state.snapProcessingCount = state.snapProcessingCount - 1;
  52. },
  53. updateExamState(state, payload) {
  54. state = Object.assign(state, payload);
  55. },
  56. updateExamResult(state, payload) {
  57. state = Object.assign(state, { examResult: payload });
  58. },
  59. updateQuestionFilter(state, type) {
  60. window._hmt.push(["_trackEvent", "正在考试页面", "筛选问题"]);
  61. state.questionFilterType = type;
  62. },
  63. updateQuestionAudioPlayTimes(state, payload) {
  64. // const cAudio = state.allAudioPlayTimes.find(
  65. // audio => audio.name === payload
  66. // ) || { name: payload, times: 1 };
  67. // console.log(cAudio);
  68. // console.log(
  69. // state.allAudioPlayTimes.find(audio => audio.name === payload)
  70. // );
  71. let alreayHas = false;
  72. let allAudioPlayTimes = state.allAudioPlayTimes.map(audio => {
  73. if (audio.name === payload) {
  74. alreayHas = true;
  75. const times = audio.times + 1;
  76. return { name: payload, times: times };
  77. }
  78. return audio;
  79. });
  80. // console.log(allAudioPlayTimes);
  81. if (!alreayHas) {
  82. // let o = {};
  83. // o.name = payload;
  84. // o.times = 1;
  85. allAudioPlayTimes.push({ name: payload, times: 1 });
  86. // allAudioPlayTimes.push(o);
  87. }
  88. // console.log(allAudioPlayTimes);
  89. const examQuestionList = state.examQuestionList.map(eq => {
  90. // console.log(eq.order, order);
  91. if (eq.order == 1) {
  92. return Object.assign(
  93. {},
  94. eq,
  95. { dirty: true },
  96. { getQuestionContent: true }, // 第一题总是获取
  97. { audioPlayTimes: JSON.stringify(allAudioPlayTimes) }
  98. );
  99. }
  100. return eq;
  101. });
  102. state = Object.assign(state, { allAudioPlayTimes, examQuestionList });
  103. },
  104. updateExamQuestion(
  105. state,
  106. { order, studentAnswer, isSign, audioPlayTimes, getQuestionContent }
  107. ) {
  108. const examQuestionList = state.examQuestionList.map(eq => {
  109. // console.log(eq.order, order);
  110. if (eq.order == order) {
  111. return Object.assign(
  112. {},
  113. eq,
  114. getQuestionContent === undefined && { dirty: true }, // 仅设置getQuestionContent时,不更新dirty
  115. studentAnswer !== undefined && { studentAnswer },
  116. audioPlayTimes !== undefined && { audioPlayTimes },
  117. isSign !== undefined && { isSign },
  118. getQuestionContent !== undefined && { getQuestionContent }
  119. );
  120. }
  121. return eq;
  122. });
  123. // if (audioPlayTimes) {
  124. // const cq = state.examQuestionList[order - 1];
  125. // examQuestionList = examQuestionList.map(eq => {
  126. // if (cq.questionId == eq.questionId) {
  127. // // 保存套题的音频播放次数
  128. // return Object.assign(
  129. // {},
  130. // eq,
  131. // { dirty: true },
  132. // audioPlayTimes !== undefined && { audioPlayTimes }
  133. // );
  134. // }
  135. // return eq;
  136. // });
  137. // }
  138. state = Object.assign(state, { examQuestionList });
  139. },
  140. resetExamQuestionDirty(state) {
  141. const examQuestionList = state.examQuestionList.map(eq => {
  142. return Object.assign({}, eq, { dirty: false });
  143. });
  144. state = Object.assign(state, { examQuestionList });
  145. },
  146. setShouldSubmitPaper(state) {
  147. state.shouldSubmitPaper = !state.shouldSubmitPaper;
  148. },
  149. setQuestionQrCode(state, payload) {
  150. state.questionQrCode = payload;
  151. },
  152. setQuestionQrCodeScanned(state, payload) {
  153. state.questionQrCodeScanned = payload;
  154. },
  155. setQuestionFileAnswerUrl(state, payload) {
  156. // 先清理之前保存过的记录
  157. state.questionAnswerFileUrl = state.questionAnswerFileUrl.filter(
  158. v => !v.saved
  159. );
  160. let ary = state.questionAnswerFileUrl;
  161. let found = false;
  162. for (const i of ary) {
  163. if (i.order === payload.order) {
  164. // 同一道题可能更新
  165. i.fileUrl = payload.fileUrl;
  166. found = true;
  167. break;
  168. }
  169. }
  170. if (found) {
  171. state.questionAnswerFileUrl = [...ary];
  172. } else {
  173. state.questionAnswerFileUrl.push(payload);
  174. }
  175. },
  176. updatePicture(state, payload) {
  177. state.pictureAnswer = payload;
  178. },
  179. updateUploadModalVisible(state, payload) {
  180. state.uploadModalVisible = payload;
  181. },
  182. updateIsDoingFaceLiveness(state, payload) {
  183. state.isDoingFaceLiveness = payload;
  184. },
  185. },
  186. actions: {},
  187. getters: {
  188. examShouldShowAnswer(state) {
  189. if (state.exam && state.exam.practiceType === "IN_PRACTICE") {
  190. return true;
  191. }
  192. return false;
  193. },
  194. },
  195. };
  196. const userStr = window.localStorage.getItem("user-for-reload");
  197. const initUser = userStr ? JSON.parse(userStr) : {};
  198. export default new Vuex.Store({
  199. state: {
  200. user: initUser,
  201. timeDifference: 0,
  202. siteMessages: [],
  203. siteMessagesTimeStamp: Date.now(),
  204. QECSConfig: {},
  205. },
  206. mutations: {
  207. updateUser(state, payload) {
  208. state = Object.assign(state, { user: payload });
  209. },
  210. updateTimeDifference(state, payload) {
  211. state = Object.assign(state, { timeDifference: payload });
  212. },
  213. updateSiteMessages(state, payload) {
  214. state = Object.assign(state, { siteMessages: payload });
  215. },
  216. updateSiteMessagesTimeStamp(state, payload) {
  217. state = Object.assign(state, { siteMessagesTimeStamp: payload });
  218. },
  219. updateQECSConfig(state, payload) {
  220. state = Object.assign(state, { QECSConfig: payload });
  221. },
  222. },
  223. actions: {},
  224. modules: {
  225. examHomeModule,
  226. examingHomeModule,
  227. },
  228. getters: {
  229. isEpcc(state) {
  230. return state.user.schoolDomain === EPCC_DOMAIN;
  231. },
  232. },
  233. });