voiceDetail.vue 11 KB

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