提交 ec343817 authored 作者: lihuihui's avatar lihuihui

fix:模拟考试,交卷修改

上级 566dc4b0
......@@ -33,7 +33,7 @@
<div class="txt">{{ currentItem.sign ? '已标记' : '标记' }}</div>
</div>
<div class="end-exam-btn">
<div class="btn" v-if="hasSubmitBtn" @click="submitExam()">交卷</div>
<div class="btn" v-if="hasSubmitBtn" @click="submitExam">交卷</div>
</div>
</div>
</div>
......@@ -59,7 +59,6 @@ export default {
disabled: false,
hasResult: false,
index: 0, // 当前题的下标
cacheAnswerTime: null, // 缓存题计时器
countDownTime: null, // 倒计时计时器
duration: 0, // 答题所用时间
examTimeText: '',
......@@ -86,14 +85,9 @@ export default {
}
},
beforeDestroy() {
clearInterval(this.cacheAnswerTime) // 停止缓存
clearInterval(this.countDownTime) // 停止倒计时
},
mounted() {
// 缓存答题
this.cacheAnswerTime = setInterval(() => {
this.submitExam(0)
}, 3000)
// 答题倒计时
this.countDown(this.data.remaining_times)
this.duration = this.data.duration || 0
......@@ -160,32 +154,9 @@ export default {
item.sign ? (item.sign = false) : (item.sign = true)
this.$forceUpdate()
},
// 提交、缓存考试 isCache:0缓存,1提交
submitExam(isCache = 1) {
const id = this.data.id
const answer = {}
this.questionList.forEach(item => {
if (!answer[item.question_item_id]) answer[item.question_item_id] = {}
item.question_list.forEach(cItem => {
answer[item.question_item_id][cItem.id] = {
sign: cItem.sign ? cItem.sign : false,
answer: cItem.user_answer
}
})
})
const param = {
sheet_id: id,
status: isCache, // 0缓存,1提交
answers: JSON.stringify(answer),
duration: this.duration
}
api.setCache(param).then(response => {
if (isCache) {
this.$router.replace({
path: '/testExam/result'
})
}
})
// 提交考试
submitExam() {
this.$emit('submitExam')
},
// 组装试题数据
genQuestions(data) {
......
<template>
<exam-card title="模拟考试" :data="data" v-if="Object.keys(data).length"></exam-card>
<exam-card @submitExam="submitExam" ref="exam" title="模拟考试" :data="data" v-if="Object.keys(data).length"></exam-card>
</template>
<script>
import * as api from '@/api/exam.js'
......@@ -8,7 +8,9 @@ export default {
components: { ExamCard },
data() {
return {
data: {}
data: {
cacheAnswerTime: null // 缓存题计时器
}
}
},
computed: {
......@@ -17,9 +19,16 @@ export default {
}
},
created() {
// 缓存答题
this.cacheAnswerTime = setInterval(() => {
this.submitExam(0)
}, 3000)
// 获取考卷
this.getTopic()
},
beforeDestroy() {
clearInterval(this.cacheAnswerTime) // 停止缓存
},
methods: {
// 获取考卷
getTopic() {
......@@ -33,6 +42,34 @@ export default {
api.getExamQuestion(param).then(response => {
this.data = JSON.parse(response.data).sheet
})
},
// 提交考卷 isCache:0缓存,1提交
submitExam(isCache = 1) {
const refData = this.$refs.exam
const id = this.data.id
const answer = {}
refData.questionList.forEach(item => {
if (!answer[item.question_item_id]) answer[item.question_item_id] = {}
item.question_list.forEach(cItem => {
answer[item.question_item_id][cItem.id] = {
sign: cItem.sign ? cItem.sign : false,
answer: cItem.user_answer
}
})
})
const param = {
sheet_id: id,
status: isCache, // 0缓存,1提交
answers: JSON.stringify(answer),
duration: refData.duration
}
api.setCache(param).then(response => {
if (isCache) {
this.$router.replace({
path: '/testExam/result'
})
}
})
}
}
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论