WordDictationPreview.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  1. <!-- eslint-disable vue/no-v-html -->
  2. <template>
  3. <div v-if="show_preview" class="chinese-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', 'words-box-dictation']">
  17. <div v-for="(item, index) in option_list" :key="index" :class="['words-item']">
  18. <div class="card-box">
  19. <div class="words-info">
  20. <span>{{ computeOptionMethods[data.option_number_show_mode](index) }} </span>
  21. <AudioPlay v-if="item.audio_file_id" :file-id="item.audio_file_id" theme-color="white" />
  22. </div>
  23. <div class="words-dic-box">
  24. <div v-for="(itemc, indexc) in item.imgArr" :key="indexc" class="words-dic-item">
  25. <span class="pinyin">{{ item.pinyin_arr[indexc].pinyin_item }}</span>
  26. <div
  27. :class="['strockplay-newWord']"
  28. @click="freeWrite(itemc ? JSON.parse(itemc) : itemc, index, indexc, item.mark)"
  29. >
  30. <SvgIcon icon-class="hanzi-writer-bg" class="character-target-bg" />
  31. <img
  32. v-if="!play_status && itemc && JSON.parse(itemc).strokes_image"
  33. class="hanzi-writer-img"
  34. :src="JSON.parse(itemc).strokes_image"
  35. alt=""
  36. />
  37. </div>
  38. </div>
  39. </div>
  40. </div>
  41. </div>
  42. </div>
  43. <div v-if="if_free_show" class="practiceBox practice-box-strock">
  44. <FreewriteLettle
  45. ref="freePaint"
  46. :current-tree-i-d="'1234456'"
  47. :current-hz="current_hz"
  48. :curren-hz-data="current_hz_data"
  49. :row-index="active_index"
  50. :col-index="active_col_index"
  51. :disabled="disabled"
  52. @closeIfFreeShow="closeIfFreeShow"
  53. @changePraShow="changePraShow"
  54. @changeCurQue="changeCurQue"
  55. @deleteWriteRecord="deleteWriteRecord"
  56. />
  57. </div>
  58. </div>
  59. </template>
  60. <script>
  61. import { computeOptionMethods } from '@/views/exercise_questions/data/common';
  62. import PreviewMixin from './components/PreviewMixin';
  63. import FreewriteLettle from './components/common/FreewriteLettle.vue';
  64. export default {
  65. name: 'WordDictationPreview',
  66. components: {
  67. FreewriteLettle,
  68. },
  69. mixins: [PreviewMixin],
  70. data() {
  71. return {
  72. computeOptionMethods,
  73. hanzi_color: '#404040', // 描红汉字底色
  74. if_free_show: false,
  75. free_img: [],
  76. active_index: null,
  77. active_col_index: null,
  78. current_hz: '', // 当前汉字
  79. current_hz_data: null, // 当前汉字数据
  80. play_status: false, // 播放状态
  81. hz_data: [
  82. '你',
  83. '最',
  84. '近',
  85. '怎',
  86. '么',
  87. '样',
  88. '我',
  89. '很',
  90. '好',
  91. '再',
  92. '见',
  93. '吃',
  94. '饭',
  95. '天',
  96. '启',
  97. '扫',
  98. '描',
  99. '以',
  100. '平',
  101. '太',
  102. '效',
  103. '国',
  104. '是',
  105. '称',
  106. '需',
  107. '值',
  108. '复',
  109. '包',
  110. '头',
  111. '条',
  112. '够',
  113. '关',
  114. '放',
  115. '发',
  116. '补',
  117. '快',
  118. '素',
  119. ],
  120. active_mark: '',
  121. option_list: [],
  122. show_preview: false,
  123. miao_arr: [],
  124. };
  125. },
  126. watch: {
  127. data: {
  128. handler(val) {
  129. if (!val || this.data.type !== 'word_dictation') return;
  130. this.handleData();
  131. },
  132. deep: true,
  133. immediate: true,
  134. },
  135. isJudgingRightWrong: {
  136. handler(val) {
  137. if (!val) return;
  138. this.handleData();
  139. },
  140. immediate: true,
  141. },
  142. },
  143. created() {
  144. // this.handleData();
  145. },
  146. mounted() {},
  147. methods: {
  148. // 初始化数据
  149. handleData() {
  150. if (!this.isJudgingRightWrong) {
  151. this.answer.answer_list = [];
  152. }
  153. this.show_preview = false;
  154. let option_list = JSON.parse(JSON.stringify(this.data)).option_list;
  155. this.miao_arr = [];
  156. option_list.forEach((item, index) => {
  157. let arr = [];
  158. this.miao_arr.push([]);
  159. item.pinyin_arr = [];
  160. let pinyin_arr = item.pinyin.trim().split(' ');
  161. pinyin_arr.forEach((itemp) => {
  162. let obj = {
  163. pinyin_item: itemp,
  164. };
  165. arr.push(null);
  166. item.pinyin_arr.push(obj);
  167. });
  168. if (this.isJudgingRightWrong) {
  169. item.imgArr = this.answer.answer_list[index].strokes_content_list;
  170. } else {
  171. item.imgArr = arr;
  172. }
  173. let obj = {
  174. mark: item.mark,
  175. strokes_content_list: arr,
  176. };
  177. if (!this.isJudgingRightWrong) {
  178. this.answer.answer_list.push(obj);
  179. }
  180. });
  181. this.option_list = option_list;
  182. this.show_preview = true;
  183. },
  184. changePraShow() {
  185. this.if_free_show = false;
  186. },
  187. closeIfFreeShow(data, rowIndex, colIndex, mark) {
  188. this.option_list[rowIndex].imgArr[colIndex] = JSON.stringify(data);
  189. this.if_free_show = false;
  190. this.freeWrite(data, rowIndex, colIndex, mark);
  191. this.$forceUpdate();
  192. },
  193. freeWrite(imgUrl, index, indexs, mark) {
  194. this.if_free_show = true;
  195. this.active_index = index;
  196. this.active_col_index = indexs;
  197. this.active_mark = mark;
  198. this.current_hz = this.hz_data[index];
  199. this.current_hz_data = imgUrl;
  200. },
  201. // 删除记录
  202. deleteWriteRecord(rowIndex, colIndex) {
  203. this.$set(this.option_list[rowIndex].imgArr, colIndex, JSON.stringify({}));
  204. this.changeCurQue(null, colIndex, this.active_mark);
  205. this.current_hz_data = null;
  206. this.active_mark = '';
  207. this.$forceUpdate();
  208. },
  209. changeCurQue(answer, colIndex, mark) {
  210. if (answer) {
  211. let write_model = [];
  212. this.answer.answer_list.forEach((itema) => {
  213. if (itema.mark === mark) {
  214. write_model = itema.strokes_content_list;
  215. }
  216. });
  217. write_model[colIndex] = JSON.stringify(answer);
  218. }
  219. },
  220. },
  221. };
  222. </script>
  223. <style lang="scss" scoped>
  224. @use '@/styles/mixin.scss' as *;
  225. .chinese-preview {
  226. @include preview;
  227. .words-box {
  228. .words-item {
  229. // display: flex;
  230. // flex-wrap: wrap;
  231. min-width: 64px;
  232. margin-bottom: 24px;
  233. }
  234. .words-top {
  235. display: flex;
  236. width: 100%;
  237. min-height: 30px;
  238. border: 1px solid #e81b1b;
  239. .words-left {
  240. box-sizing: border-box;
  241. display: flex;
  242. column-gap: 4px;
  243. align-items: center;
  244. justify-content: center;
  245. width: 64px;
  246. margin-right: 12px;
  247. border-right: 1px solid #e81b1b;
  248. }
  249. .words-right {
  250. padding: 8px 4px;
  251. margin: 0;
  252. font-size: 14px;
  253. line-height: 14px;
  254. color: #000;
  255. }
  256. }
  257. .audio-wrapper {
  258. height: 16px;
  259. :deep .audio-play {
  260. width: 16px;
  261. height: 16px;
  262. color: #000;
  263. background-color: initial;
  264. }
  265. :deep .audio-play.not-url {
  266. color: #a1a1a1;
  267. }
  268. :deep .voice-play {
  269. width: 16px;
  270. height: 16px;
  271. }
  272. }
  273. .words-info {
  274. display: flex;
  275. column-gap: 4px;
  276. align-items: center;
  277. justify-content: center;
  278. width: max-content;
  279. padding: 5px 16px;
  280. margin: 0 auto 8px;
  281. font-size: 14px;
  282. line-height: 22px;
  283. color: #fff;
  284. background: #165dff;
  285. border-radius: 20px;
  286. .pinyin {
  287. font-size: 14px;
  288. color: #fff;
  289. }
  290. .audio-wrapper {
  291. :deep .audio-play {
  292. color: #fff;
  293. }
  294. :deep .audio-play.not-url {
  295. color: #a1a1a1;
  296. }
  297. }
  298. }
  299. .card-box {
  300. display: flex;
  301. flex-wrap: wrap;
  302. }
  303. .pinyin {
  304. font-family: 'League';
  305. font-size: 12px;
  306. font-weight: 500;
  307. color: #000;
  308. }
  309. .strock-chinese {
  310. border: 1px solid #e81b1b;
  311. border-top: none;
  312. }
  313. .strockplay-newWord {
  314. position: relative;
  315. box-sizing: border-box;
  316. flex-shrink: 0;
  317. width: 64px;
  318. height: 64px;
  319. border: 1px solid #e81b1b;
  320. border-top: none;
  321. .character-target-bg,
  322. .hanzi-writer-img {
  323. position: absolute;
  324. top: 0;
  325. left: 0;
  326. width: 100%;
  327. height: 100%;
  328. color: #dedede;
  329. }
  330. .hanzi-writer-img {
  331. z-index: 1;
  332. }
  333. }
  334. .border-left-none {
  335. border-left: none;
  336. }
  337. .border-right-none {
  338. border-right: none;
  339. }
  340. &-learn {
  341. display: flex;
  342. column-gap: 24px;
  343. .words-item {
  344. display: block;
  345. }
  346. }
  347. }
  348. .words-box-dictation {
  349. display: flex;
  350. flex-wrap: wrap;
  351. column-gap: 24px;
  352. .card-box {
  353. display: block;
  354. }
  355. .words-dic-box {
  356. display: flex;
  357. column-gap: 6px;
  358. width: max-content;
  359. margin: 0 auto;
  360. }
  361. .words-dic-item {
  362. text-align: center;
  363. .pinyin {
  364. line-height: 30px;
  365. }
  366. }
  367. }
  368. .words-dic-item {
  369. .strockplay-newWord {
  370. border-top: 1px solid #e81b1b;
  371. }
  372. }
  373. .practiceBox {
  374. position: fixed;
  375. top: 0;
  376. left: 0;
  377. z-index: 101;
  378. box-sizing: border-box;
  379. width: 100%;
  380. height: 100vh;
  381. overflow: hidden;
  382. overflow-y: auto;
  383. background: rgba(0, 0, 0, 19%);
  384. &.practice-box-strock {
  385. display: flex;
  386. align-items: center;
  387. justify-content: center;
  388. padding-top: 0;
  389. }
  390. }
  391. }
  392. </style>