ChinesePreview.vue 17 KB

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