ReplaceAnswerPreview.vue 6.8 KB

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