QuestionView.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <template>
  2. <div v-if="question && examQuestion" class="question-view">
  3. <div class="question-group">{{"大题占位"}}</div>
  4. <div class="question-group-progress">{{"大题进度占位"}}</div>
  5. <template v-if="question.questionType === 'SINGLE_ANSWER_QUESTION'">
  6. <single-question-view :question="question" :examQuestion="examQuestion" />
  7. </template>
  8. <template v-if="question.questionType === 'MULTIPLE_ANSWER_QUESTION'">
  9. <multiple-question-view :question="question" :examQuestion="examQuestion" />
  10. </template>
  11. <template v-if="question.questionType === 'BOOL_ANSWER_QUESTION'">
  12. <boolean-question-view :question="question" :examQuestion="examQuestion" />
  13. </template>
  14. <template v-if="question.questionType === 'FILL_BLANK_QUESTION'">
  15. <fill-blank-question-view :question="question" :examQuestion="examQuestion" />
  16. </template>
  17. <template v-if="question.questionType === 'TEXT_ANSWER_QUESTION'">
  18. <text-question-view :question="question" :examQuestion="examQuestion" />
  19. </template>
  20. <template v-if="examQuestion.parentQuestion">
  21. <nested-question-view :question="question" :examQuestion="examQuestion" />
  22. </template>
  23. </div>
  24. </template>
  25. <script>
  26. import SingleQuestionView from "./SingleQuestionView";
  27. import MultipleQuestionView from "./MultipleQuestionView";
  28. import BooleanQuestionView from "./BooleanQuestionView";
  29. import FillBlankQuestionView from "./FillBlankQuestionView";
  30. import TextQuestionView from "./TextQuestionView";
  31. import NestedQuestionView from "./NestedQuestionView";
  32. export default {
  33. name: "QuestionView",
  34. data() {
  35. return {
  36. question: null
  37. };
  38. },
  39. props: {
  40. examQuestion: Object
  41. },
  42. methods: {
  43. async updateQuestion() {
  44. if (!this.examQuestion) {
  45. return;
  46. }
  47. const res = await this.$http.get(
  48. "/api/exam_question/question/?question_id=" +
  49. (this.examQuestion.questionId ||
  50. this.examQuestion.parentQuestion.questionId)
  51. );
  52. const question = res.data;
  53. // const examQuestion = this.examQuestion;
  54. const transferWellNumberAndTrustInBody = function(repQuestion) {
  55. //将题干中的三个#替换为下划线
  56. if (repQuestion.body) {
  57. //将题干里的&nbsp;换成空格
  58. repQuestion.body = repQuestion.body
  59. .toString()
  60. .replace(new RegExp("&nbsp;", "g"), " ");
  61. repQuestion.body = repQuestion.body
  62. .toString()
  63. .replace(new RegExp("###", "g"), "_______");
  64. //将题干中的两个##数字##替换为下划线
  65. // var baseIndex = examQuestion.orders - 1;
  66. repQuestion.body = repQuestion.body
  67. .toString()
  68. .replace(/##(\d+)##/g, function(a, b) {
  69. return "__" + parseInt(b) + "__";
  70. });
  71. // repQuestion.body = $sce.trustAsHtml(repQuestion.body);
  72. }
  73. };
  74. const initQuestion = function(repQuestion) {
  75. if (
  76. repQuestion.questionType === "SINGLE_ANSWER_QUESTION" ||
  77. repQuestion.questionType === "MULTIPLE_ANSWER_QUESTION"
  78. ) {
  79. for (var i = 0, imax = repQuestion.options.length; i < imax; i++) {
  80. // repQuestion.options[i].content = $sce.trustAsHtml(
  81. // repQuestion.options[i].content
  82. // );
  83. }
  84. }
  85. if (repQuestion.questionType === "FILL_BLANK_QUESTION") {
  86. if (repQuestion.answer && repQuestion.answer.indexOf("##") > -1) {
  87. //优先使用##
  88. repQuestion.answerList = repQuestion.answer.split("##");
  89. } else {
  90. repQuestion.answerList = [repQuestion.answer];
  91. }
  92. }
  93. transferWellNumberAndTrustInBody(repQuestion);
  94. };
  95. //判断是否为套题
  96. if (question.nestedQuestion) {
  97. transferWellNumberAndTrustInBody(question);
  98. for (var j = 0, jmax = question.subQuestionList.length; j < jmax; j++) {
  99. initQuestion(question.subQuestionList[j]);
  100. }
  101. // 对子题进行排序
  102. if (question.subQuestionList && question.subQuestionList.length > 0) {
  103. question.subQuestionList.sort(function(a, b) {
  104. if (a.quesNumber > b.quesNumber) {
  105. return 1;
  106. } else if (a.quesNumber < b.quesNumber) {
  107. return -1;
  108. } else {
  109. return 0;
  110. }
  111. });
  112. }
  113. } else {
  114. initQuestion(question);
  115. }
  116. this.question = question;
  117. }
  118. },
  119. watch: {
  120. examQuestion: function() {
  121. this.updateQuestion();
  122. }
  123. },
  124. components: {
  125. SingleQuestionView,
  126. MultipleQuestionView,
  127. BooleanQuestionView,
  128. FillBlankQuestionView,
  129. TextQuestionView,
  130. NestedQuestionView
  131. }
  132. };
  133. </script>
  134. <style scoped>
  135. question-view {
  136. display: grid;
  137. grid-template-columns: 1fr 1fr 1fr 1fr;
  138. }
  139. </style>