Browse Source

移除监听

wangxy 1 tháng trước cách đây
mục cha
commit
3a063add0d
2 tập tin đã thay đổi với 33 bổ sung25 xóa
  1. 19 19
      pages/newEnglish/components/useYinbiao.js
  2. 14 6
      pages/newEnglish/index.vue

+ 19 - 19
pages/newEnglish/components/useYinbiao.js

@@ -36,30 +36,30 @@ export function useYinBiaoAutoPlay () {
         }
     }
 
-    function initListen() {
-        uni.$on('danci-audio-ended', (mCode) => {
+    function upd(mCode) {
+        if (code !== mCode) {
+            isAutoPlaying.value = false;
+            uni.$emit('xunhuanYinbiaoBofang', isAutoPlaying.value)
+            return;
+        }
 
-            if (code !== mCode) {
-                isAutoPlaying.value = false;
-				uni.$emit('xunhuanYinbiaoBofang', isAutoPlaying.value)
-                return;
-            }
+        if (current.value<list.value.length-1) {
+            current.value = current.value+1;
+            // 继续播放第二音频
+            handlePlay();
+        } else {
+            // 播放结束
+            isAutoPlaying.value = false;
+            uni.$emit('xunhuanYinbiaoBofang', isAutoPlaying.value)
+        }
+    }
 
-            if (current.value<list.value.length-1) {
-                current.value = current.value+1;
-                // 继续播放第二音频
-                handlePlay();
-            } else {
-                // 播放结束
-                isAutoPlaying.value = false;
-				uni.$emit('xunhuanYinbiaoBofang', isAutoPlaying.value)
-            }
-        })
+    function initListen() {
+        uni.$on('danci-audio-ended', upd)
     }
 
     function removeListen() {
-
-        uni.$off('danci-audio-ended')
+        uni.$off('danci-audio-ended',upd)
     }
 
 

+ 14 - 6
pages/newEnglish/index.vue

@@ -32,7 +32,8 @@
   ref,
   reactive,
   computed,
-  nextTick
+  nextTick,
+  onUnmounted
  } from "vue";
  import {
   onLoad
@@ -62,14 +63,21 @@
  const isLearnStatus = ref(null)
  const isAudioPlaying = ref(false) // 音频播放状态
  // 监听音频播放事件
- uni.$on('danci-audio-play', (code) => {
-  isAudioPlaying.value = true
- })
+ uni.$on('danci-audio-play',  updateAudioPlayingTrue)
+ uni.$on('danci-audio-ended', updateAudioPlayingFalse)
 
- uni.$on('danci-audio-ended', () => {
-  isAudioPlaying.value = false
+ onUnmounted(() => {
+   uni.$off('danci-audio-play',updateAudioPlayingTrue)
+   uni.$off('danci-audio-ended',updateAudioPlayingFalse)
  })
 
+ function updateAudioPlayingFalse() {
+   isAudioPlaying.value = false
+ }
+ function updateAudioPlayingTrue() {
+   isAudioPlaying.value = true
+ }
+
  function handleSwiperChange(index) {
 	 return false
 	// 客户暂时不要