WordCardPreview.vue 7.3 KB

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