NewWordShow.vue 15 KB

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