小彬 2 سال پیش
والد
کامیت
de9e324986

+ 2 - 1
activityPages/activityDetail/activityDetail.vue

@@ -284,7 +284,8 @@ export default {
     },
     curTime() {
       //当前音频的播放时间
-      return this.$store.state.audioBg.curTime;
+      let initTime = this.curVoiceId === this.detailData.ActivityId ? this.$store.state.audioBg.curTime : 0;
+      return initTime;
     },
   },
   components: {

+ 4 - 0
components/audioModule/index.vue

@@ -62,6 +62,7 @@ export default {
     audioInit() {
       return {
         activityId: this.$store.state.audioBg.activityId,
+        reportId: this.$store.state.audioBg.reportId,
       };
     },
   },
@@ -102,6 +103,9 @@ export default {
       this.globalBgAudioManager.onPlay(async () => {
         this.play = true;
         this.$store.commit("audioBg/updateAudioPause", false);
+        if (this.$store.state.audioBg.activityId) {
+          activity.backAudioPlay({ ActivityId: this.$store.state.audioBg.activityId });
+        }
       });
       this.globalBgAudioManager.onPause(() => {
         console.log("音频暂停");

+ 40 - 29
reportPages/reportSecretDetail/reportSecretDetail.vue

@@ -15,8 +15,15 @@
         </view>
         <view class="content-audio">
           <view class="audio-img">
-            <image v-if="isPlay" @click="audiouspend" src="https://hzchart.oss-cn-shanghai.aliyuncs.com/cygx/czbk/suspend_icon.png"></image>
-            <image v-else @click="audioPlay" src="https://hzchart.oss-cn-shanghai.aliyuncs.com/cygx/czbk/play_icon.png" mode=""></image>
+            <image
+              @click.stop="audioPlayBack"
+              class=""
+              :src="
+                curVoiceId === detali.ArticleId && !curAudioPaused
+                  ? 'https://hzchart.oss-cn-shanghai.aliyuncs.com/cygx/czbk/suspend_icon.png'
+                  : 'https://hzchart.oss-cn-shanghai.aliyuncs.com/cygx/czbk/play_icon.png'
+              "
+            ></image>
           </view>
           <view class="audio-title">
             <text>{{ detali.VideoName }}</text>
@@ -69,6 +76,7 @@
       </block>
     </view>
     <freeCharge class="free-charge" :isShowFreeBtn="isShowFree" />
+    <audioModule :showAudioPop="false" />
   </view>
 </template>
 
@@ -76,8 +84,9 @@
 import statement from "@/reportPages/components/statement.vue";
 import researchSummary from "./components/researchSummary.vue";
 import reportChoiceness from "./components/reportChoiceness.vue";
+import audioModule from "@/components/audioModule/index";
 import freeCharge from "@/components/freeCharge";
-import { Reports,FreeButton } from "@/config/api.js";
+import { Reports, FreeButton } from "@/config/api.js";
 let app = getApp({ allowDefault: true });
 export default {
   data() {
@@ -95,20 +104,36 @@ export default {
       isShowAlert: false,
     };
   },
+  computed: {
+    curVoiceId() {
+      //当前正在播放的音频id
+      return this.$store.state.audioBg.reportId;
+    },
+    curAudioPaused() {
+      //当前音频是否暂停状态
+      return this.$store.state.audioBg.paused;
+    },
+  },
   methods: {
-    audioPlay() {
-      if (this.videoUrl === this.globalBgAudioManager.src) {
-        this.globalBgAudioManager.play();
+    //音频点击暂停播放
+    audioPlayBack() {
+      let list = { Url: this.detali.VideoUrl, Name: this.detali.Title, PlaySeconds: this.detali.VideoPlaySeconds };
+      if (this.globalBgAudioManager.src) {
+        if (this.$store.state.audioBg.reportId == this.detali.ArticleId) {
+          if (this.globalBgAudioManager.paused) {
+            this.globalBgAudioManager.play();
+          } else {
+            this.globalBgAudioManager.pause();
+          }
+        } else {
+          this.$store.commit("audioBg/addAudio", { list, reportId: this.detali.ArticleId });
+        }
       } else {
-        this.globalBgAudioManager.title = this.detali.VideoName;
-        this.globalBgAudioManager.src = this.videoUrl;
+        this.$store.commit("audioBg/removeAudio");
+        this.$store.commit("audioBg/addAudio", { list, reportId: this.detali.ArticleId });
       }
-      this.isPlay = true;
-    },
-    audiouspend() {
-      this.isPlay = false;
-      this.globalBgAudioManager.pause();
     },
+    //获取数据详情
     async getDetilaiList() {
       const res =
         this.isType == 1
@@ -173,32 +198,18 @@ export default {
     researchSummary,
     reportChoiceness,
     freeCharge,
+    audioModule,
   },
-  onLoad(option) {
+  async onLoad(option) {
     this.isType = option.type;
     this.id = Number(option.id) || "";
     uni.setNavigationBarTitle({
       title: this.isType == 1 ? "报告精选" : this.isType == 2 ? "本周研究汇总" : "上周纪要汇总",
     });
     this.userIsShowAlert();
-    this.globalBgAudioManager.onEnded((res) => {
-      this.isPlay = false;
-    });
-    this.globalBgAudioManager.onPause((res) => {
-      this.isPlay = false;
-    });
-    this.globalBgAudioManager.onPlay((res) => {
-      this.isPlay = true;
-    });
-    this.globalBgAudioManager.onStop((res) => {
-      this.isPlay = false;
-    });
-  },
-  async onShow() {
     await this.$store.dispatch("checkHandle");
     if (!this.$store.state.isAuth && !this.$store.state.isBind) this.getDetilaiList();
   },
-  onUnload() {},
   /**
    * 用户点击分享
    */

+ 37 - 25
reportPages/roadEssence/roadEssence.vue

@@ -15,8 +15,15 @@
         </view>
         <view class="content-audio">
           <view class="audio-img">
-            <image v-if="isPlay" @click="audiouspend" src="https://hzchart.oss-cn-shanghai.aliyuncs.com/cygx/czbk/suspend_icon.png"></image>
-            <image v-else @click="audioPlay" src="https://hzchart.oss-cn-shanghai.aliyuncs.com/cygx/czbk/play_icon.png" mode=""></image>
+            <image
+              @click.stop="audioPlayBack"
+              class=""
+              :src="
+                curVoiceId === detali.ArticleId && !curAudioPaused
+                  ? 'https://hzchart.oss-cn-shanghai.aliyuncs.com/cygx/czbk/suspend_icon.png'
+                  : 'https://hzchart.oss-cn-shanghai.aliyuncs.com/cygx/czbk/play_icon.png'
+              "
+            ></image>
           </view>
           <view class="audio-title">
             <text>{{ detali.VideoName }}</text>
@@ -53,6 +60,7 @@
       </block>
     </view>
     <freeCharge class="free-charge" :isShowFreeBtn="isShowFree" />
+    <audioModule :showAudioPop="false" />
   </view>
 </template>
 
@@ -60,6 +68,7 @@
 import { Reports, User, FreeButton } from "@/config/api.js";
 import statement from "@/reportPages/components/statement.vue";
 import freeCharge from "@/components/freeCharge";
+import audioModule from "@/components/audioModule/index";
 let app = getApp({ allowDefault: true });
 export default {
   data() {
@@ -74,6 +83,16 @@ export default {
       isShowAlert: false,
     };
   },
+  computed: {
+    curVoiceId() {
+      //当前正在播放的音频id
+      return this.$store.state.audioBg.reportId;
+    },
+    curAudioPaused() {
+      //当前音频是否暂停状态
+      return this.$store.state.audioBg.paused;
+    },
+  },
   methods: {
     async getDetail() {
       const res = await Reports.roadshowEssence({
@@ -121,14 +140,23 @@ export default {
         url: "/pages/index/index",
       });
     },
-    audioPlay(e) {
-      if (this.videoUrl === this.globalBgAudioManager.src) {
-        this.globalBgAudioManager.play();
+    //音频点击暂停播放
+    audioPlayBack() {
+      let list = { Url: this.detali.VideoUrl, Name: this.detali.Title, PlaySeconds: this.detali.VideoPlaySeconds };
+      if (this.globalBgAudioManager.src) {
+        if (this.$store.state.audioBg.reportId == this.detali.ArticleId) {
+          if (this.globalBgAudioManager.paused) {
+            this.globalBgAudioManager.play();
+          } else {
+            this.globalBgAudioManager.pause();
+          }
+        } else {
+          this.$store.commit("audioBg/addAudio", { list, reportId: this.detali.ArticleId });
+        }
       } else {
-        this.globalBgAudioManager.title = this.detali.VideoName;
-        this.globalBgAudioManager.src = this.videoUrl;
+        this.$store.commit("audioBg/removeAudio");
+        this.$store.commit("audioBg/addAudio", { list, reportId: this.detali.ArticleId });
       }
-      this.isPlay = true;
     },
     audiouspend() {
       this.isPlay = false;
@@ -145,21 +173,10 @@ export default {
   components: {
     statement,
     freeCharge,
+    audioModule,
   },
   onLoad(option) {
     this.id = Number(option.id) || "";
-    this.globalBgAudioManager.onEnded((res) => {
-      this.isPlay = false;
-    });
-    this.globalBgAudioManager.onPause((res) => {
-      this.isPlay = false;
-    });
-    this.globalBgAudioManager.onPlay((res) => {
-      this.isPlay = true;
-    });
-    this.globalBgAudioManager.onStop((res) => {
-      this.isPlay = false;
-    });
     this.userIsShowAlert();
   },
   async onShow() {
@@ -167,11 +184,6 @@ export default {
     if (!this.$store.state.isAuth && !this.$store.state.isBind) {
       //已授权已绑定
       this.getDetail();
-      this.audioContext = uni.createInnerAudioContext();
-      //音频自然播放结束事件
-      this.audioContext.onEnded((res) => {
-        this.isPlay = true;
-      });
     }
   },
   /**

+ 3 - 1
store/modules/audioBg.js

@@ -4,6 +4,7 @@ const audioModules = {
   state: {
     list: [], //[{url:音频地址,time:音频时长,title:音频标题,}]
     activityId: 0, //当前是哪个报告的音频
+    reportId: 0,
     paused: true, //当前是否音频正在播放 true暂停状态
     curTime: 0, //当前正在播放的音频播放的时间
     activityTitle: "",
@@ -13,6 +14,7 @@ const audioModules = {
       state.list = payload.list;
       state.activityTitle = payload.activityTitle;
       state.activityId = payload.activityId || 0;
+      state.reportId = payload.reportId || 0;
     },
     // 音频状态
     updateAudioPause(state, payload) {
@@ -20,7 +22,7 @@ const audioModules = {
     },
     // 更新音频播放进度
     updateAudioTime(state, payload) {
-      state.curTime = payload;
+        state.curTime = payload;
     },
     //删除当前音频播放
     removeAudio(state, payload) {