ReplaceAnswerPreview.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. <!-- eslint-disable vue/no-v-html -->
  2. <template>
  3. <div v-if="show_preview" class="replace-preview">
  4. <div class="stem">
  5. <span class="question-number" :style="{ fontSize: data.property.stem_question_number_font_size }">
  6. {{ questionNumberEndIsBracket(data.property.question_number) }}
  7. </span>
  8. <span v-html="sanitizeHTML(data.stem)"></span>
  9. </div>
  10. <div
  11. v-if="isEnable(data.property.is_enable_description)"
  12. class="description rich-text"
  13. v-html="sanitizeHTML(data.description)"
  14. ></div>
  15. <div class="option-list">
  16. <div v-for="(item, i) in option_list" :key="i" :class="['option-item']">
  17. <template v-if="item.length > 1">
  18. <span class="select-item select-active">{{ active_content[i] }}</span>
  19. <ul
  20. :ref="'ui' + i"
  21. class="replace-ul"
  22. :style="{ overflow: disabled ? 'hidden' : 'scroll' }"
  23. @scroll="handleScroll($event, i)"
  24. >
  25. <li
  26. v-for="(items, j) in item"
  27. :key="j"
  28. :class="[computedAnswerClass(i, items)]"
  29. @click="handleClickItem(i, j)"
  30. >
  31. {{ items.content }}
  32. </li>
  33. </ul>
  34. </template>
  35. <span v-else class="select-item replace-ul">{{ item[0].content }}</span>
  36. </div>
  37. <SoundRecordPreview
  38. :wav-blob.sync="answer.answer_list[0].audio_file_id"
  39. :disabled="disabled"
  40. position="center"
  41. v-if="answer.answer_list[0] && answer.answer_list[0].hasOwnProperty('audio_file_id')"
  42. />
  43. </div>
  44. <div v-if="isEnable(data.property.is_enable_reference_answer) && isShowRightAnswer" class="reference-box">
  45. <h5 class="reference-title">参考答案</h5>
  46. <span class="reference-answer rich-text" v-html="sanitizeHTML(data.reference_answer)"></span>
  47. </div>
  48. <div v-if="isEnable(data.property.is_enable_analysis) && isShowRightAnswer" class="analysis">
  49. <span class="analysis-title">解析</span>
  50. <div class="analysis-content" v-html="sanitizeHTML(data.analysis)"></div>
  51. </div>
  52. </div>
  53. </template>
  54. <script>
  55. import PreviewMixin from './components/PreviewMixin';
  56. import { computeOptionMethods } from '@/views/exercise_questions/data/common';
  57. import SoundRecordPreview from './components/common/SoundRecordPreview.vue';
  58. export default {
  59. name: 'ReplaceAnswerPreview',
  60. components: {
  61. SoundRecordPreview,
  62. },
  63. mixins: [PreviewMixin],
  64. data() {
  65. return {
  66. computeOptionMethods,
  67. option_list: [],
  68. active_content: [],
  69. show_preview: false,
  70. };
  71. },
  72. watch: {
  73. data: {
  74. handler(val) {
  75. if (!val || this.data.type !== 'replace_answer') return;
  76. this.handleData();
  77. },
  78. deep: true,
  79. immediate: true,
  80. },
  81. isJudgingRightWrong: {
  82. handler(val) {
  83. if (!val) return;
  84. this.handleData();
  85. },
  86. immediate: true,
  87. },
  88. },
  89. created() {},
  90. mounted() {},
  91. methods: {
  92. // 初始化数据
  93. handleData() {
  94. this.option_list = [];
  95. this.active_content = [];
  96. if (!this.isJudgingRightWrong) {
  97. this.answer.answer_list = [
  98. {
  99. audio_file_id: '',
  100. mark_list: [],
  101. },
  102. ];
  103. }
  104. let option_lists = [];
  105. this.data.option_list[0].forEach(() => {
  106. option_lists.push([]);
  107. });
  108. this.data.option_list.forEach((item) => {
  109. item.forEach((items, i) => {
  110. if (items.content) {
  111. option_lists[i].push(items);
  112. }
  113. });
  114. });
  115. option_lists.forEach((option_item) => {
  116. if (option_item.length > 0) {
  117. this.option_list.push(option_item);
  118. if (this.isJudgingRightWrong) {
  119. this.active_content.push('');
  120. this.answer.answer_list[0].mark_list.forEach((item_mark, index_mark) => {
  121. this.$refs[`ui${index_mark}`][0].scrollTop = 0;
  122. option_item.forEach((option_items, index_items) => {
  123. if (item_mark === option_items.mark) {
  124. this.active_content[index_mark] = option_items.content;
  125. setTimeout(() => {
  126. this.$refs[`ui${index_mark}`][0].scrollTop = index_items * 48;
  127. }, 100);
  128. }
  129. });
  130. });
  131. } else {
  132. this.answer.answer_list[0].mark_list.push(option_item.length > 1 ? option_item[0].mark : '');
  133. this.active_content.push(option_item.length > 1 ? option_item[0].content : '');
  134. }
  135. }
  136. });
  137. this.show_preview = true;
  138. },
  139. // 处理滚动
  140. handleScroll(event, i) {
  141. let scrollTop = event.target.scrollTop;
  142. let scrollIndex = Math.round(scrollTop / 48);
  143. this.active_content[i] = this.option_list[i][scrollIndex].content;
  144. this.answer.answer_list[0].mark_list[i] = this.option_list[i][scrollIndex].mark;
  145. this.$forceUpdate();
  146. },
  147. handleClickItem(i, j) {
  148. if (this.disabled) return;
  149. this.$refs[`ui${i}`][0].scrollTop = j * 48;
  150. this.active_content[i] = this.option_list[i][j].content;
  151. this.answer.answer_list[0].mark_list[i] = this.option_list[i][j].mark;
  152. this.$forceUpdate();
  153. },
  154. computedAnswerClass(i, item) {
  155. return this.answer.answer_list[0] &&
  156. this.answer.answer_list[0].mark_list &&
  157. this.answer.answer_list[0].mark_list[i] === item.mark
  158. ? 'active'
  159. : '';
  160. },
  161. },
  162. };
  163. </script>
  164. <style lang="scss" scoped>
  165. @use '@/styles/mixin.scss' as *;
  166. .replace-preview {
  167. @include preview;
  168. .option-list {
  169. display: flex;
  170. flex-wrap: wrap;
  171. align-items: center;
  172. justify-content: center;
  173. width: max-content;
  174. margin: 0 auto;
  175. border-left: 1px solid rgba(0, 0, 0, 8%);
  176. .option-item {
  177. position: relative;
  178. display: flex;
  179. align-items: center;
  180. height: 356px;
  181. border-right: 1px solid rgba(0, 0, 0, 8%);
  182. }
  183. .select-item {
  184. padding: 6px 8px;
  185. font-size: 20px;
  186. line-height: 28px;
  187. color: #1d2129;
  188. background-color: rgba(239, 239, 239, 100%);
  189. }
  190. .select-active {
  191. position: absolute;
  192. top: 50%;
  193. left: 0;
  194. z-index: 1;
  195. display: block;
  196. width: 100%;
  197. height: 40px;
  198. margin-top: -20px;
  199. color: rgba(29, 33, 41, 100%);
  200. background-color: rgba(239, 239, 239, 100%);
  201. }
  202. ul {
  203. height: 356px;
  204. padding: 158px 0 150px;
  205. overflow-y: scroll;
  206. &::-webkit-scrollbar {
  207. display: none;
  208. }
  209. li {
  210. padding: 6px 8px;
  211. margin-bottom: 8px;
  212. font-size: 20px;
  213. line-height: 28px;
  214. color: rgba(29, 33, 41, 100%);
  215. opacity: 0.4;
  216. }
  217. }
  218. }
  219. .sound-record-preview {
  220. display: flex;
  221. flex-wrap: wrap;
  222. justify-content: center;
  223. width: 280px;
  224. margin-left: 80px;
  225. }
  226. .reference-box {
  227. padding: 12px;
  228. background: $content-color;
  229. .reference-title {
  230. margin: 0 0 10px;
  231. font-size: 14px;
  232. font-weight: 400;
  233. line-height: 32px;
  234. color: $font-light-color;
  235. }
  236. :deep p {
  237. margin: 0;
  238. }
  239. }
  240. }
  241. </style>