QuestionView.vue 6.9 KB

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