NewWordShow.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  1. <!-- -->
  2. <template>
  3. <div class="Big-Book-prev-Textdes NewWordShow" v-if="curQue">
  4. <h2 v-if="curQue.title">{{ curQue.title }}</h2>
  5. <div class="item-box">
  6. <div class="item-pre" v-for="(item, index) in curQue.option" :key="index">
  7. <div class="item" style="margin-right: 20px">
  8. <p v-if="item.pinyin || item.en">
  9. <span>{{ item.pinyin }}</span>
  10. <span>{{ item.en }}</span>
  11. </p>
  12. <div class="con-box">
  13. <template v-if="item.imgOrText == 'text'">
  14. <template v-if="item.con">
  15. <div
  16. :key="conindex"
  17. class="strockplay-newWord"
  18. v-for="(conItem, conindex) in item.con"
  19. @click="writeWord(conItem, item.pinyin)"
  20. >
  21. <Strockplayredline
  22. :Book_text="conItem"
  23. :playStorkes="true"
  24. :targetDiv="
  25. 'bwcHanziIntp' + index + conItem + conindex + indexStr
  26. "
  27. />
  28. <div
  29. class="bwc-line"
  30. v-if="conindex < item.con.length - 1"
  31. ></div>
  32. </div>
  33. </template>
  34. <template v-else>
  35. <div class="blank-item" @click="freeWrite('', index, 0)">
  36. <img :src="freeImg[index][0]" v-if="freeImg[index][0]" />
  37. </div>
  38. </template>
  39. </template>
  40. <template v-else>
  41. <div
  42. class="img-box"
  43. v-for="(imgItem, imgIndex) in item.img_list"
  44. :key="imgIndex"
  45. @click="freeWrite(imgItem.url, imgIndex, 0)"
  46. >
  47. <el-image :src="imgItem.url" fit="scale-down" class="img_url">
  48. <div slot="placeholder" class="image-slot">
  49. <img src="../../../assets/common/icon-imgloading.png" />
  50. </div>
  51. </el-image>
  52. </div>
  53. </template>
  54. </div>
  55. </div>
  56. <template v-if="item.type && item.type.indexOf('lm') > -1">
  57. <div
  58. class="con-box"
  59. v-for="(items, indexs) in item.imgarr"
  60. :key="indexs"
  61. >
  62. <div
  63. class="strockplay-newWord"
  64. @click="freeWrite(items, index, indexs + 1)"
  65. >
  66. <!-- <div
  67. @click.stop="playHanzi(index, indexs, items)"
  68. :class="[
  69. 'strock-play-box',
  70. themeColor == 'green'
  71. ? 'green-border'
  72. : themeColor == 'red'
  73. ? 'red-border'
  74. : themeColor == 'brown'
  75. ? 'brown-border'
  76. : 'red-border',
  77. ]"
  78. ></div> -->
  79. <img
  80. v-if="!playStatus && items.strokes_image_url"
  81. :src="items.strokes_image_url"
  82. alt=""
  83. />
  84. <!-- <FreeWriteQP
  85. :id="'cans' + index + indexs"
  86. :ref="'cans'"
  87. :height="256"
  88. :width="256"
  89. /> -->
  90. </div>
  91. </div>
  92. </template>
  93. </div>
  94. </div>
  95. <div class="practiceBox practiceBoxStrock" v-if="isPraShow">
  96. <Practice
  97. :changePraShow="changePraShow"
  98. :cur="curData"
  99. :themeColor="themeColor"
  100. />
  101. </div>
  102. <div class="practiceBox practiceBoxStrock" v-if="ifFreeShow">
  103. <FreewriteLettle
  104. :changePraShow="changePraShow"
  105. ref="freePaint"
  106. :themeColor="themeColor"
  107. :currentTreeID="currentTreeID"
  108. :currentHz="currentHz"
  109. :currenHzData="currenHzData"
  110. :rowIndex="activeIndex"
  111. :colIndex="activeColIndex"
  112. :closeifFreeShow="closeifFreeShow"
  113. />
  114. </div>
  115. </div>
  116. </template>
  117. <script>
  118. import Strockplayredline from "../preview/components/Strockplayredline.vue";
  119. import Practice from "../preview/components/Practice.vue";
  120. import FreewriteLettle from "../preview/components/FreewriteLettle.vue";
  121. import { getContentFile, LearnWebSI } from "@/api/ajax";
  122. import FreeWriteQP from "./components/FreeWriteQP.vue";
  123. export default {
  124. components: { Strockplayredline, Practice, FreewriteLettle, FreeWriteQP },
  125. props: ["curQue", "themeColor", "indexStr", "currentTreeID"],
  126. data() {
  127. return {
  128. isPraShow: false,
  129. curData: null,
  130. ifFreeShow: false,
  131. freeImg: [],
  132. activeIndex: null,
  133. activeColIndex: null,
  134. currentHz: "", //当前汉字
  135. currenHzData: null, //当前汉字数据
  136. playStatus: false, //播放状态
  137. };
  138. },
  139. computed: {},
  140. watch: {},
  141. //方法集合
  142. methods: {
  143. playHanzi(rowIndex, colIndex, item) {
  144. if (this.playStatus) {
  145. this.$message.warning("请等待播放完成");
  146. return;
  147. }
  148. this.playStatus = true;
  149. console.log(this.$refs.cans);
  150. let ref = null;
  151. this.$refs.cans.forEach((item) => {
  152. if (item.$el.id == `cans${rowIndex}${colIndex}`) {
  153. ref = item;
  154. }
  155. });
  156. ref.reset();
  157. let c = document.getElementById(`cans${rowIndex}${colIndex}`);
  158. let cxt = document
  159. .getElementById(`cans${rowIndex}${colIndex}`)
  160. .getContext("2d");
  161. cxt.clearRect(0, 0, c.width, c.height);
  162. let history = item.history;
  163. const len = item.history.length;
  164. let i = 0;
  165. const runner = () => {
  166. i++;
  167. if (i < len) {
  168. ref.draw(null, history[i][0], history[i][1]);
  169. requestAnimationFrame(runner);
  170. } else {
  171. console.log("播放完成");
  172. this.playStatus = false;
  173. }
  174. };
  175. requestAnimationFrame(runner);
  176. },
  177. // 处理数据
  178. handleData() {
  179. let _this = this;
  180. let MethodName = "teaching-practice_manager-GetMyHZHandwrittenRecordList";
  181. this.curQue.option.forEach((item, index) => {
  182. let data = {
  183. courseware_id: this.currentTreeID,
  184. hz: item.con,
  185. search_scope: 1,
  186. count_limit: 6,
  187. };
  188. LearnWebSI(MethodName, data).then((res) => {
  189. let imgarr = res.hz_handwritten_record_list;
  190. let newimgarr = imgarr.map((it) => {
  191. it.history = JSON.parse(it.strokes_content);
  192. return it;
  193. });
  194. if (newimgarr.length < 6) {
  195. let num = 6 - newimgarr.length;
  196. for (let i = 0; i < num; i++) {
  197. newimgarr.push({});
  198. }
  199. }
  200. item.imgarr = newimgarr;
  201. if (index == this.curQue.option.length - 1) {
  202. this.$forceUpdate();
  203. }
  204. });
  205. });
  206. },
  207. changePraShow() {
  208. this.isPraShow = false;
  209. this.ifFreeShow = false;
  210. // this.freeImg[this.activeIndex][this.activeColIndex] =
  211. // this.$refs.freePaint.imgSrc;
  212. },
  213. async writeWord(words, pinyin) {
  214. this.activeIndex = null;
  215. this.activeColIndex = null;
  216. const MethodName = "tool-ChineseSCConvert";
  217. const data = {
  218. text: words,
  219. swap_mode: "S-C",
  220. };
  221. let TChinese = await getContentFile(MethodName, data);
  222. this.curData = {
  223. stem: [
  224. {
  225. con: words ? words : "",
  226. pinyin: pinyin && pinyin ? pinyin : "",
  227. mp3_url: "",
  228. TChinese: TChinese.text,
  229. },
  230. ],
  231. };
  232. this.isPraShow = true;
  233. },
  234. closeifFreeShow(data, rowIndex, colIndex) {
  235. this.curQue.option[rowIndex].imgarr[colIndex - 1] = data;
  236. this.ifFreeShow = false;
  237. this.freeWrite(data, rowIndex, colIndex);
  238. this.$forceUpdate();
  239. },
  240. freeWrite(imgUrl, index, indexs) {
  241. this.ifFreeShow = true;
  242. this.activeIndex = index;
  243. this.activeColIndex = indexs;
  244. this.currentHz = this.curQue.option[index].con;
  245. this.currenHzData = imgUrl;
  246. console.log(this.currenHzData);
  247. },
  248. },
  249. //生命周期 - 创建完成(可以访问当前this实例)
  250. created() {
  251. this.handleData();
  252. },
  253. //生命周期 - 挂载完成(可以访问DOM元素)
  254. mounted() {},
  255. beforeCreate() {}, //生命周期 - 创建之前
  256. beforeMount() {}, //生命周期 - 挂载之前
  257. beforeUpdate() {}, //生命周期 - 更新之前
  258. updated() {}, //生命周期 - 更新之后
  259. beforeDestroy() {}, //生命周期 - 销毁之前
  260. destroyed() {}, //生命周期 - 销毁完成
  261. activated() {}, //如果页面有keep-alive缓存功能,这个函数会触发
  262. };
  263. </script>
  264. <style lang='scss' scoped>
  265. //@import url(); 引入公共css类
  266. .NewWordShow {
  267. width: 100%;
  268. margin-bottom: 24px;
  269. h2 {
  270. margin: 0 0 8px 0;
  271. font-weight: 500;
  272. font-size: 16px;
  273. line-height: 24px;
  274. color: #000000;
  275. }
  276. .item-box {
  277. padding-bottom: 8px;
  278. padding: 0 4px;
  279. background: #f7f7f7;
  280. border: 1px solid rgba(0, 0, 0, 0.1);
  281. border-radius: 8px;
  282. .item-pre {
  283. display: flex;
  284. flex-flow: wrap;
  285. align-items: flex-end;
  286. padding: 9px 20px;
  287. }
  288. .item {
  289. box-sizing: border-box;
  290. // width: 66px;
  291. cursor: pointer;
  292. > p {
  293. white-space: nowrap;
  294. :nth-child(1) {
  295. font-family: "GB-PINYINOK-B";
  296. }
  297. :nth-child(2) {
  298. font-family: "robot";
  299. margin-left: 4px;
  300. }
  301. color: #2c2c2c;
  302. font-size: 14px;
  303. line-height: 130%;
  304. text-align: center;
  305. margin: 0 0 8px 0;
  306. }
  307. .strockplay {
  308. display: flex;
  309. justify-content: center;
  310. align-items: center;
  311. position: relative;
  312. width: 64px;
  313. height: 64px;
  314. }
  315. .strockplayRedInner {
  316. width: 64px;
  317. height: 64px;
  318. }
  319. .bwc-line {
  320. width: 1px;
  321. height: 62px;
  322. background: #de4444;
  323. }
  324. }
  325. .con-box {
  326. width: 66px;
  327. display: flex;
  328. border: 1px solid #de4444;
  329. border-radius: 8px;
  330. overflow: hidden;
  331. margin: 0 auto;
  332. .img-box {
  333. background: #fff url("../../../assets/NPC/chinaTianRed.png") center
  334. no-repeat;
  335. background-size: cover;
  336. .img_url {
  337. width: 64px;
  338. height: 64px;
  339. }
  340. }
  341. }
  342. .strockplay-newWord {
  343. width: 64px;
  344. height: 64px;
  345. background: #fff url("../../../assets/NPC/chinaTianRed.png") center
  346. no-repeat;
  347. background-size: cover;
  348. position: relative;
  349. .strock-play-box {
  350. position: absolute;
  351. cursor: pointer;
  352. }
  353. canvas {
  354. width: 64px;
  355. height: 64px;
  356. }
  357. img {
  358. width: 100%;
  359. height: 100%;
  360. }
  361. }
  362. }
  363. .practiceBox {
  364. position: fixed;
  365. left: 0;
  366. top: 0;
  367. z-index: 1000;
  368. width: 100%;
  369. height: 100vh;
  370. background: rgba(0, 0, 0, 0.19);
  371. box-sizing: border-box;
  372. overflow: hidden;
  373. overflow-y: auto;
  374. &.practiceBoxStrock {
  375. display: flex;
  376. justify-content: center;
  377. align-items: center;
  378. padding-top: 0px;
  379. }
  380. }
  381. }
  382. .NPC-Big-Book-preview-brown {
  383. .NewWordShow {
  384. .item-box {
  385. .item {
  386. .bwc-line {
  387. background: #bf875e;
  388. }
  389. }
  390. .con-box {
  391. border: 1px solid #bf875e;
  392. .img-box {
  393. background: #fff url("../../../assets/NPC/chinaTianYellow.png") center
  394. no-repeat;
  395. background-size: cover;
  396. }
  397. .blank-item {
  398. background: #fff url("../../../assets/NPC/chinaTianYellow.png") center
  399. no-repeat;
  400. background-size: cover;
  401. }
  402. }
  403. }
  404. }
  405. }
  406. .NPC-Big-Book-preview-green {
  407. .NewWordShow {
  408. .item-box {
  409. .item {
  410. .bwc-line {
  411. background: #24b99e;
  412. }
  413. }
  414. .con-box {
  415. border: 1px solid #24b99e;
  416. .img-box {
  417. background: #fff url("../../../assets/NPC/chinaTianGreen.png") center
  418. no-repeat;
  419. background-size: cover;
  420. }
  421. .blank-item {
  422. background: #fff url("../../../assets/NPC/chinaTianGreen.png") center
  423. no-repeat;
  424. background-size: cover;
  425. }
  426. }
  427. }
  428. }
  429. }
  430. </style>
  431. <style lang="scss">
  432. .NPC-Big-Book-preview-red {
  433. .strockplay-newWord {
  434. .strock-play-box {
  435. width: 16px !important;
  436. height: 16px !important;
  437. right: -1px;
  438. top: 0;
  439. background: url("../../../assets/NPC/strock-play-red-click.png") center
  440. no-repeat;
  441. background-size: cover;
  442. }
  443. .character-target-div {
  444. // background-color: initial;
  445. }
  446. }
  447. }
  448. .NPC-Big-Book-preview-green {
  449. .strockplay-newWord {
  450. .strock-play-box {
  451. width: 16px !important;
  452. height: 16px !important;
  453. right: -1px;
  454. top: 0;
  455. background: url("../../../assets/NPC/strock-play-green-click.png") center
  456. no-repeat;
  457. background-size: cover;
  458. }
  459. .character-target-div {
  460. // background-color: initial;
  461. }
  462. }
  463. }
  464. .NPC-Big-Book-preview-brown {
  465. .strockplay-newWord {
  466. .strock-play-box {
  467. width: 16px !important;
  468. height: 16px !important;
  469. right: -1px;
  470. top: 0;
  471. background: url("../../../assets/NPC/strock-play-yellow-click.png") center
  472. no-repeat;
  473. background-size: cover;
  474. }
  475. .character-target-div {
  476. // background-color: initial;
  477. }
  478. }
  479. }
  480. </style>