rt-sim-training-client/src/store/modules/exam.js

125 lines
3.7 KiB
JavaScript
Raw Normal View History

2020-04-01 13:47:29 +08:00
import store from '@/store/index_APP_TARGET';
2019-07-26 13:32:43 +08:00
const exam = {
2019-11-15 16:31:48 +08:00
namespaced: true,
2019-07-26 13:32:43 +08:00
2019-11-15 16:31:48 +08:00
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;
});
2019-07-26 13:32:43 +08:00
2019-11-15 16:31:48 +08:00
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);
}
}
2019-07-26 13:32:43 +08:00
};
2019-08-29 10:33:50 +08:00
export default exam;