WordPhrase.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541
  1. <template>
  2. <div class="NPC-zhedie">
  3. <el-collapse v-model="wordShow" @change="handleChange">
  4. <el-collapse-item name="1">
  5. <template #title>
  6. <div class="topTitle">
  7. <div class="NPC-top-left">
  8. <span class="NPC-topTitle-text">{{ curQue.title }}</span>
  9. <span
  10. :class="['NPC-play-all', playClass]"
  11. @click.stop="playNewwords"
  12. ></span>
  13. </div>
  14. <div class="NPC-top-right">
  15. <span class="NPC-top-right-text">{{
  16. wordShow.indexOf("1") != -1 ? "收起" : "展开"
  17. }}</span>
  18. <img
  19. v-if="wordShow.indexOf('1') != -1"
  20. src="../../../assets/NPC/down.png"
  21. alt=""
  22. />
  23. <img
  24. v-else
  25. class="rotate"
  26. src="../../../assets/NPC/down.png"
  27. alt=""
  28. />
  29. </div>
  30. </div>
  31. </template>
  32. <div
  33. class="NPC-word-list"
  34. v-if="curQue.option && curQue.option.length > 0"
  35. >
  36. <ul class="NPC-word-table" cellspacing="0" border="0" cellpadding="0">
  37. <li
  38. class="NPC-word-tr"
  39. v-for="(item, index) in curQue.option"
  40. :key="'curQue.option' + index"
  41. >
  42. <div
  43. class="NPC-word-row"
  44. v-for="(sItem, sIndex) in item"
  45. :key="'curQue.option.child' + sIndex"
  46. >
  47. <template
  48. v-if="sItem.mp3_list.length > 0 && sItem.mp3_list[0].url"
  49. >
  50. <span
  51. :class="[
  52. 'NPC-play-btn',
  53. mp3_index == index ? 'active' : '',
  54. ]"
  55. @click="palyAudio(item.new_word, index)"
  56. ></span>
  57. <audio
  58. :id="sItem.new_word"
  59. :src="sItem.mp3_list[0].url"
  60. ></audio>
  61. </template>
  62. <template v-else>
  63. <span style="width: 24px; height: 24px"></span>
  64. </template>
  65. <span class="tabNum"
  66. ><template v-if="sIndex == 0"
  67. >{{ index + 1 }}.</template
  68. ></span
  69. >
  70. <span class="NPC-word-tab-common NPC-word-tab-pinyin">
  71. {{ sItem.pinyin }}
  72. </span>
  73. <span class="NPC-word-tab-common NPC-word-tab-word">
  74. {{ sItem.new_word }}
  75. </span>
  76. <span class="NPC-word-tab-common NPC-word-tab-cixing">
  77. {{ sItem.cixing }}
  78. </span>
  79. <span
  80. class="NPC-word-tab-common NPC-word-tab-def"
  81. v-html="sItem.def_str"
  82. ></span>
  83. <span>
  84. <img
  85. src="../../../assets/NPC/detail-icon.png"
  86. class="detail-icon"
  87. @click="showDetail(sItem)"
  88. />
  89. </span>
  90. </div>
  91. </li>
  92. </ul>
  93. </div>
  94. </el-collapse-item>
  95. </el-collapse>
  96. <div v-if="detailShow">
  97. <WordPhraseDetail
  98. :data="data"
  99. :curQue="curQue"
  100. :changeDetailIndex="changeDetailIndex"
  101. :closeWord="closeWordShow"
  102. :detailIndex="detailIndex"
  103. />
  104. </div>
  105. </div>
  106. </template>
  107. <script>
  108. //这里可以导入其它文件(比如:组件,工具js,第三方插件js,json文件,图片文件等等)
  109. //例如:import 《组件名称》from ‘《组件路径》';
  110. import WordPhraseDetail from "./components/WordPhraseDetail.vue";
  111. import { getContent } from "@/api/ajax";
  112. export default {
  113. //import引入的组件需要注入到对象中才能使用
  114. components: {
  115. WordPhraseDetail,
  116. },
  117. props: ["curQue"],
  118. data() {
  119. //这里存放数据
  120. return {
  121. wordShow: ["1"],
  122. data: null,
  123. detailShow: false,
  124. detailIndex: 0,
  125. audio: new Audio(),
  126. playClass: "",
  127. mp3_index: -1,
  128. playWord: null,
  129. };
  130. },
  131. //计算属性 类似于data概念
  132. computed: {},
  133. //监控data中数据变化
  134. watch: {},
  135. //方法集合
  136. methods: {
  137. handleChange(val) {},
  138. palyAudio(new_word, index) {
  139. let _this = this;
  140. let node = document.getElementById(new_word);
  141. _this.playWord = node;
  142. if (node) {
  143. this.mp3_index = index;
  144. node.play();
  145. }
  146. this.handleListenPlay();
  147. },
  148. handleListenPlay() {
  149. let _this = this;
  150. if (_this.playWord) {
  151. debugger;
  152. let _this = this;
  153. _this.playWord.addEventListener("play", function () {});
  154. _this.playWord.addEventListener("pause", function () {
  155. _this.mp3_index = -1;
  156. });
  157. _this.playWord.addEventListener("ended", function () {
  158. _this.mp3_index = -1;
  159. });
  160. }
  161. },
  162. // 打开单词详情
  163. showDetail(item, index) {
  164. this.data = null;
  165. this.data = item;
  166. console.log(this.data);
  167. this.detailShow = true;
  168. this.detailIndex = index;
  169. this.getWordLiju(item.new_word);
  170. },
  171. // 获取生词的例句
  172. getWordLiju(val) {
  173. this.data.list1 = [];
  174. this.data.list2 = [];
  175. this.data.list3 = [];
  176. this.data.list1 = [
  177. {
  178. word: "国",
  179. sentence: "我是一个中国人,我爱我的国家", // 例句,
  180. begin_position: 12,
  181. end_position: 13,
  182. source_scope: 1,
  183. source_courseware_id_path: "BOOK1/C0001/CW001", // 来源课件 ID 路径 "source_courseware_name_path":"教材1/章节1/课件1", //来源课件名称路径
  184. },
  185. {
  186. word: "国",
  187. sentence: "我是一个中国人,我爱我的国家", // 例句,
  188. begin_position: 5,
  189. end_position: 6,
  190. source_scope: 1,
  191. source_courseware_id_path: "BOOK1/C0001/CW001", // 来源课件 ID 路径 "source_courseware_name_path":"教材1/章节1/课件1", //来源课件名称路径
  192. },
  193. ];
  194. this.data.list2 = [
  195. {
  196. word: "国",
  197. sentence: "我是一个中国人,我爱我的国家", // 例句,
  198. begin_position: 12,
  199. end_position: 13,
  200. source_scope: 1,
  201. source_courseware_id_path: "BOOK1/C0001/CW001", // 来源课件 ID 路径 "source_courseware_name_path":"教材1/章节1/课件1", //来源课件名称路径
  202. },
  203. {
  204. word: "国",
  205. sentence: "我是一个中国人,我爱我的国家", // 例句,
  206. begin_position: 5,
  207. end_position: 6,
  208. source_scope: 1,
  209. source_courseware_id_path: "BOOK1/C0001/CW001", // 来源课件 ID 路径 "source_courseware_name_path":"教材1/章节1/课件1", //来源课件名称路径
  210. },
  211. ];
  212. // let Mname =
  213. // "book-courseware_manager-GetCoursewareWordExampleSentenceList";
  214. // // 获取本课的 本教材的 本套的 的例句
  215. // getContent(Mname, {
  216. // courseware_id: this.currentTreeID, // 课件id
  217. // word: val, //生词
  218. // search_scope: 2, //检索范围0 本课件 1本教材 2本套
  219. // is_contain_word_variants: false,
  220. // }).then((res) => {
  221. // this.data.list3 = res.sentence_list;
  222. // getContent(Mname, {
  223. // courseware_id: this.currentTreeID, // 课件id
  224. // word: val, //生词
  225. // search_scope: 1, //检索范围0 本课件 1本教材 2本套
  226. // is_contain_word_variants: false,
  227. // }).then((res) => {
  228. // this.data.list2 = res.sentence_list;
  229. // getContent(Mname, {
  230. // courseware_id: this.currentTreeID, // 课件id
  231. // word: val, //生词
  232. // search_scope: 0, //检索范围0 本课件 1本教材 2本套
  233. // is_contain_word_variants: false,
  234. // }).then((res) => {
  235. // this.data.list1 = res.sentence_list;
  236. // });
  237. // });
  238. // });
  239. },
  240. // 关闭单词详情
  241. closeWordShow(val) {
  242. this.detailShow = val;
  243. },
  244. // 上一个单词详情
  245. lasspanetail(val) {
  246. this.detailIndex = val;
  247. this.data = null;
  248. this.data = this.curQue.option[this.detailIndex];
  249. this.getWordLiju(this.data.new_word);
  250. },
  251. // 下一个单词详情
  252. nexspanetail(val) {
  253. this.detailIndex = val;
  254. this.data = null;
  255. this.data = this.curQue.option[this.detailIndex];
  256. this.getWordLiju(this.data.new_word);
  257. },
  258. changeDetailIndex(val) {
  259. if (val == "last") {
  260. this.detailIndex--;
  261. } else {
  262. this.detailIndex++;
  263. }
  264. this.data = null;
  265. this.data = this.curQue.option[this.detailIndex];
  266. },
  267. playNewwords() {
  268. let _this = this;
  269. let mp3_index = 0;
  270. _this.mp3_index = mp3_index;
  271. let leg = this.curQue.option.length;
  272. let mp3 = this.curQue.option[mp3_index].mp3_list[0].url;
  273. _this.handlePlayVoice(mp3);
  274. _this.audio.addEventListener("ended", function () {
  275. if (mp3_index < leg - 1) {
  276. mp3_index = mp3_index + 1;
  277. _this.mp3_index = mp3_index;
  278. mp3 =
  279. _this.curQue.option[mp3_index].mp3_list.length > 0 &&
  280. _this.curQue.option[mp3_index].mp3_list[0].url;
  281. if (mp3) {
  282. _this.handlePlayVoice(mp3);
  283. }
  284. }
  285. });
  286. },
  287. handlePlayVoice(mp3) {
  288. let _this = this;
  289. if (!mp3) {
  290. return;
  291. }
  292. if (!this.audio.paused) {
  293. this.audio.pause();
  294. } else {
  295. _this.audio.pause();
  296. _this.audio.load();
  297. _this.audio.src = mp3;
  298. _this.audio.loop = false;
  299. _this.audio.play();
  300. }
  301. },
  302. stopAudio() {
  303. if (this.audio) {
  304. this.audio.pause();
  305. }
  306. },
  307. },
  308. //生命周期 - 创建完成(可以访问当前this实例)
  309. created() {
  310. console.log(this.curQue);
  311. if (this.curQue.type == "NewWord_chs") {
  312. this.curQue.option.forEach((item, index) => {
  313. item.index = index + 1;
  314. item.forEach((sItem, sIndex) => {
  315. sItem.def_str =
  316. sItem.definition_list.length > 0
  317. ? sItem.definition_list.join(";")
  318. : "";
  319. });
  320. });
  321. }
  322. console.log(this.curQue);
  323. },
  324. //生命周期 - 挂载完成(可以访问DOM元素)
  325. mounted() {
  326. let _this = this;
  327. _this.audio.addEventListener("play", function () {
  328. _this.playClass = "active";
  329. });
  330. _this.audio.addEventListener("pause", function () {
  331. _this.playClass = "";
  332. });
  333. _this.audio.addEventListener("ended", function () {
  334. _this.playClass = "";
  335. });
  336. },
  337. //生命周期-创建之前
  338. beforeCreated() {},
  339. //生命周期-挂载之前
  340. beforeMount() {},
  341. //生命周期-更新之前
  342. beforUpdate() {},
  343. //生命周期-更新之后
  344. updated() {},
  345. //生命周期-销毁之前
  346. beforeDestory() {},
  347. //生命周期-销毁完成
  348. destoryed() {},
  349. //如果页面有keep-alive缓存功能,这个函数会触发
  350. activated() {},
  351. };
  352. </script>
  353. <style lang="scss" scoped>
  354. /* @import url(); 引入css类 */
  355. .NPC-zhedie {
  356. width: 780px;
  357. margin-top: 16px;
  358. .topTitle {
  359. width: 100%;
  360. display: flex;
  361. justify-content: space-between;
  362. padding-left: 24px;
  363. padding-right: 16px;
  364. .NPC-top-left {
  365. display: flex;
  366. justify-content: flex-start;
  367. align-items: center;
  368. .NPC-topTitle-text {
  369. font-family: "sourceR";
  370. font-size: 16px;
  371. color: #fff;
  372. font-weight: bold;
  373. margin-right: 8px;
  374. }
  375. .NPC-play-all {
  376. width: 24px;
  377. height: 24px;
  378. background: url("../../../assets/NPC/play-white.png") no-repeat left top;
  379. background-size: 100% 100%;
  380. cursor: pointer;
  381. &.active {
  382. background: url("../../../assets/NPC/play-white-gif.png") no-repeat
  383. left top;
  384. background-size: 100% 100%;
  385. }
  386. }
  387. }
  388. .NPC-top-right {
  389. display: flex;
  390. justify-content: flex-start;
  391. align-items: center;
  392. &-text {
  393. font-weight: normal;
  394. font-size: 14px;
  395. line-height: 16px;
  396. color: #ffffff;
  397. }
  398. }
  399. img {
  400. width: 24px;
  401. height: 24px;
  402. }
  403. .rotate {
  404. animation-name: firstrotate;
  405. animation-direction: 2s;
  406. animation-fill-mode: both;
  407. animation-timing-function: linear;
  408. }
  409. }
  410. .NPC-word-table {
  411. width: 100%;
  412. > .NPC-word-tr {
  413. background: #fff;
  414. border-radius: 8px;
  415. padding: 8px 16px 0px 16px;
  416. margin-bottom: 8px;
  417. .NPC-word-row {
  418. cursor: pointer;
  419. display: flex;
  420. justify-content: flex-start;
  421. padding-bottom: 8px;
  422. > span {
  423. font-size: 16px;
  424. line-height: 150%;
  425. color: #000000;
  426. }
  427. }
  428. .tabNum {
  429. width: 28px;
  430. text-align: right;
  431. margin-left: 4px;
  432. }
  433. .NPC-word-tab-common {
  434. padding-left: 8px;
  435. width: 112px;
  436. }
  437. .NPC-word-tab-pinyin {
  438. font-family: "GB-PINYINOK-B";
  439. white-space: nowrap;
  440. }
  441. .NPC-word-tab-word {
  442. font-family: "sourceR";
  443. white-space: nowrap;
  444. }
  445. .NPC-word-tab-cixing {
  446. font-family: "robot";
  447. width: 40px;
  448. }
  449. .NPC-word-tab-def {
  450. width: 284px;
  451. font-family: "robot";
  452. word-break: break-word;
  453. }
  454. }
  455. }
  456. .NPC-play-btn {
  457. width: 24px;
  458. height: 24px;
  459. display: block;
  460. background: url("../../../assets/newImage/common/icon-voice-red.png")
  461. no-repeat left top;
  462. background-size: 100% 100%;
  463. &.active {
  464. background: url("../../../assets/newImage/common/icon-voice-play-red.png")
  465. no-repeat left top;
  466. background-size: 100% 100%;
  467. }
  468. }
  469. .NPC-word-list {
  470. padding: 20px 24px;
  471. }
  472. .detail-icon {
  473. width: 56px;
  474. height: 24px;
  475. display: block;
  476. cursor: pointer;
  477. }
  478. }
  479. @keyframes firstrotate {
  480. 0% {
  481. transform: rotateZ(0deg);
  482. }
  483. 100% {
  484. transform: rotateZ(180deg);
  485. }
  486. }
  487. @keyframes huifuRotate {
  488. 0% {
  489. transform: rotateZ(180deg);
  490. }
  491. 100% {
  492. transform: rotateZ(0deg);
  493. }
  494. }
  495. </style>
  496. <style lang="scss">
  497. .NPC-zhedie {
  498. .el-collapse-item__content {
  499. padding-bottom: 0;
  500. }
  501. .el-slider__button {
  502. width: 8px;
  503. height: 8px;
  504. }
  505. .el-slider__runway {
  506. margin: 0;
  507. padding: 0;
  508. }
  509. .el-slider {
  510. position: relative;
  511. top: -3px;
  512. }
  513. .el-collapse {
  514. background: #f7f7f7;
  515. box-sizing: border-box;
  516. border-radius: 8px;
  517. }
  518. .el-collapse-item__header {
  519. height: 48px;
  520. background: #e35454;
  521. border: 1px solid rgba(0, 0, 0, 0.1);
  522. box-sizing: border-box;
  523. border-radius: 8px 8px 0px 0px;
  524. }
  525. .el-collapse-item__wrap {
  526. border: 1px solid rgba(0, 0, 0, 0.1);
  527. border-top: 0;
  528. background: #f7f7f7;
  529. border-radius: 0px 0px 8px 8px;
  530. }
  531. .el-collapse-item__arrow {
  532. display: none;
  533. }
  534. .el-table__row {
  535. padding: 4px 0;
  536. }
  537. }
  538. </style>