voiceDetail.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. <template>
  2. <view class="voice-detail" v-if="isAuth">
  3. <!-- <view class="section-name">{{info.SectionName}}</view> -->
  4. <view class="title">{{info.BroadcastName}}</view>
  5. <view class="time">发布时间:{{info.PublishTime|formatTime}}</view>
  6. <view class="flex audio-box">
  7. <image
  8. :src="voiceId==curVoiceId&&!curAudioPaused?require('@/static/voice/playing.png'):require('@/static/voice/pause.png')"
  9. mode="aspectFill"
  10. @click="handlePlayAudio"
  11. />
  12. <slider
  13. activeColor="#E6B77D"
  14. :max="duration"
  15. :value="curTime"
  16. @change="handleAudioSliderChange($event)"
  17. block-size="12"
  18. class="slider"
  19. />
  20. <text class="left-time">{{curTime|formatVoiceTime}}</text>
  21. <text class="right-time">{{duration|formatVoiceTime}}</text>
  22. </view>
  23. <image class="del-btn" src="@/static/voice/del.png" mode="widthFix" @click="handleDel" v-if="info.IsAuthor"/>
  24. <image class="publish-btn" src="@/static/voice/publish.png" mode="widthFix" @click="handleSendMsg" v-if="info.CouldSendMsg"/>
  25. <sharePoster
  26. :showSlot="true"
  27. :shareData="{
  28. type:'voice_detail',
  29. code_page:'pages-voice/voiceDetail',
  30. code_scene:JSON.stringify({voiceId:info.BroadcastId}),
  31. data:{
  32. title:info.BroadcastName,
  33. img:info.ImgUrl
  34. }
  35. }"
  36. >
  37. <image style="width:34rpx;height:34rpx;float: right;" src="@/static/voice/creat-poster-icon.png" mode="aspectFill" />
  38. </sharePoster>
  39. <!-- 图片部分 -->
  40. <view class="imgs-box">
  41. <image
  42. v-for="item in info.Imgs"
  43. :key="item"
  44. :src="item"
  45. mode="widthFix"
  46. lazy-load="false"
  47. @click="preViewImg(item)"
  48. />
  49. </view>
  50. <view v-show="false"><audioBox v-if="showAudioPop"/></view>
  51. <van-dialog id="van-dialog" />
  52. <!-- 跳转去提问悬浮按钮 -->
  53. <dragButton :existTabBar="true">
  54. <navigator url="/pages-question/hasQuestion">
  55. <view class="to-question-fixed-box">
  56. <image src="@/static/toquestion-icon.png" mode="widthFix" />
  57. <text>我要提问</text>
  58. </view>
  59. </navigator>
  60. </dragButton>
  61. </view>
  62. <noAuth :info="noAuthData" v-else/>
  63. </template>
  64. <script>
  65. import {apiVoicePlayRecord,apiVoiceDel,apiVoiceDetail,apiVoiceSendMsg} from '@/api/voice'
  66. import {apiGetSceneToParams} from '@/api/common'
  67. import noAuth from '@/pages/voice/components/noAuth.vue'
  68. import audioBox from '@/components/audioBox/audioBox.vue'
  69. import dragButton from '@/components/dragButton/dragButton.vue'
  70. import sharePoster from '@/components/sharePoster/sharePoster.vue'
  71. const dayjs=require('@/utils/dayjs.min')
  72. export default {
  73. components:{
  74. noAuth,
  75. audioBox,
  76. dragButton,
  77. sharePoster
  78. },
  79. computed:{
  80. showAudioPop(){//是否显示音频弹窗
  81. return this.$store.state.audio.show
  82. },
  83. curVoiceId(){//当前正在播放的音频id
  84. return this.$store.state.audio.voiceId
  85. },
  86. curAudioPaused(){//当前音频是否暂停状态
  87. return this.$store.state.audio.paused
  88. },
  89. curTime(){
  90. let t=0
  91. if(this.voiceId==this.$store.state.audio.voiceId){
  92. t=this.$store.state.audio.curTime
  93. }
  94. return t
  95. }
  96. },
  97. filters:{
  98. formatTime(e){
  99. return dayjs(e).format('YYYY-MM-DD HH:mm:ss')
  100. },
  101. formatVoiceTime(e){
  102. let m=parseInt(e/60)
  103. let s=parseInt(e%60)
  104. return `${m>9?m:'0'+m}:${s>9?s:'0'+s}`
  105. }
  106. },
  107. data() {
  108. return {
  109. voiceId:'',
  110. isAuth:true,
  111. noAuthData:null,
  112. info:{},
  113. // curTime:0,
  114. duration:0,
  115. }
  116. },
  117. onLoad(options){
  118. this.init(options)
  119. },
  120. onShareAppMessage(){
  121. const title=`${this.info.SectionName}:${this.info.BroadcastName}`
  122. return {
  123. title:title,
  124. imageUrl:this.info.ImgUrl
  125. }
  126. },
  127. methods: {
  128. async init(options){
  129. if(options.scene){
  130. const res=await apiGetSceneToParams({scene_key:options.scene})
  131. if(res.code===200){
  132. const obj=JSON.parse(res.data)
  133. this.voiceId=obj.voiceId
  134. }
  135. }else{
  136. this.voiceId=options.voiceId||0
  137. }
  138. this.getDetail()
  139. },
  140. async getDetail(){
  141. const res=await apiVoiceDetail({broadcast_id:Number(this.voiceId)})
  142. if(res.code===200){
  143. this.info=res.data
  144. uni.setNavigationBarTitle({ title: res.data.SectionName||'播报详情' })
  145. this.duration=Number(res.data.VoicePlaySeconds)||0
  146. this.isAuth=true
  147. }else if(res.code===403){
  148. this.isAuth=false
  149. this.noAuthData=res.data
  150. }
  151. },
  152. //删除
  153. handleDel(){
  154. this.$dialog.confirm({
  155. title:'',
  156. message: '确定要删除该语音播报吗?',
  157. confirmButtonText:'确定'
  158. }).then(()=>{
  159. apiVoiceDel({broadcast_id:Number(this.voiceId)}).then(res=>{
  160. if(res.code===200){
  161. uni.showToast({
  162. title:'操作成功',
  163. icon:'none'
  164. })
  165. setTimeout(() => {
  166. uni.$emit('addVoiceSuccess')
  167. uni.switchTab({
  168. url: '/pages/voice/voice'
  169. });
  170. }, 1000);
  171. }
  172. })
  173. }).catch(()=>{})
  174. },
  175. // 推送消息
  176. handleSendMsg(){
  177. this.$dialog.confirm({
  178. title:'',
  179. message: '该操作将推送模板消息和客群,确认推送吗?',
  180. confirmButtonText:'确认'
  181. }).then(()=>{
  182. apiVoiceSendMsg({broadcast_id:Number(this.voiceId)}).then(res=>{
  183. if(res.code===200){
  184. uni.showToast({
  185. title:'操作成功',
  186. icon:'none'
  187. })
  188. setTimeout(() => {
  189. uni.$emit('addVoiceSuccess')
  190. uni.switchTab({
  191. url: '/pages/voice/voice'
  192. });
  193. }, 1000);
  194. }
  195. })
  196. }).catch(()=>{})
  197. },
  198. //上报音频播放记录
  199. async handleVoicePlayRecord(){
  200. const res=await apiVoicePlayRecord({
  201. broadcast_id:Number(this.voiceId)
  202. })
  203. if(res.code===200){
  204. console.log('上报音频播放记录');
  205. this.$store.commit('audio/addAudioRecordId',{recordId:res.data,source:2})
  206. }
  207. },
  208. //点击播放\暂停音频
  209. handlePlayAudio(){
  210. if(this.$store.state.audio.voiceId==this.voiceId){
  211. if(this.globalBgMusic.paused){
  212. this.globalBgMusic.play()
  213. }else{
  214. this.globalBgMusic.pause()
  215. }
  216. }else{
  217. const list=[{url:this.info.VoiceUrl,time:this.info.VoicePlaySeconds,title:this.info.BroadcastName,}]
  218. this.$store.commit('audio/addAudio',{
  219. list:list,
  220. voiceId:this.voiceId
  221. })
  222. this.handleVoicePlayRecord()
  223. }
  224. },
  225. //拖动音频播放进度条
  226. handleAudioSliderChange(e){
  227. const value=e.detail.value
  228. this.globalBgMusic.seek(value)
  229. },
  230. //预览图片
  231. preViewImg(item){
  232. wx.previewImage({
  233. current: item, // 当前显示图片的 http 链接
  234. urls: this.info.Imgs||[] // 需要预览的图片 http 链接列表
  235. })
  236. }
  237. },
  238. }
  239. </script>
  240. <style lang="scss" scoped>
  241. .voice-detail{
  242. padding: 50rpx 34rpx;
  243. .section-name{
  244. background: #FDF8F2;
  245. border-radius: 8rpx;
  246. border: 1px solid #E3B377;
  247. display: inline-block;
  248. padding: 19rpx 27rpx;
  249. margin-bottom: 40rpx;
  250. }
  251. .title{
  252. font-size: 32rpx;
  253. line-height: 38rpx;
  254. margin-bottom: 20rpx;
  255. }
  256. .time{
  257. color: #999;
  258. font-size: 28rpx;
  259. line-height: 33rpx;
  260. }
  261. .audio-box{
  262. background-color: #FDF8F2;
  263. height: 123rpx;
  264. align-items: center;
  265. margin-top: 50rpx;
  266. margin-bottom: 40rpx;
  267. padding: 0 30rpx;
  268. position: relative;
  269. .left-time{
  270. position: absolute;
  271. bottom: 20rpx;
  272. left: 100rpx;
  273. color: #999999;
  274. font-size: 20rpx;
  275. }
  276. .right-time{
  277. position: absolute;
  278. bottom: 20rpx;
  279. right: 40rpx;
  280. color: #999999;
  281. font-size: 20rpx;
  282. }
  283. image{
  284. width: 40rpx;
  285. height: 48rpx;
  286. flex-shrink: 0;
  287. margin-right: 30rpx;
  288. }
  289. .slider{
  290. flex: 1;
  291. margin: 0 10rpx;
  292. }
  293. }
  294. .del-btn{
  295. float: left;
  296. width: 36rpx;
  297. height: 36rpx;
  298. }
  299. .publish-btn{
  300. float: right;
  301. width: 36rpx;
  302. height: 36rpx;
  303. margin-left: 40rpx;
  304. }
  305. .imgs-box{
  306. margin-top: 120rpx;
  307. image{
  308. width: 100%;
  309. margin-bottom: 40rpx;
  310. }
  311. }
  312. }
  313. </style>