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

bug fixes

上级 882b76e0
<template> <template>
<container :title="chapter.name" v-loading="loading"> <container :title="chapter.name" v-loading="loading">
<template v-slot:header-aside v-if="isSubmited">正确率:{{detail.score}}%</template> <template v-slot:header-aside v-if="isSubmited">正确率:{{ detail.score }}%</template>
<div class="exam"> <div class="exam">
<div class="exam-form"> <div class="exam-form">
<el-form :disabled="isSubmited"> <el-form :disabled="isSubmited">
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
></exam-item> ></exam-item>
<div class="exam-buttons"> <div class="exam-buttons">
<el-tooltip effect="dark" content="提交之后就不能修改了哦" placement="right"> <el-tooltip effect="dark" content="提交之后就不能修改了哦" placement="right">
<el-button type="primary" :loading="submitLoading" @click="onSubmit">{{submitText}}</el-button> <el-button type="primary" :loading="submitLoading" @click="onSubmit">{{ submitText }}</el-button>
</el-tooltip> </el-tooltip>
</div> </div>
</el-form> </el-form>
...@@ -60,9 +60,7 @@ export default { ...@@ -60,9 +60,7 @@ export default {
chapter: { chapter: {
immediate: true, immediate: true,
handler(data) { handler(data) {
this.questions = data.homework this.questions = data.homework ? this.genQuenstions(data.homework.questions) : []
? this.genQuenstions(data.homework.questions)
: []
} }
} }
}, },
...@@ -91,8 +89,7 @@ export default { ...@@ -91,8 +89,7 @@ export default {
}, },
// 是否提交 // 是否提交
isSubmited() { isSubmited() {
// return this.detail ? !!this.detail.work_contents : false return this.detail ? !!this.detail.work_contents : false
return false
}, },
// 提交按钮文本 // 提交按钮文本
submitText() { submitText() {
...@@ -111,16 +108,13 @@ export default { ...@@ -111,16 +108,13 @@ export default {
const parseAnswers = JSON.parse(this.detail.work_contents) const parseAnswers = JSON.parse(this.detail.work_contents)
// 设置答案 // 设置答案
this.questions = this.questions.map(item => { this.questions = this.questions.map(item => {
const found = parseAnswers.find( const found = parseAnswers.find(answer => answer.question_id === item.id)
answer => answer.question_id === item.id
)
if (found) { if (found) {
const selectedIds = found.options.reduce((result, item) => { const selectedIds = found.options.reduce((result, item) => {
item.selected && result.push(item.id) item.selected && result.push(item.id)
return result return result
}, []) }, [])
item.user_answer = item.user_answer = item.question_type === 2 ? selectedIds : selectedIds[0]
item.question_type === 2 ? selectedIds : selectedIds[0]
} }
return item return item
}) })
...@@ -153,9 +147,7 @@ export default { ...@@ -153,9 +147,7 @@ export default {
temp = { temp = {
formModel: { formModel: {
id: item.id, id: item.id,
user_answer: item.user_answer user_answer: item.user_answer ? Base64.decode(item.user_answer) : '',
? Base64.decode(item.user_answer)
: '',
attachments: item.attachments || '' attachments: item.attachments || ''
} }
} }
...@@ -165,9 +157,7 @@ export default { ...@@ -165,9 +157,7 @@ export default {
item, item,
{ {
content: item.question_content, content: item.question_content,
options: item.question_options options: item.question_options ? JSON.parse(item.question_options) : []
? JSON.parse(item.question_options)
: []
}, },
temp temp
) )
...@@ -193,9 +183,7 @@ export default { ...@@ -193,9 +183,7 @@ export default {
return return
} }
// 计算答题时间 // 计算答题时间
const duration = Math.floor( const duration = Math.floor((new Date().getTime() - this.startTime) / 1000)
(new Date().getTime() - this.startTime) / 1000
)
// 答案数据 // 答案数据
const data = this.handleSubmitData() const data = this.handleSubmitData()
// 计算分数 // 计算分数
...@@ -225,9 +213,7 @@ export default { ...@@ -225,9 +213,7 @@ export default {
// 选择的项 // 选择的项
const answers = item.formModel.user_answer const answers = item.formModel.user_answer
// 是否选中该项 // 是否选中该项
const selected = Array.isArray(answers) const selected = Array.isArray(answers) ? answers.includes(option.id) : option.id === answers
? answers.includes(option.id)
: option.id === answers
// 是否选择正确 // 是否选择正确
if (option.checked !== selected && isCorrect) { if (option.checked !== selected && isCorrect) {
isCorrect = false isCorrect = false
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论