WordCardPreview.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. <!-- eslint-disable vue/no-v-html -->
  2. <template>
  3. <div class="word-card-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. <!-- 笔画学习 -->
  16. <div :class="['words-box']">
  17. <el-image
  18. v-if="
  19. option_list[active_index] &&
  20. option_list[active_index].picture_file_id &&
  21. pic_list[option_list[active_index].picture_file_id]
  22. "
  23. :src="pic_list[option_list[active_index].picture_file_id]"
  24. fit="contain"
  25. />
  26. <div class="words-right">
  27. <template v-for="(item, index) in option_list">
  28. <div v-if="index === active_index" :key="index" class="strock-box">
  29. <div v-if="item.hz_strokes_list && item.hz_strokes_list.length > 0" class="strock-left">
  30. <div v-for="(items, indexs) in item.hz_strokes_list" :key="indexs">
  31. <span class="pinyin">{{
  32. item.pinyin_list && item.pinyin_list[indexs] ? item.pinyin_list[indexs] : ''
  33. }}</span>
  34. <Strockplayredline
  35. v-if="items"
  36. :play-storkes="true"
  37. :book-text="items.hz"
  38. :target-div="'pre' + items.hz + indexs + active_index"
  39. :book-strokes="items.strokes"
  40. :class="['strock-chinese', indexs !== item.hz_strokes_list.length - 1 ? 'border-right-none' : '']"
  41. />
  42. </div>
  43. <div v-if="item.audio_file_id" class="pinyin-box">
  44. <AudioPlay v-if="item.audio_file_id" :file-id="item.audio_file_id" theme-color="white" />
  45. </div>
  46. </div>
  47. </div>
  48. </template>
  49. <el-divider />
  50. <div v-if="option_list[active_index]" class="content-box">
  51. <span
  52. v-if="
  53. option_list[active_index].definition_preview.length > 0 && option_list[active_index].definition_preview[0]
  54. "
  55. class="tips"
  56. >释义:</span
  57. >
  58. <p v-for="(itemd, indexd) in option_list[active_index].definition_preview" :key="indexd" class="definition">
  59. {{ itemd }}
  60. </p>
  61. <span v-if="option_list[active_index].collocation" class="tips">搭配:</span>
  62. <p v-if="option_list[active_index].collocation" class="definition">
  63. {{ option_list[active_index].collocation }}
  64. </p>
  65. <span
  66. v-if="
  67. option_list[active_index].example_sentence.length > 0 && option_list[active_index].example_sentence[0]
  68. "
  69. class="tips"
  70. >例句:</span
  71. >
  72. <template v-for="(iteme, indexe) in option_list[active_index].example_sentence">
  73. <p v-if="iteme.trim()" :key="indexe + iteme.trim()" class="example-sentence">
  74. <span>{{ computeOptionMethods[data.option_number_show_mode](indexe) }} </span>
  75. <span>{{ iteme }}</span>
  76. </p>
  77. </template>
  78. </div>
  79. <el-divider />
  80. <div v-if="answer.answer_list[active_index]" class="sound-box">
  81. <SoundRecordPreview
  82. :wav-blob.sync="answer.answer_list[active_index].audio_file_id"
  83. :type="'small'"
  84. :disabled="disabled"
  85. />
  86. </div>
  87. </div>
  88. <div v-if="option_list.length > 1" :class="['words-item']">
  89. <label
  90. v-for="(item, index) in option_list"
  91. :key="index"
  92. :class="[active_index === index ? 'active' : '']"
  93. @click="active_index = index"
  94. >{{ item.content }}</label
  95. >
  96. </div>
  97. </div>
  98. </div>
  99. </template>
  100. <script>
  101. import { computeOptionMethods } from '@/views/exercise_questions/data/common';
  102. import PreviewMixin from './components/PreviewMixin';
  103. import { GetFileStoreInfo } from '@/api/app';
  104. import SoundRecordPreview from './components/common/SoundRecordPreview.vue';
  105. import Strockplayredline from './components/common/Strockplayredline.vue';
  106. export default {
  107. name: 'WordCardPreview',
  108. components: { SoundRecordPreview, Strockplayredline },
  109. mixins: [PreviewMixin],
  110. data() {
  111. return {
  112. computeOptionMethods,
  113. hanzi_color: '#404040', // 描红汉字底色
  114. pic_list: {},
  115. active_index: 0,
  116. option_list: [],
  117. };
  118. },
  119. watch: {
  120. data: {
  121. handler(val) {
  122. if (!val || this.data.type !== 'word_card') return;
  123. this.handleData();
  124. },
  125. deep: true,
  126. immediate: true,
  127. },
  128. },
  129. created() {
  130. console.log(this.data);
  131. // this.handleData();
  132. },
  133. mounted() {},
  134. methods: {
  135. // 初始化数据
  136. handleData() {
  137. this.pic_list = {};
  138. this.data.file_id_list.forEach((item) => {
  139. GetFileStoreInfo({ file_id: item }).then(({ file_id, file_url }) => {
  140. this.$set(this.pic_list, file_id, file_url);
  141. });
  142. });
  143. let option_list = JSON.parse(JSON.stringify(this.data.option_list));
  144. option_list.forEach((item) => {
  145. let obj = {
  146. mark: item.mark,
  147. audio_file_id: '',
  148. };
  149. item.definition_preview = item.definition.split('\n');
  150. item.pinyin_list = item.pinyin.split(' ');
  151. if (!this.isJudgingRightWrong) {
  152. this.answer.answer_list.push(obj);
  153. }
  154. });
  155. this.option_list = option_list;
  156. },
  157. },
  158. };
  159. </script>
  160. <style lang="scss" scoped>
  161. @use '@/styles/mixin.scss' as *;
  162. .word-card-preview {
  163. @include preview;
  164. .words-box {
  165. display: flex;
  166. column-gap: 24px;
  167. .el-image {
  168. flex-shrink: 0;
  169. width: 346px;
  170. height: 346px;
  171. }
  172. .words-right {
  173. flex: 1;
  174. }
  175. .words-item {
  176. width: 120px;
  177. label {
  178. display: block;
  179. padding: 8px 16px;
  180. margin-bottom: 4px;
  181. font-size: 18px;
  182. font-weight: 400;
  183. line-height: 26px;
  184. color: rgba(0, 0, 0, 30%);
  185. cursor: pointer;
  186. border-radius: 20px;
  187. &.active {
  188. color: #fff;
  189. background: rgba(48, 110, 255, 100%);
  190. }
  191. }
  192. }
  193. .pinyin {
  194. display: block;
  195. font-family: 'League';
  196. font-size: 16px;
  197. font-weight: 500;
  198. color: #000;
  199. text-align: center;
  200. }
  201. .strock-chinese {
  202. width: 96px;
  203. height: 96px;
  204. border: 1px solid #e81b1b;
  205. :deep .strock-play-box {
  206. width: 16px;
  207. height: 16px;
  208. }
  209. }
  210. .border-right-none {
  211. border-right: none;
  212. }
  213. }
  214. .strock-left {
  215. display: flex;
  216. align-items: center;
  217. }
  218. .pinyin-box {
  219. display: flex;
  220. gap: 4px;
  221. align-items: center;
  222. width: max-content;
  223. height: 36px;
  224. padding: 4px 8px;
  225. margin-left: 16px;
  226. background: rgba(47, 111, 236, 100%);
  227. border-radius: 40px;
  228. :deep .audio-play {
  229. width: auto;
  230. height: 24px;
  231. background: none;
  232. }
  233. }
  234. .definition {
  235. margin: 0 0 8px;
  236. font-size: 16px;
  237. line-height: 24px;
  238. color: #000;
  239. }
  240. .tips {
  241. display: block;
  242. margin-bottom: 8px;
  243. font-size: 16px;
  244. font-weight: 400;
  245. line-height: 24px;
  246. color: rgba(0, 0, 0, 40%);
  247. }
  248. .example-sentence {
  249. margin: 0;
  250. font-size: 16px;
  251. line-height: 24px;
  252. color: #000;
  253. }
  254. .sound-box {
  255. width: max-content;
  256. padding: 8px;
  257. background: $content-color;
  258. border-radius: 40px;
  259. }
  260. .el-divider {
  261. margin: 16px 0;
  262. }
  263. }
  264. </style>