From 8ba5b1346308451e2c66f4414aa2c0b242d503d2 Mon Sep 17 00:00:00 2001
From: 闫增涛 <1829501689@qq.com>
Date: 星期四, 27 六月 2024 15:31:49 +0800
Subject: [PATCH] 英语音频播放优化

---
 src/books/English/view/components/index.vue |  107 +++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 78 insertions(+), 29 deletions(-)

diff --git a/src/books/English/view/components/index.vue b/src/books/English/view/components/index.vue
index dc9ac43..60252e6 100644
--- a/src/books/English/view/components/index.vue
+++ b/src/books/English/view/components/index.vue
@@ -14,23 +14,41 @@
       ></pageHeader>
       <chapterOne
         @saveCharacters="saveCharacters"
-        @closeMiniAudio="closeMiniAudio"
         v-if="showCatalogList.indexOf(2) > -1"
         :showPageList="loadPageList"
       ></chapterOne>
+      <chapterTwo
+        @saveCharacters="saveCharacters"
+        v-if="showCatalogList.indexOf(3) > -1"
+        :showPageList="loadPageList"
+      ></chapterTwo>
+      <chapterThree
+        @saveCharacters="saveCharacters"
+        v-if="showCatalogList.indexOf(4) > -1"
+        :showPageList="loadPageList"
+      ></chapterThree>
+      <chapterFour
+        @saveCharacters="saveCharacters"
+        v-if="showCatalogList.indexOf(5) > -1"
+        :showPageList="loadPageList"
+      ></chapterFour>
     </div>
     <miniAudio
       :path="audioPath"
       :currentTime="currentTime"
       @closeMiniAudio="closeMiniAudio"
       ref="audioPlayer"
-    ></miniAudio>
+    >
+    </miniAudio>
   </div>
 </template>
 
 <script>
 import pageHeader from "./header.vue";
 import chapterOne from "./chapter001.vue";
+import chapterTwo from "./chapter002.vue";
+import chapterThree from "./chapter003.vue";
+import chapterFour from "./chapter004.vue";
 import miniAudio from "@/components/miniAudio/index.vue";
 import NoteIcon from "@/assets/images/biji.png";
 import _ from "lodash";
@@ -41,7 +59,7 @@
 export default {
   data() {
     return {
-      catalogLength: 2, // 鎬荤珷鑺傛暟
+      catalogLength: 5, // 鎬荤珷鑺傛暟
       showCatalogList: [], // 鏄剧ず鐨勭珷鑺�
       loadThreshold: 300, // 瑙﹀彂鍔犺浇闃堝��
       throttleThreshold: 100, // 鑺傛祦闃堝��
@@ -90,6 +108,7 @@
         setTimeout(() => {
           this.initSwiper();
           this.initViewer();
+          this.closeAudio()
         }, 200);
       },
     },
@@ -161,7 +180,7 @@
 
     // 娴嬭瘯椤甸潰璺宠浆
     // setTimeout(() => {
-    //   this.gotoPage(1, 10);
+    //   this.gotoPage(4,59);
     //   setTimeout(() => {
     //     this.renderSign("Highlight", {
     //       id: "2ACA9359",
@@ -189,7 +208,7 @@
     //   txt: " 杩愬姩绯荤粺鏄敱楠ㄣ�侀杩炵粨鍜岄楠艰倢涓夐儴鍒嗙粍鎴愮殑銆傚叏韬殑楠ㄩ�氳繃楠ㄨ繛缁撶粍鎴愪汉浣撻楠硷紙瑙佸浘1-1锛夈�傞楠兼槸浜轰綋鐨勬敮鏋讹紝鍏锋湁淇濇姢鍐呰剰鍣ㄥ畼銆佷緵鑲岃倝闄勭潃鍜屼綔涓鸿倢鑲夎繍鍔ㄧ殑鏉犳潌绛変綔鐢ㄣ�傚湪绁炵粡绯荤粺鐨勬敮閰嶄笅锛岃倢鑲夋敹缂╃壍鍔ㄦ墍闄勭潃鐨勯缁曠潃鍏宠妭杞姩锛屼娇韬綋浜х敓鍚勭鍔ㄤ綔銆傛墍浠ワ紝杩愬姩绯荤粺鍏锋湁杩愬姩銆佹敮鎸佸拰淇濇姢绛夊姛鑳斤紝骞煎勾鏃舵湡鐨勯楠艰繕鍏锋湁閫犺鍔熻兘銆� ",
     //   txtIndex: 57
     // });
-    // }, 5000);
+    //  }, 50);
   },
   methods: {
     // setZoom1() {
@@ -210,7 +229,7 @@
     scrollFun(event) {
       // 鍒ゆ柇鍚戜笂婊氬姩杩樻槸鍚戜笅婊氬姩
       if (event.target.scrollTop > this.previousScrollTop) {
-        this.getAduio()
+        this.getAduio();
         // 鍚戜笅
         const currentScrollTop =
           event.target.scrollTop + event.target.offsetHeight;
@@ -234,7 +253,7 @@
           }
         }
       } else if (event.target.scrollTop < this.previousScrollTop) {
-        this.handleAudio()
+        this.handleAudio();
         // 鍚戜笂
         const currentScrollTop = event.target.scrollTop;
         if (currentScrollTop <= this.loadThreshold) {
@@ -313,7 +332,10 @@
           this.container ? this.container : document
         ).querySelector(`[page="${data.page}"]`);
         // 鍒涘缓 createTreeWalker 杩唬鍣紝鐢ㄤ簬閬嶅巻鏂囨湰鑺傜偣锛屼繚瀛樺埌涓�涓暟缁�
-        const treeWalker = document.createTreeWalker(pageDom, NodeFilter.SHOW_TEXT);
+        const treeWalker = document.createTreeWalker(
+          pageDom,
+          NodeFilter.SHOW_TEXT
+        );
         const allTextNodes = [];
         let currentNode = treeWalker.nextNode();
         while (currentNode) {
@@ -512,7 +534,7 @@
           const catalog = catalogDom.getAttribute("num");
           let text = null;
           if (target.querySelector("p")) {
-            text = target.querySelector("p").textContent.substring(0, 20);
+            text = target.querySelector("p").textContent.substring(0, 50);
           }
           // 杩斿洖椤电爜鍜岀珷鑺備俊鎭�
           if (this.$store.state.qiankun && this.$store.state.qiankun.pageChange)
@@ -538,6 +560,8 @@
               target,
               "chapter"
             );
+            // 娣诲姞椤电爜
+            this.loadPageList.push(Number(page));
             const catalog = catalogDom.getAttribute("num");
             // if (!this.questionDataMap[page]) {
             //   if (testData && testData[catalog]) {
@@ -563,8 +587,6 @@
             //     }
             //   }
             // }
-            // 娣诲姞椤电爜
-            this.loadPageList.push(Number(page));
             // 娓叉煋杩欎竴椤电殑鏍囪
             for (const key in this.renderSignMap) {
               if (this.renderSignMap[key][page]) {
@@ -578,7 +600,10 @@
               // 楂樹寒琛�
               setTimeout(() => {
                 // 鑾峰彇椤甸潰鎵�鏈塼ext鑺傜偣
-                const pageTextList = document.createTreeWalker(target, NodeFilter.SHOW_TEXT);
+                const pageTextList = document.createTreeWalker(
+                  target,
+                  NodeFilter.SHOW_TEXT
+                );
                 // 鍖归厤鍏抽敭瀛�
                 const allPageTextNodes = [];
                 let currentNode = pageTextList.nextNode();
@@ -629,12 +654,8 @@
           spaceBetween: 30, // 闂撮殧
           // 濡傛灉闇�瑕佸墠杩涘悗閫�鎸夐挳
           navigation: {
-            nextEl: (this.container ? this.container : document).querySelector(
-              ".swiper-button-next"
-            ),
-            prevEl: (this.container ? this.container : document).querySelector(
-              ".swiper-button-prev"
-            ),
+            nextEl: dom.querySelector(".swiper-button-next"),
+            prevEl: dom.querySelector(".swiper-button-prev"),
           },
           // 绐楀彛鍙樺寲,閲嶆柊init,閽堝F11鍏ㄥ睆鍜屾斁澶х缉灏�,蹇呴』鍔�
           observer: true,
@@ -661,12 +682,8 @@
           spaceBetween: 30, // 闂撮殧
           // 濡傛灉闇�瑕佸墠杩涘悗閫�鎸夐挳
           navigation: {
-            nextEl: (this.container ? this.container : document).querySelector(
-              ".swiper-button-next"
-            ),
-            prevEl: (this.container ? this.container : document).querySelector(
-              ".swiper-button-prev"
-            ),
+            nextEl: dom.querySelector(".swiper-button-next"),
+            prevEl: dom.querySelector(".swiper-button-prev"),
           },
           // 绐楀彛鍙樺寲,閲嶆柊init,閽堝F11鍏ㄥ睆鍜屾斁澶х缉灏�,蹇呴』鍔�
           observer: true,
@@ -714,6 +731,9 @@
       const pageData = {
         pageHeader,
         chapterOne,
+        chapterTwo,
+        chapterThree,
+        chapterFour,
       };
       // 閬嶅巻鎵�鏈夌珷鑺傛枃浠�
       for (const key in pageData) {
@@ -725,6 +745,7 @@
           propsData: {
             showPageList: [],
             questionData: {},
+            isSearch: true,
           },
         });
         pageExample.$mount(
@@ -756,6 +777,7 @@
               propsData: {
                 showPageList: [pageNum],
                 questionData: {},
+                isSearch: true,
               },
             });
             pageExample.$mount(
@@ -769,7 +791,10 @@
               .querySelector(`[page="${pageNum}"]`);
             if (thisPageDom) {
               // 鑾峰彇椤甸潰鎵�鏈塼ext鑺傜偣
-              const pageTextList = document.createTreeWalker(thisPageDom, NodeFilter.SHOW_TEXT);
+              const pageTextList = document.createTreeWalker(
+                thisPageDom,
+                NodeFilter.SHOW_TEXT
+              );
               // 鍖归厤鍏抽敭瀛�
               const allPageTextNodes = [];
               let currentNode = pageTextList.nextNode();
@@ -810,7 +835,7 @@
       // 璺宠浆
       this.gotoPage(data.catalog, data.page, () => {});
     },
-        // 鐐瑰嚮浜嬩欢锛氬皢鐢熷兓鍗曡瘝浼犵粰 涓诲簲鐢� 浠庤�岃皟鐢ㄨ瘝鍏稿姛鑳�
+    // 鐐瑰嚮浜嬩欢锛氬皢鐢熷兓鍗曡瘝浼犵粰 涓诲簲鐢� 浠庤�岃皟鐢ㄨ瘝鍏稿姛鑳�
     saveCharacters(event, word) {
       console.log("鐢熷兓瀛�", event, word);
       if (this.$store.state.qiankun && this.$store.state.qiankun.chooseWords) {
@@ -823,6 +848,7 @@
       }
       // chooseWords
     },
+
     // 椤甸潰鍚戜笅婊氬姩锛岄煶棰戝皬绐楁挱鏀惧姛鑳�
     getAduio() {
       let allVideo = (
@@ -870,13 +896,35 @@
     },
     // 鍏抽棴mini video
     closeMiniAudio() {
-      this.audioPath = ''
-    }
+      this.audioPath = "";
+    },
+    // 鐐瑰嚮闊抽鎾斁锛屽叧闂叾浠栭煶棰�
+    closeAudio() {
+      let allAudio = (
+        this.container ? this.container : document
+      ).querySelectorAll(".audio");
+      for (let index = 0; index < allAudio.length; index++) {
+        const item = allAudio[index];
+        item.addEventListener("play", () => {
+          const audioList = Array.from(allAudio);
+          for (let cindex = 0; cindex < audioList.length; cindex++) {
+            const citem = audioList[cindex];
+            if (citem.currentSrc != item.src) {
+              citem.pause();
+            }
+          }
+          this.closeMiniAudio();
+        });
+      }
+    },
   },
   components: {
     pageHeader,
     chapterOne,
-    miniAudio
+    chapterTwo,
+    chapterThree,
+    chapterFour,
+    miniAudio,
   },
 };
 </script>
@@ -886,6 +934,7 @@
   width: 100%;
   height: 100%;
   overflow: auto;
+
   .page-content {
     max-width: 816px;
     min-width: 375px;

--
Gitblit v1.9.1