|
@@ -29,6 +29,24 @@
|
|
|
@click-icon="showFilter=true"
|
|
|
/>
|
|
|
|
|
|
+ <!-- 上传图片部分 -->
|
|
|
+ <view
|
|
|
+ class="flex upload-img-box"
|
|
|
+ v-if="recorderStatus!=='doing'&&recorderStatus!=='pause'"
|
|
|
+ :style="[{'height':recorderStatus==='stop'&&'auto'},{'border-bottom':recorderStatus==='stop'?'1px solid #E6E6E6':''}]"
|
|
|
+ >
|
|
|
+ <view class="item" v-for="(item,index) in imgList" :key="item" @click="handlePreViewImg(item)">
|
|
|
+ <image :src="item" mode="aspectFill"/>
|
|
|
+ <view class="del-btn" @click.stop="handleDelImg(index)">
|
|
|
+ <van-icon name="cross" size="12" style="position: absolute;left:16rpx;top:8rpx" color="#ffffff"/>
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
+ <view class="item add-btn" @click="handleUploadImg" v-if="imgList.length<5">
|
|
|
+ <image src="./static/camera.png" mode="aspectFill" />
|
|
|
+ </view>
|
|
|
+
|
|
|
+ </view>
|
|
|
+
|
|
|
<view class="flex audio-box" v-if="recorderStatus==='stop'">
|
|
|
<image
|
|
|
:src="temAudio.paused?'../../../static/voice/pause.png':'../../../static/voice/playing.png'"
|
|
@@ -49,14 +67,14 @@
|
|
|
<image src="./static/del.png" mode="aspectFill" />
|
|
|
<text>删除</text>
|
|
|
</view>
|
|
|
-
|
|
|
+ <view class="pre_publish_time" v-if="voiceId!=0">定时发布时间:{{pre_publish_time}}</view>
|
|
|
</view>
|
|
|
|
|
|
|
|
|
- <view class="empty-voice-box" v-if="recorderStatus==='start'">
|
|
|
+ <!-- <view class="empty-voice-box" v-if="recorderStatus==='start'">
|
|
|
<image src="./static/record.png" mode="aspectFill" />
|
|
|
<view>无录音(录音时长超过十分钟自动结束)</view>
|
|
|
- </view>
|
|
|
+ </view> -->
|
|
|
|
|
|
<view class="animat-box" v-if="recorderStatus==='doing'||recorderStatus==='pause'">
|
|
|
<view class="con-box">
|
|
@@ -65,10 +83,10 @@
|
|
|
<image :class="['img move3',recorderStatus==='doing'?'animat-run':'animat-pause']" src="./static/record-img.png" mode="widthFix" />
|
|
|
</view>
|
|
|
<view class="bot-text">{{time|formatTime}}</view>
|
|
|
- </view>
|
|
|
+ </view>
|
|
|
|
|
|
<view class="sound-record-wrap" v-if="recorderStatus!=='stop'">
|
|
|
- <view class="top-text">点击开始录音</view>
|
|
|
+ <view class="top-text" v-show="recorderStatus=='start'">点击开始录音</view>
|
|
|
<image class="btn" :src="btnImg" mode="aspectFill" @click="handleClickBtn" />
|
|
|
<view
|
|
|
class="del-btn"
|
|
@@ -81,9 +99,13 @@
|
|
|
v-if="recorderStatus!=='start'"
|
|
|
@click="handleEndRecorder"
|
|
|
>完成</view>
|
|
|
+ <view style="text-align:center;color:#999;margin-top:44rpx" v-if="recorderStatus==='start'">无录音(录音时长超过十分钟自动结束)</view>
|
|
|
</view>
|
|
|
|
|
|
- <view class="publish-btn" v-if="recorderStatus==='stop'" @click="handlePublish">发布</view>
|
|
|
+ <view class="publish-btn" v-if="recorderStatus==='stop'">
|
|
|
+ <text @click="handlePublish('time')">定时发布</text>
|
|
|
+ <text @click="handlePublish">立即发布</text>
|
|
|
+ </view>
|
|
|
|
|
|
<!-- 筛选弹窗 -->
|
|
|
<van-popup
|
|
@@ -109,14 +131,68 @@
|
|
|
/>
|
|
|
</view>
|
|
|
</van-popup>
|
|
|
+
|
|
|
+ <!-- 选择时间弹窗 -->
|
|
|
+ <van-popup
|
|
|
+ :show="showTime"
|
|
|
+ position="bottom"
|
|
|
+ :close-on-click-overlay="true"
|
|
|
+ @close="showTime = false"
|
|
|
+ round
|
|
|
+ >
|
|
|
+ <van-datetime-picker
|
|
|
+ title="设置发布时间"
|
|
|
+ type="datetime"
|
|
|
+ :value="selectTime"
|
|
|
+ :min-date="minDate"
|
|
|
+ @confirm="handleConfirmTime"
|
|
|
+ @cancel="showTime = false"
|
|
|
+ />
|
|
|
+ </van-popup>
|
|
|
+
|
|
|
+ <!-- <van-dialog id="van-dialog" /> -->
|
|
|
+ <!-- 发布弹窗 -->
|
|
|
+ <van-dialog
|
|
|
+ use-slot
|
|
|
+ :show="showPublish"
|
|
|
+ confirm-button-text="发布且推送"
|
|
|
+ cancel-button-text="仅发布"
|
|
|
+ show-cancel-button
|
|
|
+ @confirm="handleConfirmPublish(1)"
|
|
|
+ @cancel="handleConfirmPublish(0)"
|
|
|
+ @close="showPublish=false"
|
|
|
+ >
|
|
|
+ <view style="padding:40px 20px 20px;text-align:center;position: relative;">
|
|
|
+ 发布后将推送模板消息和客群,确认发布吗?
|
|
|
+ <van-icon name="cross" size="20" style="position: absolute;right:10px;top:10px" color="#6666" @click="showPublish=false"/>
|
|
|
+ </view>
|
|
|
+ </van-dialog>
|
|
|
+
|
|
|
+ <!-- 定时发布提示弹窗 -->
|
|
|
+ <van-dialog
|
|
|
+ use-slot
|
|
|
+ :show="showTimeAttention"
|
|
|
+ confirm-button-text="知道了"
|
|
|
+ confirm-button-color="#E3B377"
|
|
|
+ @confirm="showTime=true"
|
|
|
+ @close="showTimeAttention=false,showTime=true"
|
|
|
+ >
|
|
|
+ <view style="padding:40px 20px 20px;text-align:center;position: relative;">
|
|
|
+ 设置定时发布后,会在设定的时间发布语音播报并推送模板消息
|
|
|
+ <van-icon name="cross" size="20" style="position: absolute;right:10px;top:10px" color="#666" @click="showTimeAttention=false,showTime=true"/>
|
|
|
+ </view>
|
|
|
+ </van-dialog>
|
|
|
</view>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
-import {apiVoiceSectionList} from '@/api/voice'
|
|
|
+import {apiVoiceSectionList,apiVoiceSendMsg,apiVoiceAdd,apiVoiceEdit,apiVoicePublish,apiVoiceDetail} from '@/api/voice'
|
|
|
import {baseApiUrl} from '@/utils/config.js'
|
|
|
+import {apiGetSceneToParams} from '@/api/common'
|
|
|
import CryptoJS from '@/utils/crypto.js'
|
|
|
import uniAsync from "@/utils/uni-async.js"; // uni api async 化
|
|
|
+import {uploadImg,commonUploadAudio} from '@/utils/upload'
|
|
|
+const dayjs=require('@/utils/dayjs.min')
|
|
|
const recorderManager = wx.getRecorderManager();//录音实例
|
|
|
let innerAudioContext = uni.createInnerAudioContext();//播放音频实例
|
|
|
let TIMER=null//计时器
|
|
@@ -149,15 +225,18 @@ export default {
|
|
|
variety_id:'',
|
|
|
section_id:'',
|
|
|
section_name:'',
|
|
|
- img_url:''
|
|
|
+ img_url:'',//分享时的底图
|
|
|
},
|
|
|
+ voiceId:0,
|
|
|
+ voiceUrl:'',//编辑音频地址
|
|
|
+ pre_publish_time:'',
|
|
|
|
|
|
recorderStatus:'start',//当前录音状态 start开始 doing正在录音 stop停止录音 pause录音暂停
|
|
|
time:0,
|
|
|
isReset:false,//是否点击了重置
|
|
|
|
|
|
temAudio:{
|
|
|
- url:'',//临时音频地址
|
|
|
+ url:'',//音频地址
|
|
|
duration:'',//时长
|
|
|
size:'',//大小
|
|
|
curTime:0,//播放时当前播放的时间
|
|
@@ -169,17 +248,25 @@ export default {
|
|
|
mainActiveIndex:0,
|
|
|
activeId:0,//选择的板块id
|
|
|
|
|
|
+ showPublish:false,
|
|
|
+
|
|
|
+ imgList:[],
|
|
|
+ showTime:false,
|
|
|
+ showTimeAttention:false,
|
|
|
+ selectTime:new Date().getTime(),
|
|
|
+ minDate:new Date().getTime()+600000,
|
|
|
}
|
|
|
},
|
|
|
- onLoad(){
|
|
|
+ onLoad(options){
|
|
|
// 调取用户授权使用麦克风
|
|
|
uni.authorize({
|
|
|
scope: 'scope.record',
|
|
|
success() {}
|
|
|
})
|
|
|
this.listenVoice()
|
|
|
-
|
|
|
this.getOptionsList()
|
|
|
+
|
|
|
+ this.init(options)
|
|
|
},
|
|
|
onShow(){
|
|
|
innerAudioContext = uni.createInnerAudioContext()
|
|
@@ -191,8 +278,45 @@ export default {
|
|
|
},
|
|
|
onUnload(){
|
|
|
innerAudioContext.destroy()
|
|
|
+ clearInterval(TIMER)
|
|
|
},
|
|
|
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=Number(obj.voiceId)
|
|
|
+ this.getVoiceDetail()
|
|
|
+ }
|
|
|
+ }else if(options.voiceId){
|
|
|
+ this.voiceId=Number(options.voiceId)
|
|
|
+ this.getVoiceDetail()
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ //语音详情
|
|
|
+ async getVoiceDetail(){
|
|
|
+ uni.setNavigationBarTitle({ title: '编辑语音' })
|
|
|
+ const res=await apiVoiceDetail({broadcast_id:Number(this.voiceId)})
|
|
|
+ if(res.code===200){
|
|
|
+ this.form.title=res.data.BroadcastName
|
|
|
+ this.form.variety_name=res.data.VarietyName
|
|
|
+ this.form.variety_id=res.data.VarietyId
|
|
|
+ this.form.section_id=res.data.SectionId
|
|
|
+ this.form.section_name=res.data.SectionName
|
|
|
+ this.voiceUrl=res.data.VoiceUrl
|
|
|
+ this.temAudio.url=res.data.VoiceUrl
|
|
|
+ this.temAudio.duration=res.data.VoicePlaySeconds
|
|
|
+ this.temAudio.size=res.data.VoiceSize
|
|
|
+ this.activeId=res.data.SectionId
|
|
|
+ this.imgList=res.data.Imgs||[]
|
|
|
+ this.pre_publish_time=dayjs(res.data.PrePublishTime).format('YYYY-MM-DD HH:mm')
|
|
|
+ this.selectTime=dayjs(res.data.PrePublishTime).valueOf()
|
|
|
+ this.recorderStatus='stop'
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
//录音事件
|
|
|
listenVoice(){
|
|
|
recorderManager.onStart(()=>{
|
|
@@ -298,6 +422,7 @@ export default {
|
|
|
//点击播放\暂停音频
|
|
|
handlePlayAudio(){
|
|
|
innerAudioContext.src=this.temAudio.url
|
|
|
+ innerAudioContext.obeyMuteSwitch=false
|
|
|
if(this.temAudio.paused){
|
|
|
innerAudioContext.play()
|
|
|
}else{
|
|
@@ -390,7 +515,7 @@ export default {
|
|
|
},
|
|
|
|
|
|
// 发布
|
|
|
- handlePublish(){
|
|
|
+ async handlePublish(type){
|
|
|
if(!this.form.title||!this.form.variety_id){
|
|
|
uni.showToast({
|
|
|
title:'请将内容填写完整',
|
|
@@ -398,29 +523,68 @@ export default {
|
|
|
})
|
|
|
return
|
|
|
}
|
|
|
- let formData={
|
|
|
+
|
|
|
+ if(type==='time'){//定时发布
|
|
|
+ this.showTimeAttention=true
|
|
|
+ }else{
|
|
|
+ this.showPublish=true
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ //确认发布 publishType 发布类型: 0-仅发布 1-发布并推送 2-定时发布
|
|
|
+ async handleConfirmPublish(publishType){
|
|
|
+
|
|
|
+ //上传音频
|
|
|
+ if(this.temAudio.url!=this.voiceUrl){
|
|
|
+ const voiceRes=await commonUploadAudio(this.temAudio.url)
|
|
|
+ if(voiceRes.code===200){
|
|
|
+ this.temAudio.url=voiceRes.data.audio_url
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //新增、编辑语音
|
|
|
+ let params={
|
|
|
broadcast_name:this.form.title,
|
|
|
section_id:Number(this.form.section_id),
|
|
|
section_name:this.form.section_name,
|
|
|
variety_id:Number(this.form.variety_id),
|
|
|
variety_name:this.form.variety_name,
|
|
|
- img_url:this.form.img_url,
|
|
|
author_id:Number(this.$store.state.user.userInfo.user_id),
|
|
|
- author:this.$store.state.user.userInfo.real_name
|
|
|
+ author:this.$store.state.user.userInfo.real_name,
|
|
|
+ imgs:this.imgList.join(','),
|
|
|
+ voice_seconds:this.temAudio.duration.toString(),
|
|
|
+ voice_size:this.temAudio.size.toString(),
|
|
|
+ voice_url:this.temAudio.url
|
|
|
}
|
|
|
- uni.uploadFile({
|
|
|
- url: baseApiUrl + "/voice/broadcast/add",
|
|
|
- filePath: this.temAudio.url,
|
|
|
- name: 'file',
|
|
|
- header: {
|
|
|
- Authorization: this.$store.state.user.token,
|
|
|
- },
|
|
|
- formData: formData,
|
|
|
- success: (result) => {
|
|
|
- const { envVersion } = uni.getAccountInfoSync().miniProgram
|
|
|
- const res = envVersion === 'release' ? JSON.parse(CryptoJS.Des3Decrypt(result.data)) : JSON.parse(result.data);
|
|
|
- console.log(res);
|
|
|
- if(res.code===200){
|
|
|
+ wx.showLoading({
|
|
|
+ title: '发布中...',
|
|
|
+ mask: true,
|
|
|
+ success: (result) => {},
|
|
|
+ fail: () => {},
|
|
|
+ complete: () => {}
|
|
|
+ });
|
|
|
+ let addRes=null
|
|
|
+ if(this.voiceId!=0){//编辑语音
|
|
|
+ params.broadcast_id=this.voiceId
|
|
|
+ addRes=await apiVoiceEdit(params)
|
|
|
+ }else{
|
|
|
+ addRes=await apiVoiceAdd(params)
|
|
|
+ }
|
|
|
+ if(addRes.code===200){
|
|
|
+ let par={
|
|
|
+ broadcast_id:addRes.data.BroadcastId,
|
|
|
+ }
|
|
|
+ if(publishType===2){//定时发布
|
|
|
+ par.publish_type=2
|
|
|
+ par.pre_publish_time=dayjs(this.selectTime).format('YYYY-MM-DD HH:mm:ss')
|
|
|
+ }else{
|
|
|
+ par.publish_type=1
|
|
|
+ }
|
|
|
+ //发布语音
|
|
|
+ const publishRes=await apiVoicePublish(par)
|
|
|
+ wx.hideLoading();
|
|
|
+ if(publishRes.code===200){
|
|
|
+ if(publishType==0){//仅发布
|
|
|
uni.showToast({
|
|
|
title:'发布成功',
|
|
|
icon:'success'
|
|
@@ -429,26 +593,82 @@ export default {
|
|
|
uni.$emit('addVoiceSuccess')
|
|
|
uni.navigateBack()
|
|
|
}, 1000);
|
|
|
- }else{
|
|
|
+ }else if(publishType==1){//发布并推送
|
|
|
+ this.handleSendMsg(addRes.data.BroadcastId)
|
|
|
+ }else{////定时发布
|
|
|
uni.showToast({
|
|
|
- title:res.msg,
|
|
|
- icon:'none'
|
|
|
+ title:'定时发布成功',
|
|
|
+ icon:'success'
|
|
|
})
|
|
|
+ setTimeout(() => {
|
|
|
+ uni.$emit('addVoiceSuccess')
|
|
|
+ uni.navigateBack()
|
|
|
+ }, 1000);
|
|
|
}
|
|
|
- },
|
|
|
- fail: () => {
|
|
|
- console.log('发布失败');
|
|
|
+ }else{
|
|
|
uni.showToast({
|
|
|
- title:'发布失败,请稍后重试!',
|
|
|
+ title:publishRes.msg,
|
|
|
icon:'none'
|
|
|
})
|
|
|
- },
|
|
|
- complete: () => {
|
|
|
- console.log('con');
|
|
|
}
|
|
|
- });
|
|
|
-
|
|
|
- }
|
|
|
+ }else{
|
|
|
+ wx.hideLoading();
|
|
|
+ uni.showToast({
|
|
|
+ title:addRes.msg,
|
|
|
+ icon:'none'
|
|
|
+ })
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ //推送消息
|
|
|
+ handleSendMsg(id){
|
|
|
+ apiVoiceSendMsg({broadcast_id:id}).then(res=>{
|
|
|
+ if(res.code===200){
|
|
|
+ uni.showToast({
|
|
|
+ title:"发布&推送成功",
|
|
|
+ icon:'success'
|
|
|
+ })
|
|
|
+ setTimeout(() => {
|
|
|
+ uni.$emit('addVoiceSuccess')
|
|
|
+ uni.navigateBack()
|
|
|
+ }, 1000);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+ //图片上传
|
|
|
+ handleUploadImg(e){
|
|
|
+ uploadImg({count:5-this.imgList.length}).then(res=>{
|
|
|
+ this.imgList=[...this.imgList,...res]
|
|
|
+ }).catch(err=>{
|
|
|
+ console.log(err);
|
|
|
+ if(err.errMsg=='chooseImage:fail cancel') return
|
|
|
+ uni.showToast({
|
|
|
+ title:'上传失败,请重试!',
|
|
|
+ icon:'none'
|
|
|
+ })
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+ //预览图片
|
|
|
+ handlePreViewImg(item){
|
|
|
+ wx.previewImage({
|
|
|
+ urls:this.imgList,
|
|
|
+ current:item
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+ //删除图片
|
|
|
+ handleDelImg(index){
|
|
|
+ this.imgList.splice(index,1)
|
|
|
+ },
|
|
|
+
|
|
|
+ //选择时间
|
|
|
+ handleConfirmTime(e){
|
|
|
+ this.selectTime=e.detail
|
|
|
+ this.showTime=false
|
|
|
+ this.handleConfirmPublish(2)
|
|
|
+ },
|
|
|
|
|
|
},
|
|
|
}
|
|
@@ -508,7 +728,7 @@ page{
|
|
|
<style lang="scss" scoped>
|
|
|
.add-voice-page{
|
|
|
.empty-voice-box{
|
|
|
- height: 50vh;
|
|
|
+ height: 36vh;
|
|
|
padding-top: 150rpx;
|
|
|
image{
|
|
|
width: 140rpx;
|
|
@@ -563,6 +783,7 @@ page{
|
|
|
margin-bottom: 180rpx;
|
|
|
padding: 0 30rpx;
|
|
|
position: relative;
|
|
|
+ border-radius: 16rpx;
|
|
|
.left-time{
|
|
|
position: absolute;
|
|
|
bottom: 20rpx;
|
|
@@ -601,19 +822,82 @@ page{
|
|
|
margin-right: 10rpx;
|
|
|
}
|
|
|
}
|
|
|
+ .pre_publish_time{
|
|
|
+ position: absolute;
|
|
|
+ bottom: -50rpx;
|
|
|
+ left: 0;
|
|
|
+ color: #999999;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
.publish-btn{
|
|
|
- width: 390rpx;
|
|
|
- height: 80rpx;
|
|
|
+ // width: 390rpx;
|
|
|
+ // height: 80rpx;
|
|
|
+ // text-align: center;
|
|
|
+ // line-height: 80rpx;
|
|
|
+ // color: #fff;
|
|
|
+ // background: #E6B77D;
|
|
|
+ // font-size: 32rpx;
|
|
|
+ // border-radius: 40px;
|
|
|
+ // margin-left: auto;
|
|
|
+ // margin-right: auto;
|
|
|
text-align: center;
|
|
|
- line-height: 80rpx;
|
|
|
- color: #fff;
|
|
|
- background: #E6B77D;
|
|
|
- font-size: 32rpx;
|
|
|
- border-radius: 40px;
|
|
|
- margin-left: auto;
|
|
|
- margin-right: auto;
|
|
|
+ text{
|
|
|
+ width: 300rpx;
|
|
|
+ height: 80rpx;
|
|
|
+ text-align: center;
|
|
|
+ line-height: 80rpx;
|
|
|
+ display: inline-block;
|
|
|
+ font-size: 32rpx;
|
|
|
+ margin: 0 15rpx;
|
|
|
+ border-radius: 40rpx;
|
|
|
+ }
|
|
|
+ text:first-child{
|
|
|
+ border: 1px solid #E6B77D;
|
|
|
+ color: #E6B77D;
|
|
|
+ }
|
|
|
+ text:last-child{
|
|
|
+ background-color: #E6B77D;
|
|
|
+ color: #fff;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ .upload-img-box{
|
|
|
+ padding: 34rpx 4rpx 34rpx 34rpx;
|
|
|
+ flex-wrap: wrap;
|
|
|
+ height: 50vh;
|
|
|
+ align-content: flex-start;
|
|
|
+ .item{
|
|
|
+ width: 200rpx;
|
|
|
+ height: 200rpx;
|
|
|
+ margin-right: 30rpx;
|
|
|
+ margin-bottom: 30rpx;
|
|
|
+ flex-shrink: 0;
|
|
|
+ position: relative;
|
|
|
+ image{
|
|
|
+ width: 100%;
|
|
|
+ height: 100%;
|
|
|
+ }
|
|
|
+ .del-btn{
|
|
|
+ position: absolute;
|
|
|
+ right: 0;
|
|
|
+ top: 0;
|
|
|
+ width: 48rpx;
|
|
|
+ height: 48rpx;
|
|
|
+ background-color: rgba(0, 0, 0, 0.7);
|
|
|
+ border-radius: 0 0 0 48rpx;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ .add-btn{
|
|
|
+ background-color: #f7f7f7;
|
|
|
+ image{
|
|
|
+ width: 80rpx;
|
|
|
+ height: 80rpx;
|
|
|
+ position: absolute;
|
|
|
+ left: 60rpx;
|
|
|
+ top: 60rpx;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|