index.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <template>
  2. <view class="container global-audio-box" v-if="showAudioPop">
  3. <view class="bg-overlay" @click="isShowMaskHandler"></view>
  4. <view class="audio-box">
  5. <view class="activity-title text_oneLine">
  6. {{ activityTitle }}
  7. <view class="icon-cross" @click.stop="isShowMaskHandler">
  8. <van-icon name="cross" font-size="32" />
  9. </view>
  10. </view>
  11. <view class="audio-card">
  12. <view class="card-title text_oneLine">
  13. {{ title }}
  14. </view>
  15. <slider activeColor="#3385FF" :max="audioTime" :value="curTime" @change="handleAudioSliderChange($event)" block-size="16" class="slider" />
  16. <view class="card-time">
  17. <text class="time">{{ curTime | formatVoiceTime }}</text>
  18. <text class="time">{{ audioTime | formatVoiceTime }}</text>
  19. </view>
  20. <view class="is-paly-card">
  21. <image
  22. @click.stop="handleChangePlayStatus"
  23. class=""
  24. :src="play ? 'https://hzchart.oss-cn-shanghai.aliyuncs.com/cygx/czbk/suspend_icon.png' : 'https://hzchart.oss-cn-shanghai.aliyuncs.com/cygx/czbk/play_icon.png'"
  25. ></image>
  26. </view>
  27. </view>
  28. </view>
  29. </view>
  30. </template>
  31. <script>
  32. import { activity } from "@/config/api";
  33. export default {
  34. name: "",
  35. filters: {
  36. formatVoiceTime(e) {
  37. let m = parseInt(e / 60);
  38. let s = parseInt(e % 60);
  39. return `${m > 9 ? m : "0" + m}:${s > 9 ? s : "0" + s}`;
  40. },
  41. },
  42. components: {},
  43. props: {
  44. showAudioPop: {
  45. type: Boolean,
  46. default: false,
  47. required: true,
  48. },
  49. },
  50. data() {
  51. return {
  52. curTime: 0,
  53. audioTime: 0, //当前音频总时长
  54. title: "", //当前音频标题
  55. activityTitle: "", //当前活动标题
  56. play: false,
  57. isEnded: false,
  58. };
  59. },
  60. computed: {
  61. audioInit() {
  62. return {
  63. activityId: this.$store.state.audioBg.activityId,
  64. reportId: this.$store.state.audioBg.reportId,
  65. };
  66. },
  67. },
  68. watch: {
  69. audioInit: {
  70. handler(nval) {
  71. this.init();
  72. },
  73. immediate: true,
  74. },
  75. },
  76. created() {},
  77. mounted() {
  78. this.init();
  79. },
  80. methods: {
  81. //点击隐藏事件
  82. isShowMaskHandler() {
  83. this.$emit("update:showAudioPop", false);
  84. },
  85. //数据初次加载
  86. init() {
  87. const curAudio = this.$store.state.audioBg.list;
  88. if (this.globalBgAudioManager.src != curAudio.Url) {
  89. this.globalBgAudioManager.src = curAudio.Url;
  90. this.globalBgAudioManager.title = curAudio.Name;
  91. }
  92. this.audioTime = curAudio.PlaySeconds;
  93. this.title = curAudio.Name;
  94. this.activityTitle = this.$store.state.audioBg.activityTitle;
  95. this.curTime = parseInt(this.globalBgAudioManager.currentTime);
  96. this.play = !this.globalBgAudioManager.paused;
  97. this.listenAudio();
  98. },
  99. //音频播放事件
  100. listenAudio() {
  101. this.globalBgAudioManager.onPlay(async () => {
  102. this.play = true;
  103. this.$store.commit("audioBg/updateAudioPause", false);
  104. if (this.$store.state.audioBg.activityId) {
  105. activity.backAudioPlay({ ActivityId: this.$store.state.audioBg.activityId });
  106. }
  107. });
  108. this.globalBgAudioManager.onPause(() => {
  109. console.log("音频暂停");
  110. this.play = false;
  111. this.$store.commit("audioBg/updateAudioPause", true);
  112. });
  113. this.globalBgAudioManager.onStop(() => {
  114. console.log("音频停止");
  115. this.play = false;
  116. this.$store.commit("audioBg/updateAudioPause", true);
  117. });
  118. this.globalBgAudioManager.onEnded(() => {
  119. console.log("音频onEnded");
  120. this.play = false;
  121. this.$store.commit("audioBg/updateAudioPause", true);
  122. });
  123. this.globalBgAudioManager.onError((e) => {
  124. console.log("音频onError", e);
  125. this.$store.commit("audioBg/removeAudio");
  126. uni.showToast({
  127. title: "音频播放错误",
  128. icon: "none",
  129. });
  130. });
  131. //音频的播放时间更新
  132. this.globalBgAudioManager.onTimeUpdate(() => {
  133. this.curTime = parseInt(this.globalBgAudioManager.currentTime);
  134. this.$store.commit("audioBg/updateAudioTime", this.curTime);
  135. });
  136. },
  137. //拖动进度条
  138. handleAudioSliderChange(e) {
  139. const value = e.detail.value;
  140. this.globalBgAudioManager.seek(value);
  141. },
  142. //音频点击暂停播放
  143. handleChangePlayStatus() {
  144. if (this.globalBgAudioManager.src) {
  145. if (!this.globalBgAudioManager.paused) {
  146. this.globalBgAudioManager.pause();
  147. } else {
  148. this.globalBgAudioManager.play();
  149. }
  150. } else {
  151. this.init();
  152. }
  153. },
  154. },
  155. };
  156. </script>
  157. <style scoped lang="scss">
  158. .global-audio-box {
  159. display: flex;
  160. height: 100%;
  161. position: fixed;
  162. width: 100%;
  163. top: 0;
  164. left: 0;
  165. z-index: 11;
  166. .bg-overlay {
  167. width: 100%;
  168. height: 100%;
  169. position: absolute;
  170. top: 0;
  171. left: 0;
  172. background-color: rgba(0, 0, 0, 0.7);
  173. }
  174. .activity-title {
  175. position: relative;
  176. width: 100%;
  177. font-size: 30rpx;
  178. font-weight: 500;
  179. margin-bottom: 35rpx;
  180. text-align: center;
  181. padding-right: 30rpx;
  182. .icon-cross {
  183. position: absolute;
  184. right: 0;
  185. top: 50%;
  186. transform: translateY(-50%);
  187. padding: 10rpx;
  188. }
  189. }
  190. .audio-box {
  191. position: absolute;
  192. bottom: 0;
  193. left: 0;
  194. padding-bottom: constant(safe-area-inset-bottom);
  195. padding-bottom: env(safe-area-inset-bottom);
  196. width: 100%;
  197. height: 460rpx;
  198. background: #ffffff;
  199. padding: 30rpx;
  200. box-sizing: border-box;
  201. border-radius: 30rpx 30rpx 0 0;
  202. }
  203. .audio-card {
  204. width: 100%;
  205. height: 282rpx;
  206. background: #f5f9ff;
  207. border-radius: 16rpx;
  208. margin: 0 auto;
  209. padding: 30rpx;
  210. .slider {
  211. width: 100%;
  212. margin: 0;
  213. }
  214. .card-title {
  215. color: #3385ff;
  216. font-size: 28rpx;
  217. padding: 0 66rpx;
  218. text-align: center;
  219. margin-bottom: 35rpx;
  220. }
  221. .card-time {
  222. display: flex;
  223. justify-content: space-between;
  224. color: #999999;
  225. font-size: 20rpx;
  226. }
  227. .is-paly-card {
  228. width: 100%;
  229. text-align: center;
  230. image {
  231. margin-top: 5rpx;
  232. width: 100rpx;
  233. height: 100rpx;
  234. }
  235. }
  236. }
  237. }
  238. </style>