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

updates

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