123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225 |
- <template>
- <div style="overflow: auto">
- <div class="question-header">
- <Icon :type="examQuestion.isSign ? 'ios-star':'ios-star-outline'" :style="{color: '#ffcc00'}" class="star" @click="toggleSign" />
- <question-index :examQuestion="examQuestion" />
- </div>
- <div v-if="parentQuestionBody" class="question-view">
- <question-body :questionBody="parentQuestionBody" :examQuestion="examQuestion" style="margin-bottom: 20px" :key="examQuestion.questionId"></question-body>
- <div class="hr" />
- </div>
- <transition name="fade">
- <div v-show="question && examQuestion" class="question-view" :key="examQuestion.order">
- <template v-if="question && question.questionType === 'SINGLE_CHOICE'">
- <single-question-view :question="question" :examQuestion="examQuestion" :key="examQuestion.order" />
- </template>
- <template v-if="question && question.questionType === 'MULTIPLE_CHOICE'">
- <multiple-question-view :question="question" :examQuestion="examQuestion" :key="examQuestion.order" />
- </template>
- <template v-if="question && question.questionType === 'TRUE_OR_FALSE'">
- <boolean-question-view :question="question" :examQuestion="examQuestion" :key="examQuestion.order" />
- </template>
- <template v-if="question && question.questionType === 'FILL_UP'">
- <fill-blank-question-view :question="question" :examQuestion="examQuestion" :key="examQuestion.order" />
- </template>
- <template v-if="question && question.questionType === 'ESSAY'">
- <text-question-view :question="question" :examQuestion="examQuestion" :key="examQuestion.order" />
- </template>
- </div>
- </transition>
- </div>
- </template>
- <script>
- import QuestionIndex from "./QuestionIndex";
- import QuestionBody from "./QuestionBody";
- import SingleQuestionView from "./SingleQuestionView";
- import MultipleQuestionView from "./MultipleQuestionView";
- import BooleanQuestionView from "./BooleanQuestionView";
- import FillBlankQuestionView from "./FillBlankQuestionView";
- import TextQuestionView from "./TextQuestionView";
- import NestedQuestionView from "./NestedQuestionView";
- import { createNamespacedHelpers } from "vuex";
- const { mapState, mapMutations } = createNamespacedHelpers("examingHomeModule");
- export default {
- name: "QuestionView",
- data() {
- return {
- parentQuestionBody: null,
- question: null,
- updateQuestioning: false // TODO: 更新问题时,隐藏旧内容。可能用不着
- };
- },
- props: {
- examQuestion: Object
- },
- created() {
- this.updateQuestion();
- },
- methods: {
- ...mapMutations(["updateExamQuestion"]),
- async updateQuestion() {
- this.updateQuestioning = true;
- const currentExamQuestion = this.examQuestion; // 避免以后执行时,this.examQuestion换掉了
- const examRecordDataId = this.$route.params.examRecordDataId;
- let qContentRes = null;
- try {
- qContentRes = await this.$http.get(
- "/api/ecs_oe_student/examQuestion/getQuestionContent?questionId=" +
- currentExamQuestion.questionId +
- "&exam_record_id=" +
- examRecordDataId
- );
- } catch (e) {
- this.updateQuestioning = false;
- this.parentQuestionBody = null;
- this.question = null;
- return;
- }
- this.updateQuestioning = false;
- const question = qContentRes.data;
- this.updateExamQuestion({
- order: currentExamQuestion.order,
- getQuestionContent: true
- });
- const transferWellNumberAndTrustInBody = function(repQuestion) {
- //将题干中的三个#替换为下划线
- if (repQuestion.body) {
- //将题干里的 换成空格
- repQuestion.body = repQuestion.body
- .toString()
- .replace(new RegExp(" ", "g"), " ");
- repQuestion.body = repQuestion.body
- .toString()
- .replace(new RegExp("###", "g"), "_______");
- //将题干中的两个##数字##替换为下划线
- // var baseIndex = examQuestion.orders - 1;
- repQuestion.body = repQuestion.body
- .toString()
- .replace(/##(\d+)##/g, function(a, b) {
- return "__" + parseInt(b) + "__";
- });
- }
- // console.log(repQuestion);
- };
- const initQuestion = function(repQuestion) {
- if (
- repQuestion.questionType === "SINGLE_CHOICE" ||
- repQuestion.questionType === "MULTIPLE_CHOICE"
- ) {
- for (
- var i = 0, imax = repQuestion.questionOptionList.length;
- i < imax;
- i++
- ) {
- // repQuestion.options[i].content = $sce.trustAsHtml(
- // repQuestion.options[i].content
- // );
- }
- }
- if (repQuestion.questionType === "FILL_UP") {
- if (repQuestion.answer && repQuestion.answer.indexOf("##") > -1) {
- //优先使用##
- repQuestion.answerList = repQuestion.answer.split("##");
- } else {
- repQuestion.answerList = [repQuestion.answer];
- }
- }
- transferWellNumberAndTrustInBody(repQuestion);
- };
- //判断是否为套题
- if (question.body) {
- transferWellNumberAndTrustInBody(question);
- for (
- var j = 0, jmax = question.questionUnitList.length;
- j < jmax;
- j++
- ) {
- initQuestion(question.questionUnitList[j]);
- }
- this.parentQuestionBody = question.body;
- } else {
- this.parentQuestionBody = null;
- initQuestion(
- question.questionUnitList[currentExamQuestion.subNumber - 1]
- );
- }
- this.question =
- question.questionUnitList[currentExamQuestion.subNumber - 1];
- {
- // cache next question content
- const currentOrder = currentExamQuestion.order;
- if (currentOrder < this.examQuestionList.length) {
- this.$http.get(
- "/api/ecs_oe_student/examQuestion/getQuestionContent?questionId=" +
- this.examQuestionList[currentOrder].questionId +
- "&exam_record_id=" +
- examRecordDataId
- );
- }
- }
- },
- async toggleSign() {
- this.updateExamQuestion({
- order: this.$route.params.order,
- isSign: !this.examQuestion.isSign
- });
- }
- },
- computed: {
- ...mapState(["examQuestionList"])
- },
- watch: {
- $route: function() {
- this.updateQuestion();
- }
- },
- components: {
- QuestionIndex,
- QuestionBody,
- SingleQuestionView,
- MultipleQuestionView,
- BooleanQuestionView,
- FillBlankQuestionView,
- TextQuestionView,
- NestedQuestionView
- }
- };
- </script>
- <style scoped>
- .question-view {
- padding: 20px;
- font-size: 16px;
- text-align: left;
- overflow: auto;
- }
- .question-header {
- display: flex;
- align-items: center;
- }
- .star {
- font-size: 36px;
- }
- .star:hover {
- cursor: pointer;
- }
- div.hr {
- border-bottom: 1px dashed gray;
- }
- </style>
|