WritePreview.vue 19 KB

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