WordDictationPreview.vue 9.6 KB

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