|
@@ -0,0 +1,83 @@
|
|
|
|
|
+<template>
|
|
|
|
|
+ <tab-side-component>
|
|
|
|
|
+ <back-title>{{ quiz.name }}</back-title>
|
|
|
|
|
+ <form @submit.prevent="handleFormSubmit">
|
|
|
|
|
+ <button>提交</button>
|
|
|
|
|
+ <div :key="question.id" v-for="(question, index) in quiz.questions">
|
|
|
|
|
+ <div>{{ index + 1 }}.</div>
|
|
|
|
|
+ <markdown-section :raw="question.stem" />
|
|
|
|
|
+ <div v-if="question.kind === QuestionKind.choice">
|
|
|
|
|
+ <label :key="index" v-for="(item, index) in question.options">
|
|
|
|
|
+ <input v-model="question.studentAnswer" type="radio" :value="index" />
|
|
|
|
|
+ <markdown-section style="display: inline" :raw="item" />
|
|
|
|
|
+ </label>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <div v-else-if="question.kind === QuestionKind.trueOrFalse">
|
|
|
|
|
+ <label>
|
|
|
|
|
+ <input v-model="question.studentAnswer" type="radio" :value="true" />
|
|
|
|
|
+ <eva-icon-checkmark />
|
|
|
|
|
+ </label>
|
|
|
|
|
+ <label>
|
|
|
|
|
+ <input v-model="question.studentAnswer" type="radio" :value="false" />
|
|
|
|
|
+ <eva-icon-close-outline />
|
|
|
|
|
+ </label>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <button>提交</button>
|
|
|
|
|
+ </form>
|
|
|
|
|
+ </tab-side-component>
|
|
|
|
|
+</template>
|
|
|
|
|
+<script>
|
|
|
|
|
+import TabSideComponent from '@/components/TabSideComponent'
|
|
|
|
|
+import BackTitle from '@/components/BackTitle'
|
|
|
|
|
+import { getQuizById, submitQuiz } from '@/server/quiz'
|
|
|
|
|
+import { createDefaultQuiz } from '@/views/quiz/utils/default'
|
|
|
|
|
+import QuestionKind from '@/server/enums/question-kind'
|
|
|
|
|
+import MarkdownSection from '@/views/quiz/components/MarkdownSection'
|
|
|
|
|
+import EvaIconCheckmark from '@/components/EvaIcon/EvaIconCheckmark'
|
|
|
|
|
+import EvaIconCloseOutline from '@/components/EvaIcon/EvaIconCloseOutline'
|
|
|
|
|
+
|
|
|
|
|
+export default {
|
|
|
|
|
+ components: { EvaIconCloseOutline, EvaIconCheckmark, MarkdownSection, BackTitle, TabSideComponent },
|
|
|
|
|
+ data() {
|
|
|
|
|
+ return {
|
|
|
|
|
+ quiz: createDefaultQuiz(),
|
|
|
|
|
+ hasSubmit: false,
|
|
|
|
|
+
|
|
|
|
|
+ QuestionKind
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ beforeRouteLeave (to, from, next) {
|
|
|
|
|
+ if (this.hasSubmit) {
|
|
|
|
|
+ next()
|
|
|
|
|
+ } else if (window.confirm('您的答案没有提交,确定要离开页面?')) {
|
|
|
|
|
+ next()
|
|
|
|
|
+ } else {
|
|
|
|
|
+ next(false)
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ mounted() {
|
|
|
|
|
+ this.fetchQuizDetail()
|
|
|
|
|
+ },
|
|
|
|
|
+ methods: {
|
|
|
|
|
+ fetchQuizDetail() {
|
|
|
|
|
+ const { quizId } = this.$route.params
|
|
|
|
|
+ getQuizById(quizId)
|
|
|
|
|
+ .then(res => (this.quiz = res))
|
|
|
|
|
+ .catch(err => this.$setErrorMessage(err.response.data.msg))
|
|
|
|
|
+ },
|
|
|
|
|
+ handleFormSubmit() {
|
|
|
|
|
+ const { quizId } = this.$route.params
|
|
|
|
|
+ submitQuiz({ quizId, answers: this.quiz.questions })
|
|
|
|
|
+ .then(() => {
|
|
|
|
|
+ this.hasSubmit = true
|
|
|
|
|
+ this.$setSuccessMessage('提交成功')
|
|
|
|
|
+ this.$router.go(-1)
|
|
|
|
|
+ })
|
|
|
|
|
+ .catch(err =>
|
|
|
|
|
+ this.$setErrorMessage(err.response.data.msg)
|
|
|
|
|
+ )
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+</script>
|