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

updates

上级 cf194517
......@@ -2,8 +2,9 @@
<exam-card
title="课后练习"
:data="data"
@submitExam="handleSubmit"
:hasCountDown="false"
:hasCountdown="false"
@submit="handleSubmit"
@back="handleBack"
v-if="Object.keys(data).length"
></exam-card>
</template>
......@@ -36,10 +37,9 @@ export default {
this.data = JSON.parse(response.data).sheet
})
},
// 缓存答案
handleCache(data) {
const params = this.genSubmitData(data)
api.setCourseCache(Object.assign(params, { status: 0 }))
// 返回
handleBack() {
this.$router.push(`/course/learn/${this.$route.query.course_id}`)
},
// 提交答案
handleSubmit(data) {
......@@ -52,26 +52,20 @@ export default {
})
},
// 组装提交数据
genSubmitData(questionList) {
genSubmitData(questionGroups) {
const answers = {}
questionList.forEach(item => {
if (!answers[item.question_item_id]) {
answers[item.question_item_id] = {}
questionGroups.forEach(group => {
if (!answers[group.question_item_id]) {
answers[group.question_item_id] = {}
}
item.question_list.forEach(cItem => {
answers[item.question_item_id][cItem.id] = {
sign: cItem.sign ? cItem.sign : false,
answers: cItem.user_answer
group.question_list.forEach(item => {
answers[item.question_item_id][item.id] = {
sign: item.sign ? item.sign : false,
answers: item.user_answer
}
})
})
return {
type: 1,
sheet_id: this.data.id,
status: 0,
answers: JSON.stringify(answers),
duration: 0
}
return { type: 1, sheet_id: this.data.id, status: 0, answers: JSON.stringify(answers), duration: 0 }
}
}
}
......
<template>
<exam-card
:title="title"
:questionItems="questionItems"
:groups="questionGroups"
:hasMark="false"
:hasDeleteBtn="true"
:hasCountDown="false"
:hasShowResultBtn="true"
submitButtonText="清空记录,重新答题"
@submitExam="handleSubmit"
@back="handleBack"
@submit="handleSubmit"
@page-change="handlePageChange"
@deleteQuestion="deleteQuestion"
@delete="deleteQuestion"
ref="exam"
v-if="Object.keys(data).length"
></exam-card>
......@@ -28,10 +30,10 @@ export default {
title() {
return this.$route.query.type === '1' ? '错题集合' : '收藏试题'
},
questionItems() {
return this.data.list.map(groups => {
const [first = {}] = groups
return { question_item_id: '', question_type: first.question_type, question_list: groups, hasResult: false }
questionGroups() {
return this.data.list.map(list => {
const [first = {}] = list
return { question_item_id: '', question_type: first.question_type, question_list: list, hasResult: false }
})
}
},
......@@ -46,15 +48,20 @@ export default {
question_id: data.question_list[0].question_id,
type: this.$route.query.type
}
api
.deleteQuestion(param)
.then(response => {
// this.getTopic()
this.$router.go(0)
api.deleteQuestion(param).then(response => {
this.getTopic().then(() => {
// 重置
this.$refs.exam.reset()
})
.finally(() => {
})
console.log(data)
})
},
// 返回
handleBack() {
if (this.$route.query.type === '1') {
this.$router.push('/my/questions/wrong')
} else {
this.$router.push('/my/questions/collection')
}
},
// 获取考卷
getTopic() {
......@@ -65,7 +72,7 @@ export default {
page: this.page,
page_size: 20
}
api.getMyQuestion(param).then(response => {
return api.getMyQuestion(param).then(response => {
this.data = response
})
},
......@@ -81,25 +88,21 @@ export default {
})
},
// 缓存答案
handlePageChange(data) {
this.cacheQuestion(this.genSubmitData(this.$refs.exam.questionItems))
handlePageChange(data, groups) {
this.cacheQuestion(this.genSubmitData(groups))
},
cacheQuestion(param, call) {
api
.setMyCache(param)
.then(response => {
call()
})
.finally(() => {
})
cacheQuestion(param, callback) {
api.setMyCache(param).then(response => {
callback && callback()
})
},
// 组装提交数据
genSubmitData(questionList) {
genSubmitData(questionGroups) {
const answers = {}
questionList.forEach(item => {
item.question_list.forEach(cItem => {
if (cItem.user_answer.length) {
answers[cItem.question_id] = cItem.user_answer
questionGroups.forEach(group => {
group.question_list.forEach(item => {
if (item.user_answer.length) {
answers[item.question_id] = item.user_answer
}
})
})
......
<template>
<div>
<exam-card :hasSubmitBtn="!!(!this.$route.query.id)" :hasCountDown="!!(!this.$route.query.id)" v-if="Object.keys(data).length" @submitExam="submitExam" ref="exam" title="模拟考试" :data="data"></exam-card>
<exam-card
title="模拟考试"
:hasSubmitBtn="!!!this.$route.query.id"
:hasCountdown="!!!this.$route.query.id"
:data="data"
@submit="submitExam"
@back="handleBack"
ref="exam"
v-if="Object.keys(data).length"
></exam-card>
</div>
</template>
<script>
......@@ -47,6 +56,10 @@ export default {
this.data = JSON.parse(response.data).sheet
})
},
// 返回
handleBack() {
this.$router.push('/testExam')
},
// 提交考卷 isCache:0缓存,1提交
submitExam(isCache) {
const refData = this.$refs.exam
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论