writeTable.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  1. <template>
  2. <div :class="['writeTable']" v-if="data">
  3. <div class="writeTop" :class="[data.fileList ? 'writeTop-nopadding' : '']">
  4. <template v-if="data.fileList">
  5. <UploadDrag
  6. :fileList="data.fileList"
  7. @changeFillId="changeFillId"
  8. v-if="data.fileList.length === 0"
  9. :disabled="is_preview"
  10. ></UploadDrag>
  11. <div class="item-image" v-else>
  12. <el-image
  13. style="width: 593px; height: 224px"
  14. :src="data.fileList[0].fileUrl"
  15. :preview-src-list="[data.fileList[0].fileUrl]"
  16. fit="cover"
  17. />
  18. <span v-if="!is_preview" class="item-image-del" @click="handleDeleteImg"><i class="el-icon-delete"></i></span>
  19. </div>
  20. <div class="item-info">
  21. <template v-if="data.hz_info.length === 1">
  22. <div class="item-info-left">
  23. <p v-if="dataConfig.wordPinyin || dataConfig.wordVoice" class="voice-box">
  24. <AudioPlay :file-id="audio_file" v-if="audio_file" />
  25. <span v-if="dataConfig.wordPinyin">{{ data.pinyin }}</span>
  26. </p>
  27. <div class="hz-box">
  28. <Strockplay
  29. className="adult-strockplay"
  30. :strokePlayColor="dataConfig.borderColor"
  31. :Book_text="itemh.con"
  32. :playStorkes="dataConfig.playStorkes"
  33. :strokeColor="dataConfig.fontColor"
  34. :palyWidth="dataConfig.playWidth"
  35. :BoxbgType="dataConfig.BoxbgType"
  36. :curItem="itemh.hzDetail.hz_json"
  37. :targetDiv="'writeTops-item-' + pageNumber + '-' + indexh + '-' + itemh.con"
  38. :fontSize="fontSize"
  39. :class="[indexh !== 0 ? 'writeTop-item-noLeft' : '']"
  40. class="writeTop-item"
  41. v-for="(itemh, indexh) in data.hz_info"
  42. :key="indexh"
  43. />
  44. </div>
  45. </div>
  46. <div class="item-info-right">
  47. <p class="voice-box" v-if="dataConfig.wordPinyin || dataConfig.wordVoice"></p>
  48. <div class="item-info-row">
  49. <div class="item-info-half">
  50. <label>偏旁:</label>
  51. <div :id="'character-target-info-div' + pageNumber"></div>
  52. </div>
  53. <div class="item-info-half">
  54. <label>笔画:</label>
  55. {{ data.hz_info[0].hzDetail.hz_json.medians.length }}
  56. </div>
  57. </div>
  58. <template v-if="is_preview">
  59. <div class="item-info-row">
  60. <div class="item-info-half">
  61. <label>释义:</label>
  62. {{ data.info.definition }}
  63. </div>
  64. <div class="item-info-half">
  65. <label>搭配:</label>
  66. {{ data.info.collocation }}
  67. </div>
  68. </div>
  69. <div class="item-info-row">
  70. <div class="item-info-all">{{ data.info.exampleSent }}</div>
  71. </div>
  72. </template>
  73. <template v-else>
  74. <div class="item-info-row">
  75. <el-input v-model="data.info.definition" placeholder="输入释义"></el-input>
  76. <el-input v-model="data.info.collocation" placeholder="输入搭配"></el-input>
  77. </div>
  78. <div class="item-info-row">
  79. <el-input v-model="data.info.exampleSent" placeholder="输入例句"></el-input>
  80. </div>
  81. </template>
  82. </div>
  83. </template>
  84. <template v-else>
  85. <div class="item-info-left item-info-left-long">
  86. <p v-if="dataConfig.wordPinyin || dataConfig.wordVoice" class="voice-box">
  87. <AudioPlay :file-id="audio_file" v-if="audio_file" />
  88. <span v-if="dataConfig.wordPinyin">{{ data.pinyin }}</span>
  89. </p>
  90. <div class="hz-box" :style="{ margin: '8px auto' }">
  91. <Strockplay
  92. className="adult-strockplay"
  93. :strokePlayColor="dataConfig.borderColor"
  94. :Book_text="itemh.con"
  95. :playStorkes="dataConfig.playStorkes"
  96. :strokeColor="dataConfig.fontColor"
  97. :palyWidth="dataConfig.playWidth"
  98. :BoxbgType="dataConfig.BoxbgType"
  99. :curItem="itemh.hzDetail.hz_json"
  100. :targetDiv="'writeTops-item-' + pageNumber + '-' + indexh + '-' + itemh.con"
  101. :fontSize="fontSize"
  102. :class="[indexh !== 0 ? 'writeTop-item-noLeft' : '']"
  103. class="writeTop-item writeTop-item-small"
  104. v-for="(itemh, indexh) in data.hz_info"
  105. :key="indexh"
  106. />
  107. </div>
  108. <template v-if="is_preview">
  109. <div class="item-info-row" :style="{ height: '48px' }">
  110. <div class="item-info-all">{{ data.info.definition }}</div>
  111. </div>
  112. </template>
  113. <el-input v-else type="textarea" v-model="data.info.definition" rows="2" placeholder="输入"></el-input>
  114. </div>
  115. </template>
  116. </div>
  117. </template>
  118. <div
  119. class="writeTop-row"
  120. v-for="(itemR, indexR) in data.list"
  121. :key="indexR"
  122. :style="{ marginBottom: dataConfig.marginBottom }"
  123. >
  124. <div
  125. class="writeTop-item"
  126. :class="[indexI !== 0 ? 'writeTop-item-noLeft' : '']"
  127. v-for="(itemI, indexI) in itemR"
  128. :key="indexI"
  129. :style="{
  130. width: dataConfig.width,
  131. height: dataConfig.width,
  132. borderColor: dataConfig.borderColor,
  133. }"
  134. >
  135. <template v-if="itemI && itemI.con && !itemI.write && !itemI.answer && !itemI.miaoRed">
  136. <Strockplay
  137. v-if="'writeTop-item-' + pageNumber + '-' + indexR + '-' + indexI + type + fontSize"
  138. className="adult-strockplay"
  139. :strokePlayColor="dataConfig.borderColor"
  140. :Book_text="itemI.con"
  141. :playStorkes="dataConfig.playStorkes"
  142. :strokeColor="dataConfig.fontColor"
  143. :palyWidth="dataConfig.playWidth"
  144. :BoxbgType="dataConfig.BoxbgType"
  145. :curItem="itemI.hzDetail"
  146. :targetDiv="'writeTop-item-' + pageNumber + '-' + indexR + '-' + indexI + type + itemI.con"
  147. :fontSize="fontSize"
  148. />
  149. </template>
  150. <template v-else-if="itemI && itemI.answer">
  151. <StrockplayredlineTable
  152. :Book_text="itemI.con"
  153. :playStorkes="false"
  154. :strokeColorgray="dataConfig.miaoRedBgcolor"
  155. :strokeColor="dataConfig.fontColor"
  156. :strokeNumber="itemI.answer"
  157. :curItem="itemI.hzDetail"
  158. :BoxbgType="dataConfig.BoxbgType"
  159. :targetDiv="'write-item-miaohong-' + pageNumber + '-' + indexR + '-' + indexI + type + itemI.con"
  160. :targetDivGray="'write-item-miaohong-gray-' + pageNumber + '-' + indexR + '-' + indexI + type + itemI.con"
  161. :fontSize="fontSize"
  162. />
  163. </template>
  164. <template v-else-if="itemI && itemI.miaoRed">
  165. <Strockred
  166. v-if="'write-item-' + pageNumber + '-' + indexR + '-' + indexI + type"
  167. className="adult-strockplay"
  168. :strokePlayColor="dataConfig.borderColor"
  169. :Book_text="itemI.con"
  170. :curItem="itemI.hzDetail"
  171. :hanzicolor="dataConfig.miaoRedBgcolor"
  172. :drawingColor="dataConfig.writeColor"
  173. :BoxbgType="dataConfig.BoxbgType"
  174. :targetDiv="'write-item-' + pageNumber + '-' + indexR + '-' + indexI + type + itemI.con"
  175. :fontSize="fontSize"
  176. />
  177. </template>
  178. <div v-else-if="itemI" class="tian-div" @click="freeWrite(itemI, indexR, indexI)">
  179. <svg-icon
  180. icon-class="tian"
  181. className="tian"
  182. v-if="dataConfig.BoxbgType == 0"
  183. :style="{ color: '#DEDEDE' }"
  184. />
  185. <svg-icon icon-class="mi" className="tian" v-if="dataConfig.BoxbgType == 1" :style="{ color: '#DEDEDE' }" />
  186. <img v-if="itemI && itemI.strokes_image_url" :src="itemI.strokes_image_url" alt="" />
  187. </div>
  188. </div>
  189. </div>
  190. </div>
  191. <div class="writeBottom">
  192. <span>BLCUP 全球国际中文教学云平台</span>
  193. <b>{{ pageNumber + '/' + totalNumber }}</b>
  194. <a>www.chinesedu.com</a>
  195. </div>
  196. <div class="practiceBox practiceBoxStrock" v-if="ifFreeShow">
  197. <FreewriteLettle
  198. :changePraShow="changePraShow"
  199. ref="freePaint"
  200. :currenHzData="currenHzData"
  201. :rowIndex="activeIndex"
  202. :colIndex="activeColIndex"
  203. :closeifFreeShow="closeifFreeShow"
  204. @ExerciseChangeCurQue="ExerciseChangeCurQue"
  205. :BoxbgType="dataConfig.BoxbgType"
  206. :lineColor="dataConfig.writeColor"
  207. />
  208. </div>
  209. </div>
  210. </template>
  211. <script>
  212. //这里可以导入其它文件(比如:组件,工具js,第三方插件js,json文件,图片文件等等)
  213. import StrockplayredlineTable from '../../components/corpus/StrockplayredlineTable.vue';
  214. import Strockplay from '../../components/corpus/Strockplay.vue';
  215. import Strockred from '../../components/corpus/Strockred.vue';
  216. import FreewriteLettle from '../../components/corpus/FreewriteLettle.vue';
  217. import UploadDrag from './UploadDrag.vue';
  218. import AudioPlay from './AudioPlay.vue';
  219. const HanziWriter = require('hanzi-writer');
  220. import { getLogin } from '@/api/api';
  221. export default {
  222. //import引入的组件需要注入到对象中才能使用
  223. components: {
  224. StrockplayredlineTable,
  225. Strockplay,
  226. Strockred,
  227. FreewriteLettle,
  228. UploadDrag,
  229. AudioPlay,
  230. },
  231. props: [
  232. 'dataConfig',
  233. 'data',
  234. 'pageNumber',
  235. 'totalNumber',
  236. 'type',
  237. 'none',
  238. 'fontSize',
  239. 'audio_file_obj',
  240. 'is_preview',
  241. ],
  242. data() {
  243. //这里存放数据
  244. return {
  245. ifFreeShow: false,
  246. activeIndex: null,
  247. activeColIndex: null,
  248. fileList: [],
  249. info: {
  250. definition: '',
  251. collocation: '',
  252. exampleSent: '',
  253. },
  254. writer: null,
  255. audio_file: '',
  256. };
  257. },
  258. //计算属性 类似于data概念
  259. computed: {},
  260. //监控data中数据变化
  261. watch: {
  262. pageNumber: {
  263. handler: function (val, oldVal) {
  264. if (val != oldVal) {
  265. let _this = this;
  266. _this.$nextTick(() => {
  267. if (_this.data.hz_info && _this.data.hz_info.length === 1) {
  268. _this.initHanziwrite();
  269. }
  270. });
  271. }
  272. },
  273. deep: true,
  274. },
  275. },
  276. //方法集合
  277. methods: {
  278. changePraShow() {
  279. this.ifFreeShow = false;
  280. },
  281. closeifFreeShow(data, rowIndex, colIndex) {
  282. this.ifFreeShow = false;
  283. this.$forceUpdate();
  284. },
  285. freeWrite(item, row, col) {
  286. this.ifFreeShow = true;
  287. this.activeIndex = row;
  288. this.activeColIndex = col;
  289. // this.currentHz = this.curQue.option[indexs].rightOption[rightindex].con;
  290. if (item) {
  291. this.currenHzData = item;
  292. } else {
  293. this.currenHzData = {};
  294. }
  295. },
  296. ExerciseChangeCurQue(answer, rowIndex, colIndex) {
  297. if (answer) {
  298. this.data.list[rowIndex][colIndex].strokes_image_url = answer.strokes_image_url;
  299. this.data.list[rowIndex][colIndex].history = answer.history;
  300. this.$forceUpdate();
  301. }
  302. },
  303. changeFillId(file, fileList) {
  304. let obj = {
  305. name: file.name,
  306. fileId: file.file_id,
  307. fileUrl: file.file_url_open,
  308. };
  309. this.data.fileList.push(obj);
  310. },
  311. handleDeleteImg() {
  312. this.data.fileList = [];
  313. },
  314. initHanziwrite() {
  315. let _this = this;
  316. let node = document.getElementById(`character-target-info-div` + _this.pageNumber);
  317. if (node && node.children.length > 1) {
  318. node.removeChild(node.children[1]);
  319. }
  320. //var ren = require("hanzi-writer-data/国");
  321. _this.writer = HanziWriter.default.create(
  322. `character-target-info-div` + _this.pageNumber,
  323. _this.data.hz_info[0].con,
  324. {
  325. width: 22,
  326. height: 22,
  327. padding: 0,
  328. radicalColor: '#000000',
  329. strokeColor: '#fff',
  330. },
  331. );
  332. },
  333. },
  334. //生命周期 - 创建完成(可以访问当前this实例)
  335. created() {
  336. if (this.data.pinyin) {
  337. let MethodName = 'tool-PinyinToVoiceFile';
  338. let datas = {
  339. pinyin: this.data.pinyin.split(' ').join(','),
  340. };
  341. getLogin(MethodName, datas).then((res) => {
  342. if (res.status === 1) {
  343. this.audio_file = res.file_id;
  344. }
  345. });
  346. }
  347. },
  348. //生命周期 - 挂载完成(可以访问DOM元素)
  349. mounted() {
  350. let _this = this;
  351. _this.$nextTick(() => {
  352. if (_this.data.hz_info && _this.data.hz_info.length === 1) {
  353. _this.initHanziwrite();
  354. }
  355. });
  356. },
  357. //生命周期-创建之前
  358. beforeCreated() {},
  359. //生命周期-挂载之前
  360. beforeMount() {},
  361. //生命周期-更新之前
  362. beforUpdate() {},
  363. //生命周期-更新之后
  364. updated() {},
  365. //生命周期-销毁之前
  366. beforeDestory() {},
  367. //生命周期-销毁完成
  368. destoryed() {},
  369. //如果页面有keep-alive缓存功能,这个函数会触发
  370. activated() {},
  371. };
  372. </script>
  373. <style lang="scss" scoped>
  374. .writeTable {
  375. background: #ffffff;
  376. border: 1px solid rgba(0, 0, 0, 0.08);
  377. width: 595px;
  378. height: 842px;
  379. box-sizing: border-box;
  380. .writeTop {
  381. height: 732px;
  382. padding-top: 48px;
  383. .item-image {
  384. position: relative;
  385. .item-image-del {
  386. position: absolute;
  387. top: 8px;
  388. right: 8px;
  389. width: 16px;
  390. height: 16px;
  391. display: block;
  392. cursor: pointer;
  393. background-color: #ffffff;
  394. color: #ee3232;
  395. padding: 8px;
  396. border-radius: 50%;
  397. box-shadow: 0px 4px 4px 0px rgba(0, 0, 0, 0.25);
  398. }
  399. }
  400. .writeTop-row {
  401. display: flex;
  402. justify-content: center;
  403. }
  404. }
  405. .writeTop-nopadding {
  406. padding-top: 0;
  407. height: 780px;
  408. }
  409. .item-info {
  410. display: flex;
  411. width: 100%;
  412. padding: 16px 46px;
  413. column-gap: 16px;
  414. box-sizing: border-box;
  415. &-left {
  416. .writeTop-item {
  417. width: 98px;
  418. height: 98px;
  419. :deep .strock-play-box {
  420. width: 18px !important;
  421. height: 18px !important;
  422. }
  423. :deep .playStorkes-btn {
  424. width: 18px !important;
  425. height: 18px !important;
  426. }
  427. &-small {
  428. width: 62px;
  429. height: 62px;
  430. :deep .strock-play-box {
  431. width: 11px !important;
  432. height: 11px !important;
  433. }
  434. :deep .playStorkes-btn {
  435. width: 11px !important;
  436. height: 11px !important;
  437. }
  438. }
  439. }
  440. &-long {
  441. width: 100%;
  442. }
  443. }
  444. &-right {
  445. flex: 1;
  446. }
  447. :deep .el-textarea__inner {
  448. resize: none;
  449. background-color: #f3f3f3;
  450. border: none;
  451. outline: none;
  452. }
  453. .voice-box {
  454. width: 100%;
  455. height: 32px;
  456. display: flex;
  457. align-items: center;
  458. justify-content: center;
  459. column-gap: 4px;
  460. img {
  461. width: 24px;
  462. height: 24px;
  463. }
  464. span {
  465. font-family: League;
  466. font-size: 16px;
  467. font-weight: 400;
  468. color: #de4444;
  469. }
  470. }
  471. .item-info-row {
  472. display: flex;
  473. column-gap: 11px;
  474. margin-bottom: 6px;
  475. :deep .el-input__inner {
  476. background-color: #f3f3f3;
  477. border: none;
  478. outline: none;
  479. height: 32px;
  480. }
  481. }
  482. .item-info-half,
  483. .item-info-all {
  484. width: 50%;
  485. display: flex;
  486. font-size: 14px;
  487. line-height: 22px;
  488. height: 22px;
  489. }
  490. .item-info-all {
  491. width: 100%;
  492. }
  493. }
  494. .hz-box {
  495. display: flex;
  496. width: max-content;
  497. }
  498. .writeTop-item {
  499. border: 1px solid #de4444;
  500. }
  501. .writeTop-item-noLeft {
  502. border-left: none;
  503. }
  504. .writeBottom {
  505. display: flex;
  506. width: 100%;
  507. justify-content: space-between;
  508. padding: 0 38px;
  509. box-sizing: border-box;
  510. position: relative;
  511. span {
  512. font-weight: 500;
  513. font-size: 10px;
  514. line-height: 14px;
  515. color: #000000;
  516. opacity: 0.2;
  517. }
  518. b {
  519. font-weight: 400;
  520. font-size: 14px;
  521. line-height: 14px;
  522. color: #000000;
  523. width: 60px;
  524. text-align: center;
  525. position: absolute;
  526. left: 50%;
  527. margin-left: -30px;
  528. top: 0px;
  529. }
  530. a {
  531. font-weight: 500;
  532. font-size: 12px;
  533. line-height: 14px;
  534. color: #000000;
  535. opacity: 0.2;
  536. }
  537. }
  538. .tian-div {
  539. width: 100%;
  540. height: 100%;
  541. position: relative;
  542. .tian {
  543. width: 100%;
  544. height: 100%;
  545. }
  546. img {
  547. width: 100%;
  548. height: 100%;
  549. position: absolute;
  550. left: 0;
  551. top: 0;
  552. }
  553. }
  554. .practiceBox {
  555. position: fixed;
  556. left: 0;
  557. top: 0;
  558. z-index: 100100;
  559. width: 100%;
  560. height: 100vh;
  561. background: rgba(0, 0, 0, 0.19);
  562. box-sizing: border-box;
  563. overflow: hidden;
  564. overflow-y: auto;
  565. &.practiceBoxStrock {
  566. display: flex;
  567. justify-content: center;
  568. align-items: center;
  569. padding-top: 0px;
  570. }
  571. }
  572. }
  573. </style>