NewWordShow.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542
  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)"
  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 && 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. :TaskModel="TaskModel"
  114. @changeCurQue="changeCurQue"
  115. @deleteWriteRecord="deleteWriteRecord"
  116. />
  117. </div>
  118. </div>
  119. </template>
  120. <script>
  121. import Strockplayredline from "../preview/components/Strockplayredline.vue";
  122. import Practice from "../preview/components/Practice.vue";
  123. import FreewriteLettle from "../preview/components/FreewriteLettle.vue";
  124. import { getContentFile, LearnWebSI } from "../../../api/ajax";
  125. import FreeWriteQP from "./components/FreeWriteQP.vue";
  126. export default {
  127. components: { Strockplayredline, Practice, FreewriteLettle, FreeWriteQP },
  128. props: ["curQue", "themeColor", "indexStr", "currentTreeID", "TaskModel"],
  129. data() {
  130. return {
  131. isPraShow: false,
  132. curData: null,
  133. ifFreeShow: false,
  134. freeImg: [],
  135. activeIndex: null,
  136. activeColIndex: null,
  137. currentHz: "", //当前汉字
  138. currenHzData: null, //当前汉字数据
  139. playStatus: false, //播放状态
  140. userAnswer: {
  141. writeModel: {}, //生词/取词模式
  142. },
  143. };
  144. },
  145. computed: {},
  146. watch: {},
  147. //方法集合
  148. methods: {
  149. playHanzi(rowIndex, colIndex, item) {
  150. if (this.playStatus) {
  151. this.$message.warning("请等待播放完成");
  152. return;
  153. }
  154. this.playStatus = true;
  155. console.log(this.$refs.cans);
  156. let ref = null;
  157. this.$refs.cans.forEach((item) => {
  158. if (item.$el.id == `cans${rowIndex}${colIndex}`) {
  159. ref = item;
  160. }
  161. });
  162. ref.reset();
  163. let c = document.getElementById(`cans${rowIndex}${colIndex}`);
  164. let cxt = document
  165. .getElementById(`cans${rowIndex}${colIndex}`)
  166. .getContext("2d");
  167. cxt.clearRect(0, 0, c.width, c.height);
  168. let history = item.history;
  169. const len = item.history.length;
  170. let i = 0;
  171. const runner = () => {
  172. i++;
  173. if (i < len) {
  174. ref.draw(null, history[i][0], history[i][1]);
  175. requestAnimationFrame(runner);
  176. } else {
  177. console.log("播放完成");
  178. this.playStatus = false;
  179. }
  180. };
  181. requestAnimationFrame(runner);
  182. },
  183. // 处理数据
  184. handleData() {
  185. let _this = this;
  186. let MethodName = "teaching-practice_manager-GetMyHZHandwrittenRecordList";
  187. this.curQue.option.forEach((item, index) => {
  188. let data = {
  189. courseware_id: this.currentTreeID,
  190. hz: item.con,
  191. search_scope: 1,
  192. count_limit: 6,
  193. };
  194. LearnWebSI(MethodName, data).then((res) => {
  195. let imgarr = res.hz_handwritten_record_list;
  196. let newimgarr = imgarr.map((it) => {
  197. it.history = JSON.parse(it.strokes_content);
  198. return it;
  199. });
  200. if (newimgarr.length < 6) {
  201. let num = 6 - newimgarr.length;
  202. for (let i = 0; i < num; i++) {
  203. newimgarr.push({});
  204. }
  205. }
  206. item.imgarr = newimgarr;
  207. this.$forceUpdate();
  208. });
  209. });
  210. },
  211. // 处理数据
  212. handleAnswerData() {
  213. let _this = this;
  214. _this.curQue.option.forEach((item, index) => {
  215. let con = item.con;
  216. let arr = [];
  217. if (
  218. _this.curQue.Bookanswer.writeModel &&
  219. _this.curQue.Bookanswer.writeModel[con]
  220. ) {
  221. arr = _this.curQue.Bookanswer.writeModel[con].map((it) => {
  222. if (it && it.strokes_content) {
  223. it.history = JSON.parse(it.strokes_content);
  224. }
  225. return it;
  226. });
  227. } else {
  228. arr = [null, null, null, null, null, null];
  229. }
  230. item.imgarr = arr;
  231. });
  232. console.log(_this.curQue.option);
  233. },
  234. changePraShow() {
  235. this.isPraShow = false;
  236. this.ifFreeShow = false;
  237. // this.freeImg[this.activeIndex][this.activeColIndex] =
  238. // this.$refs.freePaint.imgSrc;
  239. },
  240. async writeWord(words, pinyin) {
  241. this.activeIndex = null;
  242. this.activeColIndex = null;
  243. const MethodName = "tool-ChineseSCConvert";
  244. const data = {
  245. text: words,
  246. swap_mode: "S-C",
  247. };
  248. let TChinese = await getContentFile(MethodName, data);
  249. this.curData = {
  250. stem: [
  251. {
  252. con: words ? words : "",
  253. pinyin: pinyin && pinyin ? pinyin : "",
  254. mp3_url: "",
  255. TChinese: TChinese.text,
  256. },
  257. ],
  258. };
  259. this.isPraShow = true;
  260. },
  261. closeifFreeShow(data, rowIndex, colIndex) {
  262. this.curQue.option[rowIndex].imgarr[colIndex] = data;
  263. this.ifFreeShow = false;
  264. this.freeWrite(data, rowIndex, colIndex);
  265. this.$forceUpdate();
  266. },
  267. freeWrite(imgUrl, index, indexs) {
  268. let _this = this;
  269. if (_this.TaskModel == "ANSWER" && !imgUrl) {
  270. return;
  271. }
  272. _this.ifFreeShow = true;
  273. _this.activeIndex = index;
  274. _this.activeColIndex = indexs;
  275. _this.currentHz = _this.curQue.option[index].con;
  276. _this.currenHzData = imgUrl;
  277. //console.log(this.currenHzData);
  278. },
  279. //删除记录
  280. deleteWriteRecord(rowIndex, colIndex) {
  281. this.$set(this.curQue.option[rowIndex].imgarr, colIndex, {});
  282. },
  283. changeCurQue(answer, colIndex) {
  284. if (answer) {
  285. let writeModel = this.curQue.Bookanswer.writeModel;
  286. let hz = answer.hz;
  287. if (writeModel.hasOwnProperty(hz)) {
  288. writeModel[hz][colIndex] = answer;
  289. } else {
  290. writeModel[hz] = [];
  291. for (let i = 0; i < 6; i++) {
  292. writeModel[hz].push(null);
  293. }
  294. writeModel[hz][colIndex] = answer;
  295. }
  296. console.log(this.curQue.Bookanswer);
  297. }
  298. },
  299. },
  300. //生命周期 - 创建完成(可以访问当前this实例)
  301. created() {
  302. let _this = this;
  303. if (!_this.curQue.Bookanswer) {
  304. _this.curQue.Bookanswer = JSON.parse(JSON.stringify(_this.userAnswer));
  305. }
  306. if (_this.TaskModel != "ANSWER") {
  307. _this.handleData();
  308. } else {
  309. _this.handleAnswerData();
  310. }
  311. },
  312. //生命周期 - 挂载完成(可以访问DOM元素)
  313. mounted() {},
  314. beforeCreate() {}, //生命周期 - 创建之前
  315. beforeMount() {}, //生命周期 - 挂载之前
  316. beforeUpdate() {}, //生命周期 - 更新之前
  317. updated() {}, //生命周期 - 更新之后
  318. beforeDestroy() {}, //生命周期 - 销毁之前
  319. destroyed() {}, //生命周期 - 销毁完成
  320. activated() {}, //如果页面有keep-alive缓存功能,这个函数会触发
  321. };
  322. </script>
  323. <style lang='scss' scoped>
  324. //@import url(); 引入公共css类
  325. .NewWordShow {
  326. width: 100%;
  327. margin-bottom: 24px;
  328. h2 {
  329. margin: 0 0 8px 0;
  330. font-weight: 500;
  331. font-size: 16px;
  332. line-height: 24px;
  333. color: #000000;
  334. }
  335. .item-box {
  336. padding-bottom: 8px;
  337. padding: 0 4px;
  338. background: #f7f7f7;
  339. border: 1px solid rgba(0, 0, 0, 0.1);
  340. border-radius: 8px;
  341. .item-pre {
  342. display: flex;
  343. flex-flow: wrap;
  344. align-items: flex-end;
  345. padding: 9px 20px;
  346. }
  347. .item {
  348. box-sizing: border-box;
  349. // width: 66px;
  350. cursor: pointer;
  351. > p {
  352. white-space: nowrap;
  353. :nth-child(1) {
  354. font-family: "GB-PINYINOK-B";
  355. }
  356. :nth-child(2) {
  357. font-family: "robot";
  358. margin-left: 4px;
  359. }
  360. color: #2c2c2c;
  361. font-size: 14px;
  362. line-height: 130%;
  363. text-align: center;
  364. margin: 0 0 8px 0;
  365. }
  366. .strockplay {
  367. display: flex;
  368. justify-content: center;
  369. align-items: center;
  370. position: relative;
  371. width: 64px;
  372. height: 64px;
  373. }
  374. .strockplayRedInner {
  375. width: 64px;
  376. height: 64px;
  377. }
  378. .bwc-line {
  379. width: 1px;
  380. height: 62px;
  381. background: #de4444;
  382. }
  383. }
  384. .con-box {
  385. width: 66px;
  386. display: flex;
  387. border: 1px solid #de4444;
  388. border-radius: 8px;
  389. overflow: hidden;
  390. margin: 0 auto;
  391. .img-box {
  392. background: #fff url("../../../assets/NPC/chinaTianRed.png") center
  393. no-repeat;
  394. background-size: cover;
  395. .img_url {
  396. width: 64px;
  397. height: 64px;
  398. }
  399. }
  400. }
  401. .strockplay-newWord {
  402. width: 64px;
  403. height: 64px;
  404. background: #fff url("../../../assets/NPC/chinaTianRed.png") center
  405. no-repeat;
  406. background-size: cover;
  407. position: relative;
  408. .strock-play-box {
  409. position: absolute;
  410. cursor: pointer;
  411. }
  412. canvas {
  413. width: 64px;
  414. height: 64px;
  415. }
  416. img {
  417. width: 100%;
  418. height: 100%;
  419. }
  420. }
  421. }
  422. .practiceBox {
  423. position: fixed;
  424. left: 0;
  425. top: 0;
  426. z-index: 1000;
  427. width: 100%;
  428. height: 100vh;
  429. background: rgba(0, 0, 0, 0.19);
  430. box-sizing: border-box;
  431. overflow: hidden;
  432. overflow-y: auto;
  433. &.practiceBoxStrock {
  434. display: flex;
  435. justify-content: center;
  436. align-items: center;
  437. padding-top: 0px;
  438. }
  439. }
  440. }
  441. .NPC-Big-Book-preview-brown {
  442. .NewWordShow {
  443. .item-box {
  444. .item {
  445. .bwc-line {
  446. background: #bf875e;
  447. }
  448. }
  449. .con-box {
  450. border: 1px solid #bf875e;
  451. .img-box {
  452. background: #fff url("../../../assets/NPC/chinaTianYellow.png") center
  453. no-repeat;
  454. background-size: cover;
  455. }
  456. .blank-item {
  457. background: #fff url("../../../assets/NPC/chinaTianYellow.png") center
  458. no-repeat;
  459. background-size: cover;
  460. }
  461. }
  462. }
  463. }
  464. }
  465. .NPC-Big-Book-preview-green {
  466. .NewWordShow {
  467. .item-box {
  468. .item {
  469. .bwc-line {
  470. background: #24b99e;
  471. }
  472. }
  473. .con-box {
  474. border: 1px solid #24b99e;
  475. .img-box {
  476. background: #fff url("../../../assets/NPC/chinaTianGreen.png") center
  477. no-repeat;
  478. background-size: cover;
  479. }
  480. .blank-item {
  481. background: #fff url("../../../assets/NPC/chinaTianGreen.png") center
  482. no-repeat;
  483. background-size: cover;
  484. }
  485. }
  486. }
  487. }
  488. }
  489. </style>
  490. <style lang="scss">
  491. .NPC-Big-Book-preview-red {
  492. .strockplay-newWord {
  493. .strock-play-box {
  494. width: 16px !important;
  495. height: 16px !important;
  496. right: -1px;
  497. top: 0;
  498. background: url("../../../assets/NPC/strock-play-red-click.png") center
  499. no-repeat;
  500. background-size: cover;
  501. }
  502. .character-target-div {
  503. // background-color: initial;
  504. }
  505. }
  506. }
  507. .NPC-Big-Book-preview-green {
  508. .strockplay-newWord {
  509. .strock-play-box {
  510. width: 16px !important;
  511. height: 16px !important;
  512. right: -1px;
  513. top: 0;
  514. background: url("../../../assets/NPC/strock-play-green-click.png") center
  515. no-repeat;
  516. background-size: cover;
  517. }
  518. .character-target-div {
  519. // background-color: initial;
  520. }
  521. }
  522. }
  523. .NPC-Big-Book-preview-brown {
  524. .strockplay-newWord {
  525. .strock-play-box {
  526. width: 16px !important;
  527. height: 16px !important;
  528. right: -1px;
  529. top: 0;
  530. background: url("../../../assets/NPC/strock-play-yellow-click.png") center
  531. no-repeat;
  532. background-size: cover;
  533. }
  534. .character-target-div {
  535. // background-color: initial;
  536. }
  537. }
  538. }
  539. </style>