ソースを参照

音频提示及自动播放

natasha 1 年間 前
コミット
909ab8ccc2
1 ファイル変更26 行追加3 行削除
  1. 26 3
      src/components/Adult/preview/AudioLine.vue

+ 26 - 3
src/components/Adult/preview/AudioLine.vue

@@ -100,7 +100,8 @@ export default {
       duioCurrentTime: null, // 剩余时间
       count: 0,
       loading: null,
-      isClick: false
+      isClick: false,
+      timer: null // 计时器
     };
   },
   // 计算属性 类似于data概念
@@ -179,6 +180,7 @@ export default {
   // 方法集合
   methods: {
     PlayAudio() {
+      let _this = this;
       let audioId = this.audioId;
       let audio = document.getElementsByTagName("audio");
       if (
@@ -218,7 +220,25 @@ export default {
         }
         setTimeout(() => {
           if (this.audio.currentTime === 0) {
-            this.$message.warning("音频正在加载中,请稍后重试");
+            if (!document.querySelector(".el-message")) {
+              _this.$message({
+                showClose: true,
+                message: "音频正在加载中,请等待",
+                type: "warning",
+                duration: 0
+              });
+            }
+
+            if (_this.timer) {
+              clearInterval(_this.timer);
+            }
+            _this.timer = setInterval(() => {
+              _this.PlayAudio();
+            }, 2000);
+          } else {
+            clearInterval(_this.timer);
+            _this.timer = null;
+            _this.$message.closeAll();
           }
         }, 300);
 
@@ -349,7 +369,10 @@ export default {
   // 生命周期-更新之前
   beforUpdate() {},
   // 生命周期-销毁之前
-  beforeDestory() {},
+  beforeDestory() {
+    this.$message.closeAll();
+    clearInterval(this.timer);
+  },
   // 生命周期-销毁完成
   destoryed() {}
 };