CharacterPreview.vue 21 KB

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