reportBgAudio.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <template>
  2. <view class="report-bg-audio-page">
  3. <view class="title">{{title}}</view>
  4. <view class="time">发布时间:{{PublishTime|formatTime}}</view>
  5. <view class="flex audio-box">
  6. <image
  7. :src="reportId==curAudioReportId&&!curAudioPaused?require('@/static/voice/playing.png'):require('@/static/voice/pause.png')"
  8. mode="aspectFill"
  9. @click="handlePlayAudio"
  10. />
  11. <slider
  12. activeColor="#E6B77D"
  13. :max="duration"
  14. :value="curTime"
  15. @change="handleAudioSliderChange($event)"
  16. block-size="12"
  17. class="slider"
  18. />
  19. <text class="left-time">{{curTime|formatVoiceTime}}</text>
  20. <text class="right-time">{{duration|formatVoiceTime}}</text>
  21. </view>
  22. <view v-show="false"><audioBox v-if="showAudioPop"/></view>
  23. </view>
  24. </template>
  25. <script>
  26. const dayjs=require('@/utils/dayjs.min')
  27. import audioBox from '@/components/audioBox/audioBox.vue'
  28. import {apiReportDetail,apiChapterDetail} from '@/api/report'
  29. export default {
  30. components:{
  31. audioBox,
  32. },
  33. computed:{
  34. showAudioPop(){//是否显示音频弹窗
  35. return this.$store.state.audio.show
  36. },
  37. curAudioReportId(){//当前正在播放的音频id
  38. return this.$store.state.audio.reportId
  39. },
  40. curAudioPaused(){//当前音频是否暂停状态
  41. return this.$store.state.audio.paused
  42. },
  43. curTime(){
  44. let t=0
  45. if(this.reportId==this.$store.state.audio.reportId){
  46. t=this.$store.state.audio.curTime
  47. }
  48. return t
  49. }
  50. },
  51. filters:{
  52. formatTime(e){
  53. return dayjs(e).format('YYYY-MM-DD HH:mm:ss')
  54. },
  55. formatVoiceTime(e){
  56. let m=parseInt(e/60)
  57. let s=parseInt(e%60)
  58. return `${m>9?m:'0'+m}:${s>9?s:'0'+s}`
  59. }
  60. },
  61. data() {
  62. return {
  63. reportId:'',
  64. title:'',
  65. PublishTime:'',
  66. audioData:{},
  67. duration:0,
  68. }
  69. },
  70. onLoad(options){
  71. this.init(options)
  72. },
  73. methods: {
  74. async init(options){
  75. this.reportId=options.reportId||0
  76. const res=options.chapterId!='0'?await apiChapterDetail({report_chapter_id:Number(options.chapterId)}):await apiReportDetail({report_id:Number(options.reportId)})
  77. if(res.code===200){
  78. this.PublishTime=options.chapterId!='0'?res.data.report_chapter_item.publish_time:res.data.report_info.publish_time
  79. if(options.chapterId=='0'){
  80. const time=dayjs(res.data.report_info.publish_time).format('MMDD')
  81. if(res.data.report_info.classify_name_second==res.data.report_info.title){
  82. this.title=`【第${res.data.report_info.stage}期】${res.data.report_info.title}(${time})`
  83. }else{
  84. this.title=`【第${res.data.report_info.stage}期|${res.data.report_info.classify_name_second}】${res.data.report_info.title}(${time})`
  85. }
  86. this.audioData={
  87. video_name:res.data.report_info.video_name,
  88. video_play_seconds:res.data.report_info.video_play_seconds,
  89. video_url:res.data.report_info.video_url,
  90. video_img:res.data.report_info.video_img
  91. }
  92. }else{
  93. this.audioData={
  94. video_name:res.data.report_chapter_item.video_name,
  95. video_play_seconds:res.data.report_chapter_item.video_play_seconds,
  96. video_url:res.data.report_chapter_item.video_url,
  97. video_img:res.data.report_chapter_item.video_img
  98. }
  99. this.title=`【第${res.data.report_chapter_item.stage}期 | ${res.data.report_chapter_item.classify_name_first} | ${res.data.report_chapter_item.type_name}】${res.data.report_chapter_item.title}(${dayjs(res.data.report_chapter_item.publish_time).format('MMDD')})`
  100. }
  101. this.duration=this.audioData.video_play_seconds
  102. const startTime=parseInt(options.ctime)||0
  103. this.handlePlayAudio(startTime)
  104. }
  105. },
  106. //点击播放\暂停音频
  107. handlePlayAudio(startTime){
  108. if(this.$store.state.audio.reportId==this.reportId){
  109. if(this.globalBgMusic.paused){
  110. this.globalBgMusic.play()
  111. }else{
  112. this.globalBgMusic.pause()
  113. }
  114. }else{
  115. const list=[{url:this.audioData.video_url,time:this.audioData.video_play_seconds,title:this.audioData.video_name,}]
  116. this.$store.commit('audio/addAudio',{
  117. list:list,
  118. reportId:this.reportId,
  119. startTime:startTime||0
  120. })
  121. }
  122. },
  123. //拖动音频播放进度条
  124. handleAudioSliderChange(e){
  125. const value=e.detail.value
  126. this.globalBgMusic.seek(value)
  127. },
  128. },
  129. }
  130. </script>
  131. <style lang="scss" scoped>
  132. .report-bg-audio-page{
  133. padding: 50rpx 34rpx;
  134. .section-name{
  135. background: #FDF8F2;
  136. border-radius: 8rpx;
  137. border: 1px solid #E3B377;
  138. display: inline-block;
  139. padding: 19rpx 27rpx;
  140. margin-bottom: 40rpx;
  141. }
  142. .title{
  143. font-size: 36rpx;
  144. line-height: 50rpx;
  145. margin-bottom: 20rpx;
  146. font-weight: 500;
  147. }
  148. .time{
  149. color: #999;
  150. font-size: 28rpx;
  151. line-height: 33rpx;
  152. }
  153. .audio-box{
  154. background-color: #FDF8F2;
  155. height: 123rpx;
  156. align-items: center;
  157. margin-top: 50rpx;
  158. margin-bottom: 40rpx;
  159. padding: 0 30rpx;
  160. position: relative;
  161. .left-time{
  162. position: absolute;
  163. bottom: 20rpx;
  164. left: 100rpx;
  165. color: #999999;
  166. font-size: 20rpx;
  167. }
  168. .right-time{
  169. position: absolute;
  170. bottom: 20rpx;
  171. right: 40rpx;
  172. color: #999999;
  173. font-size: 20rpx;
  174. }
  175. image{
  176. width: 40rpx;
  177. height: 48rpx;
  178. flex-shrink: 0;
  179. margin-right: 30rpx;
  180. }
  181. .slider{
  182. flex: 1;
  183. margin: 0 10rpx;
  184. }
  185. }
  186. }
  187. </style>