123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 |
- import Vue from "vue";
- import Vuex from "vuex";
- Vue.use(Vuex);
- const examHomeModule = {
- namespaced: true,
- state: { faceCheckModalOpen: false },
- mutations: {
- toggleFaceCheckModal(state, open) {
- if (open === undefined) {
- state.faceCheckModalOpen = !state.faceCheckModalOpen;
- } else {
- state.faceCheckModalOpen = open;
- }
- },
- },
- actions: {},
- getters: {},
- };
- const examingHomeModule = {
- namespaced: true,
- state: {
- exam: null,
- paperStruct: null,
- examQuestionList: null,
- questionFilterType: "ALL",
- snapNow: false,
- remainTime: null,
- snapProcessingCount: 0,
- shouldSubmitPaper: false,
- allAudioPlayTimes: [],
- questionQrCode: null,
- questionQrCodeScanned: null,
- questionAudioFileUrl: [],
- },
- mutations: {
- updateRemainTime(state, remainTime) {
- state = Object.assign(state, { remainTime });
- },
- toggleSnapNow(state) {
- state.snapNow = !state.snapNow;
- if (state.snapNow) {
- state.snapProcessingCount = state.snapProcessingCount + 1;
- }
- },
- decreaseSnapCount(state) {
- state.snapProcessingCount = state.snapProcessingCount - 1;
- },
- updateExamState(state, payload) {
- state = Object.assign(state, payload);
- },
- updateExamResult(state, payload) {
- state = Object.assign(state, { examResult: payload });
- },
- updateQuestionFilter(state, type) {
- window._hmt.push(["_trackEvent", "正在考试页面", "筛选问题"]);
- state.questionFilterType = type;
- },
- updateQuestionAudioPlayTimes(state, payload) {
- // const cAudio = state.allAudioPlayTimes.find(
- // audio => audio.name === payload
- // ) || { name: payload, times: 1 };
- // console.log(cAudio);
- // console.log(
- // state.allAudioPlayTimes.find(audio => audio.name === payload)
- // );
- let alreayHas = false;
- let allAudioPlayTimes = state.allAudioPlayTimes.map(audio => {
- if (audio.name === payload) {
- alreayHas = true;
- const times = audio.times + 1;
- return { name: payload, times: times };
- }
- return audio;
- });
- // console.log(allAudioPlayTimes);
- if (!alreayHas) {
- // let o = {};
- // o.name = payload;
- // o.times = 1;
- allAudioPlayTimes.push({ name: payload, times: 1 });
- // allAudioPlayTimes.push(o);
- }
- // console.log(allAudioPlayTimes);
- const examQuestionList = state.examQuestionList.map(eq => {
- // console.log(eq.order, order);
- if (eq.order == 1) {
- return Object.assign(
- {},
- eq,
- { dirty: true },
- { getQuestionContent: true }, // 第一题总是获取
- { audioPlayTimes: JSON.stringify(allAudioPlayTimes) }
- );
- }
- return eq;
- });
- state = Object.assign(state, { allAudioPlayTimes, examQuestionList });
- },
- updateExamQuestion(
- state,
- { order, studentAnswer, isSign, audioPlayTimes, getQuestionContent }
- ) {
- const examQuestionList = state.examQuestionList.map(eq => {
- // console.log(eq.order, order);
- if (eq.order == order) {
- return Object.assign(
- {},
- eq,
- getQuestionContent === undefined && { dirty: true }, // 仅设置getQuestionContent时,不更新dirty
- studentAnswer !== undefined && { studentAnswer },
- audioPlayTimes !== undefined && { audioPlayTimes },
- isSign !== undefined && { isSign },
- getQuestionContent !== undefined && { getQuestionContent }
- );
- }
- return eq;
- });
- // if (audioPlayTimes) {
- // const cq = state.examQuestionList[order - 1];
- // examQuestionList = examQuestionList.map(eq => {
- // if (cq.questionId == eq.questionId) {
- // // 保存套题的音频播放次数
- // return Object.assign(
- // {},
- // eq,
- // { dirty: true },
- // audioPlayTimes !== undefined && { audioPlayTimes }
- // );
- // }
- // return eq;
- // });
- // }
- state = Object.assign(state, { examQuestionList });
- },
- resetExamQuestionDirty(state) {
- const examQuestionList = state.examQuestionList.map(eq => {
- return Object.assign({}, eq, { dirty: false });
- });
- state = Object.assign(state, { examQuestionList });
- },
- setShouldSubmitPaper(state) {
- state.shouldSubmitPaper = !state.shouldSubmitPaper;
- },
- setQuestionQrCode(state, payload) {
- state.questionQrCode = payload;
- },
- setQuestionQrCodeScanned(state, payload) {
- state.questionQrCodeScanned = payload;
- },
- setQuestionAudioFileUrl(state, payload) {
- state.questionAudioFileUrl = state.questionAudioFileUrl.filter(
- v => !v.saved
- );
- let ary = state.questionAudioFileUrl;
- let found = false;
- for (const i of ary) {
- if (i.order === payload.order) {
- i.audioFileUrl = payload.audioFileUrl;
- found = true;
- break;
- }
- }
- if (found) {
- state.questionAudioFileUrl = [...ary];
- } else {
- state.questionAudioFileUrl.push(payload);
- }
- },
- },
- actions: {},
- getters: {
- examShouldShowAnswer(state) {
- if (state.exam && state.exam.practiceType === "IN_PRACTICE") {
- return true;
- }
- return false;
- },
- },
- };
- const userStr = window.localStorage.getItem("user-for-reload");
- const initUser = userStr ? JSON.parse(userStr) : {};
- export default new Vuex.Store({
- state: {
- user: initUser,
- timeDifference: 0,
- },
- mutations: {
- updateUser(state, payload) {
- state = Object.assign(state, { user: payload });
- },
- updateTimeDifference(state, payload) {
- state = Object.assign(state, { timeDifference: payload });
- },
- },
- actions: {},
- modules: {
- examHomeModule,
- examingHomeModule,
- },
- });
|