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

fix:模拟考试,交卷修改

上级 566dc4b0
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
<div class="txt">{{ currentItem.sign ? '已标记' : '标记' }}</div> <div class="txt">{{ currentItem.sign ? '已标记' : '标记' }}</div>
</div> </div>
<div class="end-exam-btn"> <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> </div>
</div> </div>
...@@ -59,7 +59,6 @@ export default { ...@@ -59,7 +59,6 @@ export default {
disabled: false, disabled: false,
hasResult: false, hasResult: false,
index: 0, // 当前题的下标 index: 0, // 当前题的下标
cacheAnswerTime: null, // 缓存题计时器
countDownTime: null, // 倒计时计时器 countDownTime: null, // 倒计时计时器
duration: 0, // 答题所用时间 duration: 0, // 答题所用时间
examTimeText: '', examTimeText: '',
...@@ -86,14 +85,9 @@ export default { ...@@ -86,14 +85,9 @@ export default {
} }
}, },
beforeDestroy() { beforeDestroy() {
clearInterval(this.cacheAnswerTime) // 停止缓存
clearInterval(this.countDownTime) // 停止倒计时 clearInterval(this.countDownTime) // 停止倒计时
}, },
mounted() { mounted() {
// 缓存答题
this.cacheAnswerTime = setInterval(() => {
this.submitExam(0)
}, 3000)
// 答题倒计时 // 答题倒计时
this.countDown(this.data.remaining_times) this.countDown(this.data.remaining_times)
this.duration = this.data.duration || 0 this.duration = this.data.duration || 0
...@@ -160,32 +154,9 @@ export default { ...@@ -160,32 +154,9 @@ export default {
item.sign ? (item.sign = false) : (item.sign = true) item.sign ? (item.sign = false) : (item.sign = true)
this.$forceUpdate() this.$forceUpdate()
}, },
// 提交、缓存考试 isCache:0缓存,1提交 // 提交考试
submitExam(isCache = 1) { submitExam() {
const id = this.data.id this.$emit('submitExam')
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'
})
}
})
}, },
// 组装试题数据 // 组装试题数据
genQuestions(data) { genQuestions(data) {
......
<template> <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> </template>
<script> <script>
import * as api from '@/api/exam.js' import * as api from '@/api/exam.js'
...@@ -8,7 +8,9 @@ export default { ...@@ -8,7 +8,9 @@ export default {
components: { ExamCard }, components: { ExamCard },
data() { data() {
return { return {
data: {} data: {
cacheAnswerTime: null // 缓存题计时器
}
} }
}, },
computed: { computed: {
...@@ -17,9 +19,16 @@ export default { ...@@ -17,9 +19,16 @@ export default {
} }
}, },
created() { created() {
// 缓存答题
this.cacheAnswerTime = setInterval(() => {
this.submitExam(0)
}, 3000)
// 获取考卷 // 获取考卷
this.getTopic() this.getTopic()
}, },
beforeDestroy() {
clearInterval(this.cacheAnswerTime) // 停止缓存
},
methods: { methods: {
// 获取考卷 // 获取考卷
getTopic() { getTopic() {
...@@ -33,6 +42,34 @@ export default { ...@@ -33,6 +42,34 @@ export default {
api.getExamQuestion(param).then(response => { api.getExamQuestion(param).then(response => {
this.data = JSON.parse(response.data).sheet 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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论