提交 b2fb0077 authored 作者: 王鹏飞's avatar 王鹏飞

feat:课后练习增加答案缓存

上级 025be5bf
......@@ -7,6 +7,7 @@
:hasCountdown="false"
@submit="handleSubmit"
@back="handleBack"
ref="exam"
v-if="Object.keys(data).length"
></exam-card>
</template>
......@@ -19,13 +20,17 @@ export default {
return {
status: 1, // 考试状态
hasMark: true,
data: {}
data: {},
cacheAnswerTime: null
}
},
beforeMount() {
// 获取考卷
this.getTopic()
},
beforeDestroy() {
this.cacheAnswerTime && clearInterval(this.cacheAnswerTime) // 停止缓存
},
methods: {
// 获取考卷
getTopic() {
......@@ -41,9 +46,13 @@ export default {
this.data = JSON.parse(response.data).sheet
// 已提交
const isSubmited = ['1', '2'].includes(this.data.status)
// 缓存答题
if (isSubmited) {
this.status = 2
this.hasMark = false
} else {
clearInterval(this.cacheAnswerTime)
this.cacheAnswerTime = setInterval(this.handleCache, 3000)
}
})
},
......@@ -55,6 +64,7 @@ export default {
handleSubmit(data) {
const params = this.genSubmitData(data).params
const answerNum = this.genSubmitData(data).answerNum
params.status = 1
if (answerNum !== 0) {
this.$confirm(`您还有${answerNum}道题没有作答`, '请确认', {
confirmButtonText: '确认提交',
......@@ -70,13 +80,21 @@ export default {
}
},
submitApi(params) {
api.setCourseCache(Object.assign(params, { status: 1 })).then(res => {
this.cacheAnswerTime && clearInterval(this.cacheAnswerTime) // 停止缓存
api.setCourseCache(params).then(res => {
this.$router.replace({
path: '/course/chapter/result',
query: Object.assign({}, this.$route.query, { type: 2 })
})
})
},
// 缓存答案
handleCache() {
const refData = this.$refs.exam
const params = this.genSubmitData(refData.questionGroups).params
params.status = 0
api.setCourseCache(params)
},
// 组装提交数据
genSubmitData(questionGroups) {
const answers = {}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论