WordPhraseDetailEn.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730
  1. <template>
  2. <div class="Module">
  3. <div class="module-inner">
  4. <div class="top" v-if="detail">
  5. <div class="operation">
  6. <div>
  7. <!-- <img
  8. style="margin-right: 8px"
  9. src="../../assets/Left-16-normal-Black.png"
  10. alt=""
  11. @click="lastDetail"
  12. v-if="!notshowNext"
  13. />
  14. <img
  15. src="../../assets/Right-16-normal-Black.png"
  16. alt=""
  17. @click="nextDetail"
  18. v-if="!notshowNext"
  19. /> -->
  20. <img
  21. @click="closeWordShow"
  22. src="../../assets/Cross-16-normal-Black.png"
  23. alt=""
  24. />
  25. </div>
  26. </div>
  27. <div class="wordDetail">
  28. <p class="word">{{ detail.new_word.new_word }}</p>
  29. <div class="yinpin" v-if="detail.new_word.pinyin">
  30. <span> /{{ detail.new_word.pinyin }}/</span>
  31. <img
  32. @click="palyAudio('deafult')"
  33. :src="playBtn == 'deafult' ? voicePlaySrc : voicePauseSrc"
  34. alt=""
  35. v-if="
  36. detail.new_word.mp3_list &&
  37. detail.new_word.mp3_list.length > 0 &&
  38. playWord == 'deafult' &&
  39. voiceSrc
  40. "
  41. />
  42. <img
  43. @click="palyAudio('deafult')"
  44. :src="voicePauseSrc"
  45. alt=""
  46. v-else-if="
  47. detail.new_word.mp3_list && detail.new_word.mp3_list.length > 0
  48. "
  49. />
  50. <audio
  51. v-if="
  52. detail.new_word.mp3_list && detail.new_word.mp3_list.length > 0
  53. "
  54. id="deafult"
  55. :src="detail.new_word.mp3_list[0].id"
  56. ></audio>
  57. </div>
  58. <p
  59. class="jieshu"
  60. v-for="(fy, i) in detail.new_word.definition_list"
  61. :key="i"
  62. >
  63. <template v-if="fy.indexOf('. ') > -1">
  64. <i>{{ fy.substring(0, fy.indexOf(". ") + 2) }}</i>
  65. <span
  66. >{{ fy.substring(fy.indexOf(". ") + 2, fy.length)
  67. }}{{
  68. i == detail.new_word.definition_list.length - 1 ? "" : ";"
  69. }}</span
  70. >
  71. </template>
  72. <template v-else>
  73. <span>{{
  74. i == detail.new_word.definition_list.length - 1 ? fy : fy + ";"
  75. }}</span>
  76. </template>
  77. </p>
  78. </div>
  79. <div class="zhedie">
  80. <div v-if="list1 && list1.length > 0">
  81. <div class="topTitle">
  82. <span>本课例句({{ list1.length }})</span>
  83. <span @click="handleChangeTab('wordShow')"
  84. >{{ wordShow ? "收起" : "展开" }}
  85. <img v-if="wordShow" src="../../assets/down-black.png" alt="" />
  86. <img
  87. v-else
  88. class="rotate"
  89. src="../../assets/up-black.png"
  90. alt=""
  91. />
  92. </span>
  93. </div>
  94. <el-collapse-transition>
  95. <div class="liju" v-if="wordShow">
  96. <div v-for="(item, i) in list1" :key="i">
  97. <div>{{ i + 1 }}.</div>
  98. <div style="flex: 1">
  99. <p v-html="item.res"></p>
  100. <p class="p2">
  101. 来源:{{ item.source_courseware_name_path }}
  102. </p>
  103. </div>
  104. </div>
  105. </div>
  106. </el-collapse-transition>
  107. </div>
  108. <div v-if="list2 && list2.length > 0">
  109. <div class="topTitle">
  110. <span>本书例句({{ list2.length }})</span>
  111. <span @click="handleChangeTab('wordShow2')"
  112. >{{ wordShow2 ? "收起" : "展开" }}
  113. <img
  114. v-if="wordShow2"
  115. src="../../assets/down-black.png"
  116. alt=""
  117. />
  118. <img
  119. v-else
  120. class="rotate"
  121. src="../../assets/up-black.png"
  122. alt=""
  123. />
  124. </span>
  125. </div>
  126. <el-collapse-transition>
  127. <div class="liju" v-if="wordShow2">
  128. <div v-for="(item, i) in list2" :key="i">
  129. <div>{{ i + 1 }}.</div>
  130. <div style="flex: 1">
  131. <p v-html="item.res"></p>
  132. <p class="p2">
  133. 来源:{{ item.source_courseware_name_path }}
  134. </p>
  135. </div>
  136. </div>
  137. </div>
  138. </el-collapse-transition>
  139. </div>
  140. <div v-if="list3 && list3.length > 0">
  141. <div class="topTitle">
  142. <span>本套教材例句({{ list3.length }})</span>
  143. <span @click="handleChangeTab('wordShow3')"
  144. >{{ wordShow3 ? "收起" : "展开" }}
  145. <img
  146. v-if="wordShow3"
  147. src="../../assets/down-black.png"
  148. alt=""
  149. />
  150. <img
  151. v-else
  152. class="rotate"
  153. src="../../assets/up-black.png"
  154. alt=""
  155. />
  156. </span>
  157. </div>
  158. <el-collapse-transition>
  159. <div class="liju" v-if="wordShow3">
  160. <div v-for="(item, i) in list3" :key="i">
  161. <div>{{ list3.length + i + 1 }}.</div>
  162. <div style="flex: 1">
  163. <p v-html="item.res"></p>
  164. <p class="p2">
  165. 来源:{{ item.source_courseware_name_path }}
  166. </p>
  167. </div>
  168. </div>
  169. </div>
  170. </el-collapse-transition>
  171. </div>
  172. </div>
  173. </div>
  174. <div class="bottom" v-if="dictDetail">
  175. <div class="from">
  176. 来自网易有道<img
  177. @click="closeWordShow"
  178. src="../../assets/Cross-16-normal-Black.png"
  179. alt=""
  180. v-if="!dictDetail"
  181. />
  182. </div>
  183. <div class="wordDetail">
  184. <p class="word">
  185. {{ dictDetail["query"] }}
  186. </p>
  187. <div class="yinpin">
  188. <div class="yinpin-box">
  189. <span>英 </span>
  190. <span v-if="dictDetail['uk-phonetic']">
  191. /{{ dictDetail["uk-phonetic"] }}/</span
  192. >
  193. <img
  194. @click="palyAudio('Y')"
  195. :src="playBtn == 'Y' ? voicePlaySrc : voicePauseSrc"
  196. alt=""
  197. v-if="
  198. dictDetail &&
  199. dictDetail['uk-sound'] &&
  200. playWord == 'Y' &&
  201. voiceSrc
  202. "
  203. />
  204. <img
  205. @click="palyAudio('Y')"
  206. :src="voicePauseSrc"
  207. alt=""
  208. v-else-if="dictDetail"
  209. />
  210. <audio id="Y" :src="dictDetail['uk-sound']"></audio>
  211. </div>
  212. <div>
  213. <span>美 </span>
  214. <span v-if="dictDetail['us-phonetic']">
  215. /{{ dictDetail["us-phonetic"] }}/</span
  216. >
  217. <img
  218. @click="palyAudio('M')"
  219. :src="playBtn == 'M' ? voicePlaySrc : voicePauseSrc"
  220. alt=""
  221. v-if="
  222. dictDetail &&
  223. dictDetail['us-sound'] &&
  224. playWord == 'M' &&
  225. voiceSrc
  226. "
  227. />
  228. <img
  229. @click="palyAudio('M')"
  230. :src="voicePauseSrc"
  231. alt=""
  232. v-else-if="dictDetail && dictDetail['us-sound']"
  233. />
  234. <audio id="M" :src="dictDetail['us-sound']"></audio>
  235. </div>
  236. </div>
  237. <div class="jieshu" v-for="(fy, i) in dictDetail.part" :key="i">
  238. <i>
  239. {{ fy.part }}
  240. </i>
  241. <div>
  242. {{ fy.exp }}
  243. </div>
  244. </div>
  245. </div>
  246. </div>
  247. </div>
  248. </div>
  249. </template>
  250. <script>
  251. //这里可以导入其它文件(比如:组件,工具js,第三方插件js,json文件,图片文件等等)
  252. //例如:import 《组件名称》from ‘《组件路径》';
  253. import { getBookWebContent, getLearnWebContent } from "@/api/ajax";
  254. export default {
  255. //import引入的组件需要注入到对象中才能使用
  256. components: {},
  257. props: ["closeWord", "collId", "currentTreeID"],
  258. data() {
  259. //这里存放数据
  260. return {
  261. height: "",
  262. margintop: "",
  263. wordShow: true,
  264. wordShow2: false,
  265. wordShow3: false,
  266. list1: [],
  267. list2: [],
  268. list3: [],
  269. playWord: "",
  270. playBtn: "",
  271. voiceSrc: require("../../assets/play-red.png"),
  272. voicePauseSrc: require("../../assets/play-red.png"),
  273. voicePlaySrc: require("../../assets/icon-voice-play-red.png"),
  274. collFlag: false,
  275. loading: false,
  276. detail: null,
  277. dictDetail: null,
  278. };
  279. },
  280. // 计算属性 类似于data概念
  281. computed: {},
  282. // 监控data中数据变化
  283. watch: {},
  284. // 方法集合
  285. methods: {
  286. palyAudio(new_word) {
  287. let node = document.getElementById(new_word);
  288. this.playWord = new_word;
  289. if (node) {
  290. node.play();
  291. this.voiceSrc = this.voicePlaySrc;
  292. this.playBtn = new_word;
  293. }
  294. this.handleListenPlay();
  295. },
  296. handleListenPlay() {
  297. let _this = this;
  298. if (_this.playWord) {
  299. let node = document.getElementById(_this.playWord);
  300. node.addEventListener("play", function () {});
  301. node.addEventListener("pause", function () {
  302. _this.playBtn = "";
  303. });
  304. node.addEventListener("ended", function () {
  305. _this.playBtn = "";
  306. });
  307. }
  308. },
  309. // 关闭单词详情
  310. closeWordShow() {
  311. this.closeWord(false);
  312. },
  313. // 上一个单词详情
  314. lastDetail() {
  315. if (this.detailIndex == 0) {
  316. this.$message.warning("当前已经是第一个");
  317. return;
  318. }
  319. this.changeDetailIndex("last");
  320. },
  321. // 下一个单词详情
  322. nextDetail() {
  323. if (this.detailIndex == this.curQue.option.length - 1) {
  324. this.$message.warning("当前已经是最后一个了 ");
  325. return;
  326. }
  327. this.changeDetailIndex("next");
  328. },
  329. handleChangeTab(flag) {
  330. this[flag] = !this[flag];
  331. },
  332. viewIntp() {
  333. this.loading1 = true;
  334. this.loading2 = true;
  335. this.loading3 = true;
  336. let Mname =
  337. "book-courseware_manager-GetCoursewareWordExampleSentenceList";
  338. // 获取本课的 本教材的 本套的 的例句
  339. getBookWebContent(Mname, {
  340. courseware_id: this.currentTreeID, // 课件id
  341. word: this.detail.new_word.new_word, //生词
  342. search_scope: 0, //检索范围0 本课件 1本教材 2本套
  343. is_contain_word_variants: false,
  344. })
  345. .then((res) => {
  346. this.loading1 = false;
  347. this.list1 = this.handleExample(res.sentence_list);
  348. getBookWebContent(Mname, {
  349. courseware_id: this.currentTreeID, // 课件id
  350. word: this.detail.new_word.new_word, //生词
  351. search_scope: 1, //检索范围0 本课件 1本教材 2本套
  352. is_contain_word_variants: false,
  353. })
  354. .then((res) => {
  355. this.loading2 = false;
  356. this.list2 = this.handleExample(res.sentence_list);
  357. getBookWebContent(Mname, {
  358. courseware_id: this.currentTreeID, // 课件id
  359. word: this.detail.new_word.new_word, //生词
  360. search_scope: 2, //检索范围0 本课件 1本教材 2本套
  361. is_contain_word_variants: false,
  362. })
  363. .then((res) => {
  364. this.loading3 = false;
  365. this.list3 = this.handleExample(res.sentence_list);
  366. })
  367. .catch((err) => {
  368. this.loading3 = false;
  369. });
  370. })
  371. .catch((err) => {
  372. this.loading2 = false;
  373. });
  374. })
  375. .catch((err) => {
  376. this.loading1 = false;
  377. });
  378. },
  379. // 处理例句高亮数据
  380. handleExample(list) {
  381. let _this = this;
  382. // let list1Ora = JSON.parse(JSON.stringify(_this.data.list1))
  383. list = list.map((item, index) => {
  384. let position_str = [];
  385. let sentence = JSON.parse(JSON.stringify(item.sentence));
  386. let res = "";
  387. for (let i = 0; i < item.position_list.length; i++) {
  388. let part1 = "";
  389. let part2 = "";
  390. let part3 = "";
  391. if (item.position_list.length > 1) {
  392. if (i == 0) {
  393. part1 = sentence.substring(0, item.position_list[i].begin);
  394. part2 = sentence.substring(
  395. item.position_list[i].begin,
  396. item.position_list[i].end
  397. );
  398. part3 = sentence.substring(
  399. item.position_list[i].end,
  400. item.position_list[i + 1].begin
  401. );
  402. } else if (i == item.position_list.length - 1) {
  403. part1 = "";
  404. part2 = sentence.substring(
  405. item.position_list[i].begin,
  406. item.position_list[i].end
  407. );
  408. part3 = sentence.substring(item.position_list[i].end);
  409. } else {
  410. part1 = "";
  411. part2 = sentence.substring(
  412. item.position_list[i].begin,
  413. item.position_list[i].end
  414. );
  415. part3 = sentence.substring(
  416. item.position_list[i].end,
  417. item.position_list[i + 1].begin
  418. );
  419. }
  420. } else {
  421. part1 = sentence.substring(0, item.position_list[i].begin);
  422. part2 = sentence.substring(
  423. item.position_list[i].begin,
  424. item.position_list[i].end
  425. );
  426. part3 = sentence.substring(item.position_list[i].end);
  427. }
  428. res +=
  429. part1 + '<span style="color:#DE4444;">' + part2 + "</span>" + part3;
  430. }
  431. item.res = res;
  432. return item;
  433. });
  434. return list;
  435. },
  436. getMyCollection() {
  437. this.loading = true;
  438. let Mname = "order-collection_manager-GetMyCollection";
  439. let data = {
  440. id: this.collId,
  441. };
  442. getLearnWebContent(Mname, data).then((res) => {
  443. this.loading = false;
  444. this.detail = res;
  445. if (res.new_word.definition_dictionary_json) {
  446. let dictDetail = JSON.parse(res.new_word.definition_dictionary_json);
  447. this.dictDetail = dictDetail.data;
  448. console.log(this.dictDetail);
  449. }
  450. this.viewIntp();
  451. });
  452. },
  453. },
  454. //生命周期 - 创建完成(可以访问当前this实例)
  455. created() {
  456. this.getMyCollection();
  457. },
  458. //生命周期 - 挂载完成(可以访问DOM元素)
  459. mounted() {
  460. let Fathernode = document.getElementsByClassName(
  461. "NNPE-Big-Book-preview"
  462. )[0];
  463. if (Fathernode) {
  464. // this.height = Fathernode.clientHeight + "px";
  465. this.height = Fathernode.clientHeight + "px";
  466. // this.margintop = "-" + window.innerHeight / 2 + "px";
  467. }
  468. },
  469. //生命周期-创建之前
  470. beforeCreated() {},
  471. //生命周期-挂载之前
  472. beforeMount() {},
  473. //生命周期-更新之前
  474. beforUpdate() {},
  475. //生命周期-更新之后
  476. updated() {},
  477. //生命周期-销毁之前
  478. beforeDestory() {},
  479. //生命周期-销毁完成
  480. destoryed() {},
  481. //如果页面有keep-alive缓存功能,这个函数会触发
  482. activated() {},
  483. };
  484. </script>
  485. <style lang="scss" scoped>
  486. /* @import url(); 引入css类 */
  487. .Module {
  488. .module-inner {
  489. // position: fixed;
  490. // top: 0%;
  491. // left: 50%;
  492. // margin-left: -394px;
  493. width: 788px;
  494. margin: 0 auto;
  495. > div {
  496. width: 788px;
  497. margin-left: 36px;
  498. background: #ffffff;
  499. box-shadow: 0px 4px 24px rgba(0, 0, 0, 0.25);
  500. border-radius: 8px;
  501. padding-top: 16px;
  502. .operation {
  503. height: 24px;
  504. div {
  505. float: right;
  506. margin-right: 16px;
  507. > :nth-child(1) {
  508. margin-right: 16px;
  509. }
  510. > :nth-child(2) {
  511. margin-right: 8px;
  512. }
  513. > :nth-child(3) {
  514. margin-right: 16px;
  515. }
  516. > :last-child {
  517. margin-right: 0;
  518. }
  519. }
  520. img {
  521. width: 16px;
  522. height: 16px;
  523. cursor: pointer;
  524. }
  525. }
  526. }
  527. }
  528. .top {
  529. margin-top: 33px;
  530. padding-bottom: 42px;
  531. .wordDetail {
  532. width: 538px;
  533. margin-left: 40px;
  534. padding-bottom: 23px;
  535. p {
  536. margin: 0;
  537. }
  538. .word {
  539. font-weight: bold;
  540. font-size: 24px;
  541. line-height: 28px;
  542. color: #7b61ff;
  543. }
  544. .yinpin {
  545. font-size: 16px;
  546. line-height: 150%;
  547. color: #000000;
  548. margin-top: 16px;
  549. display: flex;
  550. align-items: center;
  551. justify-content: flex-start;
  552. > div {
  553. height: 16px;
  554. display: flex;
  555. align-items: center;
  556. }
  557. }
  558. img {
  559. margin-left: 10px;
  560. width: 16px;
  561. height: 16px;
  562. cursor: pointer;
  563. }
  564. .jieshu {
  565. margin-top: 16px;
  566. font-size: 16px;
  567. line-height: 150%;
  568. color: #000000;
  569. }
  570. }
  571. .zhedie {
  572. width: 708px;
  573. margin: 0 auto;
  574. > div {
  575. margin-bottom: 16px;
  576. }
  577. .topTitle {
  578. width: 100%;
  579. display: flex;
  580. justify-content: space-between;
  581. padding: 0 12px;
  582. align-items: center;
  583. background: #fff !important;
  584. height: 40px;
  585. background: #fff !important;
  586. border: 1px solid rgba(0, 0, 0, 0.1);
  587. -webkit-box-sizing: border-box;
  588. box-sizing: border-box;
  589. border-radius: 8px 8px 0px 0px;
  590. > :nth-child(1) {
  591. font-weight: 500;
  592. font-size: 16px;
  593. line-height: 150%;
  594. color: rgba(0, 0, 0, 0.85);
  595. }
  596. > :nth-child(2) {
  597. display: flex;
  598. align-items: center;
  599. font-weight: normal;
  600. font-size: 14px;
  601. line-height: 22px;
  602. color: rgba(0, 0, 0, 0.85);
  603. cursor: pointer;
  604. }
  605. img {
  606. width: 16px;
  607. height: 16px;
  608. margin-left: 4px;
  609. }
  610. .rotate {
  611. animation-name: firstrotate;
  612. animation-direction: 2s;
  613. animation-fill-mode: both;
  614. animation-timing-function: linear;
  615. }
  616. }
  617. .liju {
  618. padding-bottom: 16px;
  619. padding-right: 24px;
  620. background: #f7f7f7;
  621. border: 1px solid rgba(0, 0, 0, 0.1);
  622. border-top: none;
  623. border-radius: 0 0 4px 4px;
  624. > div {
  625. padding-top: 16px;
  626. margin-left: 8px;
  627. display: flex;
  628. > :nth-child(1) {
  629. margin-right: 6px;
  630. line-height: 24px;
  631. }
  632. p {
  633. margin: 0;
  634. line-height: 24px;
  635. font-size: 16px;
  636. color: rgba(0, 0, 0, 0.85);
  637. word-break: break-word;
  638. }
  639. .p2 {
  640. font-size: 12px;
  641. line-height: 20px;
  642. color: rgba(0, 0, 0, 0.85);
  643. opacity: 0.3;
  644. }
  645. }
  646. }
  647. }
  648. }
  649. .bottom {
  650. margin-top: 16px;
  651. padding-bottom: 23px;
  652. .from {
  653. // text-align: right;
  654. margin-right: 16px;
  655. font-size: 14px;
  656. line-height: 16px;
  657. color: #000000;
  658. opacity: 0.2;
  659. display: flex;
  660. justify-content: flex-end;
  661. align-items: center;
  662. img {
  663. width: 16px;
  664. margin-left: 16px;
  665. cursor: pointer;
  666. }
  667. }
  668. .wordDetail {
  669. width: 708px;
  670. margin-left: 40px;
  671. padding-bottom: 23px;
  672. border-bottom: 1px solid rgba(0, 0, 0, 0.1);
  673. p {
  674. margin: 0;
  675. }
  676. .word {
  677. font-weight: bold;
  678. font-size: 24px;
  679. line-height: 28px;
  680. color: #7b61ff;
  681. }
  682. .yinpin {
  683. font-size: 16px;
  684. line-height: 150%;
  685. color: #000000;
  686. margin-top: 16px;
  687. display: flex;
  688. justify-content: flex-start;
  689. align-items: center;
  690. > div {
  691. height: 24px;
  692. display: flex;
  693. align-items: center;
  694. > :nth-child(1) {
  695. margin-right: 5px;
  696. }
  697. }
  698. > :nth-child(2) {
  699. margin-left: 27px;
  700. }
  701. img {
  702. margin-left: 10px;
  703. width: 16px;
  704. height: 16px;
  705. cursor: pointer;
  706. }
  707. }
  708. .jieshu {
  709. margin-top: 16px;
  710. font-size: 16px;
  711. line-height: 150%;
  712. color: #000000;
  713. display: flex;
  714. > :nth-child(1) {
  715. // width: 30px;
  716. // text-align: right;
  717. margin-right: 5px;
  718. }
  719. :nth-child(2) {
  720. max-width: 524px;
  721. }
  722. }
  723. }
  724. }
  725. }
  726. </style>