|
@@ -0,0 +1,103 @@
|
|
|
+<template>
|
|
|
+ <div class="question-view">
|
|
|
+ <div class="question-body" v-html="questionBody"></div>
|
|
|
+ <div class="ops">
|
|
|
+ <i-button @click="resetQuestion(examQuestion.id)">重置</i-button>
|
|
|
+ <div class="score">({{question.questionScore}}分)</div>
|
|
|
+ </div>
|
|
|
+ <div v-for="(option, index) in stuAnswer.split('##')" :key="index" class="option">
|
|
|
+ <span class="question-options">{{index+1}}. </span>
|
|
|
+ <input type="text" name="question" :value="option" @input="inputAnswer" />
|
|
|
+ </div>
|
|
|
+
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script>
|
|
|
+const optionName = ["A", "B", "C", "D", "E", "F"];
|
|
|
+export default {
|
|
|
+ name: "FillBlankQuestionView",
|
|
|
+ data() {
|
|
|
+ const questionNumber = this.question.body.split(/_{5,}/).length - 1;
|
|
|
+
|
|
|
+ const answers = this.examQuestion.stuAnswer
|
|
|
+ ? this.examQuestion.stuAnswer.split("##")
|
|
|
+ : "##".repeat(questionNumber - 1).split("##");
|
|
|
+ let questionBody = this.question.body.replace(
|
|
|
+ /_{5,}/g,
|
|
|
+ () =>
|
|
|
+ "<span style='display: inline-block; min-width: 80px; border-bottom: 1px solid black'>" +
|
|
|
+ (answers.shift() || questionNumber - answers.length) +
|
|
|
+ "</span>"
|
|
|
+ );
|
|
|
+ return {
|
|
|
+ questionNumber,
|
|
|
+ questionBody,
|
|
|
+ stuAnswer: this.examQuestion.stuAnswer || "##".repeat(questionNumber - 1)
|
|
|
+ };
|
|
|
+ },
|
|
|
+ props: {
|
|
|
+ question: Object,
|
|
|
+ examQuestion: Object
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ answerQuestion: function(examQuestionId, stuAnswer) {
|
|
|
+ this.stuAnswer = stuAnswer;
|
|
|
+ this.$http.put("/api/exam_question/" + examQuestionId, { stuAnswer });
|
|
|
+ },
|
|
|
+ resetQuestion: function(examQuestionId) {
|
|
|
+ this.stuAnswer = "##".repeat(this.questionNumber - 1);
|
|
|
+ setTimeout(this.inputAnswer, 100);
|
|
|
+ this.$http.put("/api/exam_question/" + examQuestionId, {
|
|
|
+ stuAnswer: null
|
|
|
+ });
|
|
|
+ },
|
|
|
+ inputAnswer: function(e) {
|
|
|
+ const questionNumber = this.question.body.split(/_{5,}/).length - 1;
|
|
|
+ let ans = "";
|
|
|
+ document
|
|
|
+ .querySelectorAll(".option input")
|
|
|
+ .forEach(e => (ans += e.value + "##"));
|
|
|
+ console.log(ans);
|
|
|
+ this.stuAnswer = ans.slice(0, -2);
|
|
|
+ const answers = this.stuAnswer.split("##");
|
|
|
+ this.questionBody = this.question.body.replace(
|
|
|
+ /_{5,}/g,
|
|
|
+ () =>
|
|
|
+ "<span style='display: inline-block; min-width: 80px; border-bottom: 1px solid black'>" +
|
|
|
+ (answers.shift() || questionNumber - answers.length) +
|
|
|
+ "</span>"
|
|
|
+ );
|
|
|
+ }
|
|
|
+ },
|
|
|
+ watch: {
|
|
|
+ stuAnswer: function() {
|
|
|
+ // question.body =
|
|
|
+ }
|
|
|
+ }
|
|
|
+};
|
|
|
+</script>
|
|
|
+
|
|
|
+<style scoped>
|
|
|
+.question-view {
|
|
|
+ display: block;
|
|
|
+}
|
|
|
+
|
|
|
+.ops {
|
|
|
+ display: flex;
|
|
|
+ align-items: flex-end;
|
|
|
+}
|
|
|
+
|
|
|
+.stu-answer {
|
|
|
+ width: 100px;
|
|
|
+ border-bottom: 1px solid black;
|
|
|
+}
|
|
|
+
|
|
|
+.option {
|
|
|
+ /* display: flex; */
|
|
|
+}
|
|
|
+.question-options {
|
|
|
+ text-align: left;
|
|
|
+ padding-left: 10px;
|
|
|
+}
|
|
|
+</style>
|