nebula/pages/answer.vue

140 lines
4.1 KiB
Vue
Raw Normal View History

2020-12-08 19:59:46 +08:00
<template>
<el-row class="wrapper">
<el-col v-for="answerRecord in answerRecords" :key="answerRecord.id">
<el-col v-if="answerRecord.subjectAnswerRecords">
<el-col class="question-tip">
<h1> 您已完成今日答题任务!</h1>
</el-col>
<el-col>
<h2>答题记录</h2>
</el-col>
</el-col>
2020-12-08 19:59:46 +08:00
<el-col class="question-content">
2022-01-03 12:53:30 +08:00
<h2 v-html="getQuestionContent(answerRecord.questionContent)"></h2>
2020-12-08 19:59:46 +08:00
</el-col>
<el-col>
<el-col v-if="answerRecord.subjectAnswerRecords">
<el-col class="question-option">
<el-radio-group v-model="answerRecord.subjectAnswerRecords[0].answer" :disabled="true">
<template v-for="subjectOption in answerRecord.subjectOptionDTOList">
2022-01-03 12:53:30 +08:00
<el-col :span="24" style="margin-bottom: 10px;">
<el-radio :key="subjectOption.optionName" :label="subjectOption.optionName">
<span>{{ subjectOption.optionName }}.</span>
<span>{{ subjectOption.optionContent }}</span>
</el-radio>
</el-col>
2020-12-08 19:59:46 +08:00
</template>
</el-radio-group>
</el-col>
<el-col :span="6">
2020-12-10 17:03:32 +08:00
你的答案:
<span v-if="answerRecord.correctAnswer == answerRecord.subjectAnswerRecords[0].answer" class="question-answer answer-right">{{answerRecord.subjectAnswerRecords[0].answer}}</span>
<span v-else class="question-answer answer-wrong">{{answerRecord.subjectAnswerRecords[0].answer}}</span>
2020-12-08 19:59:46 +08:00
</el-col>
<el-col class="question-operate" :span="6">
正确答案: <span class="question-answer"> {{ answerRecord.correctAnswer }} </span>
2020-12-08 19:59:46 +08:00
</el-col>
</el-col>
<el-col v-else>
<el-col class="question-option">
<el-radio-group v-model="answer">
<template v-for="subjectOption in answerRecord.subjectOptionDTOList">
2022-01-03 12:53:30 +08:00
<el-col :span="24" style="margin-bottom: 10px;">
<el-radio :key="subjectOption.optionName" :label="subjectOption.optionName">
<span>{{ subjectOption.optionName }}.</span>
<span>{{ subjectOption.optionContent }}</span>
</el-radio>
</el-col>
2020-12-08 19:59:46 +08:00
</template>
</el-radio-group>
</el-col>
<el-col class="question-operate" :span="6">
<el-button type="primary" @click="submitAnswer">提交答案</el-button>
</el-col>
</el-col>
</el-col>
</el-col>
</el-row>
</template>
<script>
import {mapState} from 'vuex';
export default {
name: "answer",
2022-10-27 23:22:46 +08:00
middleware: 'auth',
fetch() {
let {store, params, error} = this.$nuxt.context
2020-12-08 19:59:46 +08:00
return Promise.all([
store
.dispatch('answer/fetchDetail', params)
.catch(err => error({statusCode: 404}))
])
},
computed: {
...mapState({
answerRecords: state => state.answer.detail.answerRecords
})
},
data() {
return {
answer: '',
correctAnswer: ''
}
},
methods: {
getQuestionContent(questionContent) {
2022-01-03 12:53:30 +08:00
questionContent = questionContent.replace("", "____");
2020-12-08 19:59:46 +08:00
questionContent = questionContent.replace("", "");
return questionContent;
},
submitAnswer() {
let _ts = this;
_ts.$axios.$post("/api/answer/answer", {
idSubjectQuestion: _ts.answerRecords[0].id,
answer: _ts.answer
}).then(function (res) {
if (res) {
2021-02-20 16:55:43 +08:00
_ts.$message.success('回答正确!');
} else {
_ts.$message.error('回答错误!');
2020-12-08 19:59:46 +08:00
}
2021-02-20 16:55:43 +08:00
_ts.$store.dispatch('answer/fetchDetail');
2020-12-08 19:59:46 +08:00
})
}
},
mounted() {
this.$store.commit('setActiveMenu', 'answer');
}
}
</script>
<style scoped>
.question-tip {
margin-bottom: 40px;
margin-left: 15%;
}
2020-12-08 19:59:46 +08:00
.question-content {
margin: 10px auto;
}
.question-option {
margin: 10px auto;
}
.question-answer {
font-size: 36px;
padding-left: 10px;
}
.question-operate {
margin: 10px auto;
text-align: right;
}
2020-12-10 17:03:32 +08:00
.answer-right {
color: limegreen;
}
.answer-wrong {
color: red;
}
2020-12-08 19:59:46 +08:00
</style>