QuestionView.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <template>
  2. <div v-if="question && examQuestion" class="question-view">
  3. <div class="sign-button">
  4. <Icon :type="examQuestion.isSign ? 'ios-star':'ios-star-outline'" :style="{color: '#ffcc00'}" class="star" @click="toggleSign" />
  5. </div>
  6. <div v-if="parentQuestionBody" class="question-view">
  7. <question-body :questionBody="parentQuestionBody" :examQuestionId="examQuestion.id" style="margin-bottom: 20px" :key="this.examQuestion.order"></question-body>
  8. <div class="hr" />
  9. </div>
  10. <template v-if="question.questionType === 'SINGLE_CHOICE'">
  11. <single-question-view :question="question" :examQuestion="examQuestion" :key="this.examQuestion.order" />
  12. </template>
  13. <template v-if="question.questionType === 'MULTIPLE_CHOICE'">
  14. <multiple-question-view :question="question" :examQuestion="examQuestion" :key="this.examQuestion.order" />
  15. </template>
  16. <template v-if="question.questionType === 'TRUE_OR_FALSE'">
  17. <boolean-question-view :question="question" :examQuestion="examQuestion" :key="this.examQuestion.order" />
  18. </template>
  19. <template v-if="question.questionType === 'FILL_UP'">
  20. <fill-blank-question-view :question="question" :examQuestion="examQuestion" :key="this.examQuestion.order" />
  21. </template>
  22. <template v-if="question.questionType === 'ESSAY'">
  23. <text-question-view :question="question" :examQuestion="examQuestion" :key="this.examQuestion.order" />
  24. </template>
  25. </div>
  26. </template>
  27. <script>
  28. import QuestionBody from "./QuestionBody";
  29. import SingleQuestionView from "./SingleQuestionView";
  30. import MultipleQuestionView from "./MultipleQuestionView";
  31. import BooleanQuestionView from "./BooleanQuestionView";
  32. import FillBlankQuestionView from "./FillBlankQuestionView";
  33. import TextQuestionView from "./TextQuestionView";
  34. import NestedQuestionView from "./NestedQuestionView";
  35. import { createNamespacedHelpers } from "vuex";
  36. const { mapMutations } = createNamespacedHelpers("examingHomeModule");
  37. export default {
  38. name: "QuestionView",
  39. data() {
  40. return {
  41. parentQuestionBody: null,
  42. question: null
  43. };
  44. },
  45. props: {
  46. examQuestion: Object
  47. },
  48. created() {
  49. this.updateQuestion();
  50. },
  51. methods: {
  52. ...mapMutations(["updateExamQuestion"]),
  53. async updateQuestion() {
  54. const res = await this.$http.get(
  55. "/api/ecs_oe_student/examQuestion/getQuestionContent?questionId=" +
  56. this.examQuestion.questionId
  57. );
  58. const question = res.data;
  59. const transferWellNumberAndTrustInBody = function(repQuestion) {
  60. //将题干中的三个#替换为下划线
  61. if (repQuestion.body) {
  62. //将题干里的&nbsp;换成空格
  63. repQuestion.body = repQuestion.body
  64. .toString()
  65. .replace(new RegExp("&nbsp;", "g"), " ");
  66. repQuestion.body = repQuestion.body
  67. .toString()
  68. .replace(new RegExp("###", "g"), "_______");
  69. //将题干中的两个##数字##替换为下划线
  70. // var baseIndex = examQuestion.orders - 1;
  71. repQuestion.body = repQuestion.body
  72. .toString()
  73. .replace(/##(\d+)##/g, function(a, b) {
  74. return "__" + parseInt(b) + "__";
  75. });
  76. }
  77. // console.log(repQuestion);
  78. };
  79. const initQuestion = function(repQuestion) {
  80. if (
  81. repQuestion.questionType === "SINGLE_CHOICE" ||
  82. repQuestion.questionType === "MULTIPLE_CHOICE"
  83. ) {
  84. for (
  85. var i = 0, imax = repQuestion.questionOptionList.length;
  86. i < imax;
  87. i++
  88. ) {
  89. // repQuestion.options[i].content = $sce.trustAsHtml(
  90. // repQuestion.options[i].content
  91. // );
  92. }
  93. }
  94. if (repQuestion.questionType === "FILL_UP") {
  95. if (repQuestion.answer && repQuestion.answer.indexOf("##") > -1) {
  96. //优先使用##
  97. repQuestion.answerList = repQuestion.answer.split("##");
  98. } else {
  99. repQuestion.answerList = [repQuestion.answer];
  100. }
  101. }
  102. transferWellNumberAndTrustInBody(repQuestion);
  103. };
  104. //判断是否为套题
  105. if (question.body) {
  106. transferWellNumberAndTrustInBody(question);
  107. for (
  108. var j = 0, jmax = question.questionUnitList.length;
  109. j < jmax;
  110. j++
  111. ) {
  112. initQuestion(question.questionUnitList[j]);
  113. }
  114. // 对子题进行排序
  115. // if (question.questionUnitList && question.questionUnitList.length > 0) {
  116. // question.questionUnitList.sort(function(a, b) {
  117. // if (a.quesNumber > b.quesNumber) {
  118. // return 1;
  119. // } else if (a.quesNumber < b.quesNumber) {
  120. // return -1;
  121. // } else {
  122. // return 0;
  123. // }
  124. // });
  125. // }
  126. this.parentQuestionBody = question.body;
  127. } else {
  128. this.parentQuestionBody = null;
  129. initQuestion(
  130. question.questionUnitList[this.examQuestion.subNumber - 1]
  131. );
  132. }
  133. this.question =
  134. question.questionUnitList[this.examQuestion.subNumber - 1];
  135. },
  136. async toggleSign() {
  137. await this.$http.post(
  138. "/api/ecs_oe_student/examQuestion/submitQuestionAnswer",
  139. [
  140. {
  141. order: this.examQuestion.order,
  142. isSign: !this.examQuestion.isSign
  143. }
  144. ]
  145. );
  146. this.updateExamQuestion({
  147. order: this.$route.params.order,
  148. isSign: !this.examQuestion.isSign
  149. });
  150. }
  151. },
  152. watch: {
  153. $route: function() {
  154. this.updateQuestion();
  155. }
  156. },
  157. components: {
  158. QuestionBody,
  159. SingleQuestionView,
  160. MultipleQuestionView,
  161. BooleanQuestionView,
  162. FillBlankQuestionView,
  163. TextQuestionView,
  164. NestedQuestionView
  165. }
  166. };
  167. </script>
  168. <style scoped>
  169. .question-view {
  170. padding: 20px;
  171. font-size: 16px;
  172. text-align: left;
  173. }
  174. .star {
  175. font-size: 36px;
  176. }
  177. .star:hover {
  178. cursor: pointer;
  179. }
  180. div.hr {
  181. border-bottom: 1px dashed gray;
  182. }
  183. </style>