Administrator
2021-08-27 bb0d6a910c2145f5936bb89dbd2fce41d3d1933b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import { start } from '@/api/exam/examRecord'
import { setStore, getStore } from '@/util/store'
import { submit } from '@/api/exam/answer'
 
const exam = {
  state: {
    exam: getStore({
      name: 'exam'
    }) || {},
    examRecord: getStore({
      name: 'examRecord'
    }) || {},
    subject: getStore({
      name: 'subject'
    }) || {},
    incorrectRecord: getStore({
      name: 'incorrectRecord'
    }) || {},
    examUserData: {},
  },
  actions: {
 
    // 设置题目信息
    SetSubjectInfo({ commit, state }, subject) {
      commit('SET_SUBJECT', subject)
    },
    // 开始考试
    StartExam({ commit, state }, examRecord) {
      return new Promise((resolve, reject) => {
        start(examRecord).then(response => {
          commit('SET_EXAM', response.data.data.examination)
          commit('SET_EXAM_RECORD', response.data.data.examRecord)
          commit('SET_SUBJECT', response.data.data.subjectDto)
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    // 提交考试
    SubmitExam({ commit, state }, exam) {
      return new Promise((resolve, reject) => {
        submit(exam).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    // 当前错题记录
    SetIncorrectRecord({ commit, state }, incorrectRecord) {
      commit('SET_INCORRECT_RECORD', incorrectRecord)
    }
  },
  mutations: {
    SetexamUserData(state, data) {
      state.examUserData = data;
    },
    SET_EXAM: (state, exam) => {
      state.exam = exam
      setStore({
        name: 'exam',
        content: state.exam
      })
    },
    SET_EXAM_RECORD: (state, examRecord) => {
      state.examRecord = examRecord
      setStore({
        name: 'examRecord',
        content: state.examRecord
      })
    },
    SET_SUBJECT: (state, subject) => {
      state.subject = subject
      setStore({
        name: 'subject',
        content: state.subject
      })
    },
    SET_INCORRECT_RECORD: (state, incorrectRecord) => {
      state.incorrectRecord = incorrectRecord
      setStore({
        name: 'incorrectRecord',
        content: state.incorrectRecord
      })
    }
  }
}
 
export default exam