ChinesePreview.vue 15 KB

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