rt-sim-training-client/src/store/modules/exam.js
2019-11-15 16:31:48 +08:00

125 lines
3.6 KiB
JavaScript

import store from '@/store';
const exam = {
namespaced: true,
state: {
deviceCode: '', // 考试目标code
started: false, // 考试状态
usedTime: 0, // 考试当前所用时间
totalTime: 0, // 考试总时间
timeInterval: null, // 计时器
suspend: false, // 暂停
ruleList: [], // 考试规则列表
courseDetail: {}, // 课程详情
courseList: [] // 课程列表
},
getters: {
started: (state) => {
return state.started;
},
usedTime: (state) => {
return state.usedTime;
},
totalTime: (state) => {
return state.totalTime;
},
suspend: (state) => {
return state.suspend;
}
},
mutations: {
setStarted: (state, started) => {
state.started = started;
},
setSuspend: (state, suspend) => {
state.suspend = suspend;
},
setUsedTime: (state, usedTime) => {
state.usedTime = usedTime;
},
setTotalTime: (state, totalTime) => {
state.totalTime = totalTime;
},
countUsedTime: (state) => {
if (state.timeInterval) {
clearInterval(state.timeInterval);
state.timeInterval = null;
}
state.timeInterval = setInterval(() => {
if (!state.suspend) {
state.usedTime++;
}
}, 1000);
},
stopCountTime: (state) => {
if (state.timeInterval) {
clearInterval(state.timeInterval);
state.timeInterval = null;
}
},
setRuleList: (state, ruleList) => {
state.ruleList = ruleList;
},
setCourseDetail: (state, courseDetail) => {
state.courseDetail = courseDetail;
},
setCourse: (state, courseList) => {
state.courseList = courseList;
},
setCenter: (state, deviceCode) => {
state.deviceCode = deviceCode;
}
},
actions: {
start({ commit }) {
commit('setStarted', true);
commit('setSuspend', false);
commit('setUsedTime', 0);
commit('countUsedTime');
},
over({ commit }) {
commit('setStarted', false);
commit('setSuspend', true);
commit('setUsedTime', 0);
commit('stopCountTime');
},
isOver() {
const trainingList = store.getters['trainingList/trainingList'];
const doList = trainingList.filter(elem => {
if (elem.usedTime !== undefined) return true;
});
if (doList.length >= trainingList.length) {
return true;
}
},
setSuspend({ commit }, suspend) {
commit('setSuspend', suspend);
},
setUsedTime({ commit }, usedTime) {
commit('setUsedTime', usedTime || 0);
},
setTotalTime({ commit }, totalTime) {
commit('setTotalTime', totalTime || 0);
},
countUsedTime({ commit }) {
commit('countUsedTime');
},
setRuleList({ commit }, ruleList) {
commit('setRuleList', ruleList);
},
setCourseDetail({ commit }, courseDetail) {
commit('setCourseDetail', courseDetail);
},
setCourse({ commit }, course) {
commit('setCourse', course);
},
setCenter({ commit }, deviceCode) {
commit('setCenter', deviceCode);
}
}
};
export default exam;