|
@@ -0,0 +1,284 @@
|
|
|
+<template>
|
|
|
+ <view class="voice-detail" v-if="isAuth">
|
|
|
+ <view class="section-name">{{info.SectionName}}</view>
|
|
|
+ <view class="title">{{info.BroadcastName}}</view>
|
|
|
+ <view class="time">发布时间:{{info.CreateTime|formatTime}}</view>
|
|
|
+ <view class="flex audio-box">
|
|
|
+ <image
|
|
|
+ :src="paused?'../../../static/voice/pause.png':'../../../static/voice/playing.png'"
|
|
|
+ mode="aspectFill"
|
|
|
+ @click="handlePlayAudio"
|
|
|
+ />
|
|
|
+ <slider
|
|
|
+ activeColor="#E6B77D"
|
|
|
+ :max="duration"
|
|
|
+ :value="curTime"
|
|
|
+ @change="handleAudioSliderChange($event)"
|
|
|
+ block-size="12"
|
|
|
+ class="slider"
|
|
|
+ />
|
|
|
+ <text class="left-time">{{curTime|formatVoiceTime}}</text>
|
|
|
+ <text class="right-time">{{duration|formatVoiceTime}}</text>
|
|
|
+ </view>
|
|
|
+ <image class="del-btn" src="@/static/voice/del.png" mode="widthFix" @click="handleDel" v-if="info.IsAuthor"/>
|
|
|
+ <image class="publish-btn" src="@/static/voice/publish.png" mode="widthFix" @click="handleSendMsg" v-if="info.CouldSendMsg"/>
|
|
|
+
|
|
|
+ <van-dialog id="van-dialog" />
|
|
|
+ </view>
|
|
|
+ <noAuth :info="noAuthData" v-else/>
|
|
|
+
|
|
|
+</template>
|
|
|
+
|
|
|
+<script>
|
|
|
+import {apiVoicePlayRecord,apiVoiceDel,apiVoiceDetail,apiVoiceSendMsg} from '@/api/voice'
|
|
|
+import {apiGetSceneToParams} from '@/api/common'
|
|
|
+import noAuth from '@/pages/voice/components/noAuth.vue'
|
|
|
+const moment=require('@/utils/moment-with-locales.min')
|
|
|
+let innerAudioContext = uni.createInnerAudioContext();//播放音频实例
|
|
|
+export default {
|
|
|
+ components:{
|
|
|
+ noAuth
|
|
|
+ },
|
|
|
+ filters:{
|
|
|
+ formatTime(e){
|
|
|
+ return moment(e).format('YYYY-MM-DD HH:mm:ss')
|
|
|
+ },
|
|
|
+ formatVoiceTime(e){
|
|
|
+ let m=parseInt(e/60)
|
|
|
+ let s=parseInt(e%60)
|
|
|
+ return `${m>9?m:'0'+m}:${s>9?s:'0'+s}`
|
|
|
+ }
|
|
|
+ },
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ voiceId:'',
|
|
|
+ isAuth:true,
|
|
|
+ noAuthData:null,
|
|
|
+ info:{},
|
|
|
+
|
|
|
+ curTime:0,
|
|
|
+ duration:0,
|
|
|
+ paused:true,
|
|
|
+
|
|
|
+ isStartPlay:true,//是否从头播放的
|
|
|
+ }
|
|
|
+ },
|
|
|
+ onLoad(options){
|
|
|
+ this.init(options)
|
|
|
+ },
|
|
|
+ onShow(){
|
|
|
+ innerAudioContext=uni.createInnerAudioContext();
|
|
|
+ this.listenAudio()
|
|
|
+ },
|
|
|
+ onShareAppMessage(){
|
|
|
+ const title=`${this.info.SectionName}:${this.info.BroadcastName}`
|
|
|
+ return {
|
|
|
+ title:title,
|
|
|
+ imageUrl:this.info.ImgUrl
|
|
|
+ }
|
|
|
+ },
|
|
|
+ onHide(){
|
|
|
+ innerAudioContext.pause()
|
|
|
+ },
|
|
|
+ onUnload(){
|
|
|
+ innerAudioContext.destroy()
|
|
|
+ this.paused=true
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ async init(options){
|
|
|
+ if(options.scene){
|
|
|
+ const res=await apiGetSceneToParams({scene_key:options.scene})
|
|
|
+ if(res.code===200){
|
|
|
+ const obj=JSON.parse(res.data)
|
|
|
+ this.voiceId=obj.voiceId
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ this.voiceId=options.voiceId||0
|
|
|
+ }
|
|
|
+ this.getDetail()
|
|
|
+ },
|
|
|
+
|
|
|
+ async getDetail(){
|
|
|
+ const res=await apiVoiceDetail({broadcast_id:Number(this.voiceId)})
|
|
|
+ if(res.code===200){
|
|
|
+ this.info=res.data
|
|
|
+ this.duration=Number(res.data.VoicePlaySeconds)||0
|
|
|
+ this.isAuth=true
|
|
|
+ }else if(res.code===403){
|
|
|
+ this.isAuth=false
|
|
|
+ this.noAuthData=res.data
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ //删除
|
|
|
+ handleDel(){
|
|
|
+ this.$dialog.confirm({
|
|
|
+ title:'',
|
|
|
+ message: '确定要删除该语音播报吗?',
|
|
|
+ confirmButtonText:'确定'
|
|
|
+ }).then(()=>{
|
|
|
+ apiVoiceDel({broadcast_id:Number(this.voiceId)}).then(res=>{
|
|
|
+ if(res.code===200){
|
|
|
+ uni.showToast({
|
|
|
+ title:'操作成功',
|
|
|
+ icon:'none'
|
|
|
+ })
|
|
|
+ setTimeout(() => {
|
|
|
+ uni.$emit('addVoiceSuccess')
|
|
|
+ uni.switchTab({
|
|
|
+ url: '/pages/voice/voice'
|
|
|
+ });
|
|
|
+ }, 1000);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }).catch(()=>{})
|
|
|
+ },
|
|
|
+
|
|
|
+ // 推送消息
|
|
|
+ handleSendMsg(){
|
|
|
+ this.$dialog.confirm({
|
|
|
+ title:'',
|
|
|
+ message: '该操作将推送模板消息和客群,确认推送吗?',
|
|
|
+ confirmButtonText:'确认'
|
|
|
+ }).then(()=>{
|
|
|
+ apiVoiceSendMsg({broadcast_id:Number(this.voiceId)}).then(res=>{
|
|
|
+ if(res.code===200){
|
|
|
+ uni.showToast({
|
|
|
+ title:'操作成功',
|
|
|
+ icon:'none'
|
|
|
+ })
|
|
|
+ setTimeout(() => {
|
|
|
+ uni.$emit('addVoiceSuccess')
|
|
|
+ uni.switchTab({
|
|
|
+ url: '/pages/voice/voice'
|
|
|
+ });
|
|
|
+ }, 1000);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }).catch(()=>{})
|
|
|
+ },
|
|
|
+
|
|
|
+ //上报音频播放记录
|
|
|
+ async handleVoicePlayRecord(){
|
|
|
+ const res=await apiVoicePlayRecord({
|
|
|
+ broadcast_id:Number(this.voiceId)
|
|
|
+ })
|
|
|
+ if(res.code===200){
|
|
|
+ console.log('上报音频播放记录');
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ //点击播放\暂停音频
|
|
|
+ handlePlayAudio(){
|
|
|
+ if(this.isStartPlay){
|
|
|
+ this.handleVoicePlayRecord()
|
|
|
+ }
|
|
|
+ innerAudioContext.src=this.info.VoiceUrl
|
|
|
+ this.isStartPlay=false
|
|
|
+ innerAudioContext.obeyMuteSwitch=false
|
|
|
+ if(this.paused){
|
|
|
+ innerAudioContext.play()
|
|
|
+ }else{
|
|
|
+ innerAudioContext.pause()
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ //音频播放事件
|
|
|
+ listenAudio(){
|
|
|
+ innerAudioContext.onPlay(()=>{
|
|
|
+ console.log('开始播放录音');
|
|
|
+ this.paused=false
|
|
|
+ })
|
|
|
+ innerAudioContext.onPause(()=>{
|
|
|
+ console.log('录音播放暂停');
|
|
|
+ this.paused=true
|
|
|
+ })
|
|
|
+ innerAudioContext.onEnded(()=>{
|
|
|
+ console.log('录音播放自然结束');
|
|
|
+ this.paused=true
|
|
|
+ this.curTime=0
|
|
|
+ this.isStartPlay=true
|
|
|
+ })
|
|
|
+ innerAudioContext.onTimeUpdate(()=>{
|
|
|
+ // console.log('时间更新');
|
|
|
+ this.curTime=parseInt(innerAudioContext.currentTime)
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+ //拖动音频播放进度条
|
|
|
+ handleAudioSliderChange(e){
|
|
|
+ const value=e.detail.value
|
|
|
+ innerAudioContext.seek(value)
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ },
|
|
|
+}
|
|
|
+</script>
|
|
|
+
|
|
|
+<style lang="scss" scoped>
|
|
|
+ .voice-detail{
|
|
|
+ padding: 50rpx 34rpx;
|
|
|
+ .section-name{
|
|
|
+ background: #FDF8F2;
|
|
|
+ border-radius: 8rpx;
|
|
|
+ border: 1px solid #E3B377;
|
|
|
+ display: inline-block;
|
|
|
+ padding: 19rpx 27rpx;
|
|
|
+ margin-bottom: 40rpx;
|
|
|
+ }
|
|
|
+ .title{
|
|
|
+ font-size: 32rpx;
|
|
|
+ line-height: 38rpx;
|
|
|
+ margin-bottom: 20rpx;
|
|
|
+ }
|
|
|
+ .time{
|
|
|
+ color: #999;
|
|
|
+ font-size: 28rpx;
|
|
|
+ line-height: 33rpx;
|
|
|
+ }
|
|
|
+ .audio-box{
|
|
|
+ background-color: #FDF8F2;
|
|
|
+ height: 123rpx;
|
|
|
+ align-items: center;
|
|
|
+ margin-top: 50rpx;
|
|
|
+ margin-bottom: 40rpx;
|
|
|
+ padding: 0 30rpx;
|
|
|
+ position: relative;
|
|
|
+ .left-time{
|
|
|
+ position: absolute;
|
|
|
+ bottom: 20rpx;
|
|
|
+ left: 100rpx;
|
|
|
+ color: #999999;
|
|
|
+ font-size: 20rpx;
|
|
|
+ }
|
|
|
+ .right-time{
|
|
|
+ position: absolute;
|
|
|
+ bottom: 20rpx;
|
|
|
+ right: 40rpx;
|
|
|
+ color: #999999;
|
|
|
+ font-size: 20rpx;
|
|
|
+ }
|
|
|
+ image{
|
|
|
+ width: 40rpx;
|
|
|
+ height: 48rpx;
|
|
|
+ flex-shrink: 0;
|
|
|
+ margin-right: 30rpx;
|
|
|
+ }
|
|
|
+ .slider{
|
|
|
+ flex: 1;
|
|
|
+ margin: 0 10rpx;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ .del-btn{
|
|
|
+ float: left;
|
|
|
+ width: 36rpx;
|
|
|
+ height: 36rpx;
|
|
|
+ }
|
|
|
+ .publish-btn{
|
|
|
+ float: right;
|
|
|
+ width: 36rpx;
|
|
|
+ height: 36rpx;
|
|
|
+ }
|
|
|
+ }
|
|
|
+</style>
|