NewWordShow.vue 15 KB

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