jwyu 2 gadi atpakaļ
vecāks
revīzija
8d992ec219
2 mainītis faili ar 53 papildinājumiem un 4 dzēšanām
  1. 18 2
      pages-voice/addVoice.vue
  2. 35 2
      pages/voice/voice.vue

+ 18 - 2
pages-voice/addVoice.vue

@@ -116,6 +116,7 @@
 import {apiVoiceSectionList} from '@/api/voice'
 import {baseApiUrl} from '@/utils/config.js'
 import CryptoJS from '@/utils/crypto.js'
+import uniAsync from "@/utils/uni-async.js"; // uni api async 化
 const recorderManager = wx.getRecorderManager();//录音实例
 const innerAudioContext = uni.createInnerAudioContext();//播放音频实例
 let TIMER=null//计时器
@@ -147,7 +148,8 @@ export default {
                 variety_name:'',
                 variety_id:'',
                 section_id:'',
-                section_name:''
+                section_name:'',
+                img_url:''
             },
 
             recorderStatus:'start',//当前录音状态 start开始 doing正在录音 stop停止录音 pause录音暂停
@@ -234,7 +236,18 @@ export default {
         },
 
         //点击录音操作按钮
-        handleClickBtn(){
+        async handleClickBtn(){
+            const setRes=await uniAsync.getSetting()
+            console.log(setRes.authSetting['scope.record']);
+            if(!setRes.authSetting['scope.record']){
+                uni.showToast({
+                    title:'请打开麦克风交流',
+                    icon:'none'
+                })
+                uni.openSetting()
+                return
+            }
+             
             if(this.recorderStatus==='start'){
                 recorderManager.start({
                     duration:600000,
@@ -354,6 +367,7 @@ export default {
             this.form.section_name=detail.SectionName
             this.form.variety_name=this.options[this.mainActiveIndex].VarietyName
             this.form.variety_id=this.options[this.mainActiveIndex].VarietyId
+            this.form.img_url=detail.ImgUrl
             this.showFilter=false
         },
 
@@ -376,6 +390,7 @@ export default {
                 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
             }
@@ -397,6 +412,7 @@ export default {
                             icon:'success'
                         })
                         setTimeout(() => {
+                            uni.$emit('addVoiceSuccess')
                             uni.navigateBack()
                         }, 1000);
                     }else{

+ 35 - 2
pages/voice/voice.vue

@@ -70,7 +70,7 @@
 </template>
 
 <script>
-import {apiVoiceList,apiVoiceSectionList,apiVoicePlayRecord} from '@/api/voice'
+import {apiVoiceList,apiVoiceSectionList,apiVoicePlayRecord,apiVoiceDel} from '@/api/voice'
 import {apiGetSceneToParams} from '@/api/common'
 import noAuth from './components/noAuth.vue'
 const moment=require('@/utils/moment-with-locales.min')
@@ -120,7 +120,11 @@ export default {
         this.init(options)
         this.getOptionsList()
         this.listenAudio()
+        this.addListenVoiceSuccess()
     },
+    onUnload(){
+		uni.$off('addVoiceSuccess')
+	},
     onShareAppMessage({from,target}) {
         console.log(from,target);
         let path='/pages/voice/voice?voiceId=0'
@@ -129,7 +133,7 @@ export default {
         if(from=='button'){
             title=`${target.dataset.item.SectionName}:${target.dataset.item.BroadcastName}`
             path=`/pages/voice/voice?voiceId=${target.dataset.item.BroadcastId}`
-            imageUrl=''
+            imageUrl=target.dataset.item.ImgUrl
         }
         return {
             title:title,
@@ -155,6 +159,18 @@ export default {
     },
 
     methods: {
+        // 监听添加音频成功刷新列表
+        addListenVoiceSuccess(){
+            uni.$on('addVoiceSuccess',()=>{
+                this.voiceId=0
+                this.page=1
+                this.list=[]
+                this.finished=false
+                this.getVoiceList()
+                this.getOptionsList()
+            })
+        },
+
         async init(options){
             if(options.scene){
                 const res=await apiGetSceneToParams({scene_key:options.scene})
@@ -183,6 +199,22 @@ export default {
                 if(arr.length===0){
                     this.finished=true
                 }
+
+                // 如果有voiceId 则说明是分享进入的 如果没有数据则提示
+                if(this.voiceId!=0&&arr.length===0){
+                    uni.showToast({
+                        title:'该语音播报不存在',
+                        icon:'none'
+                    })
+                    setTimeout(() => {
+                        this.voiceId=0
+                        this.page=1
+                        this.list=[]
+                        this.finished=false
+                        this.getVoiceList()
+                        this.getOptionsList()
+                    }, 1500);
+                }
             }else if(res.code===403){
                 //无权限用户
                 this.isAuth=false
@@ -257,6 +289,7 @@ export default {
             
             //没有初始化时
             if(!innerAudioContext.src){
+                this.listenAudio()
                 this.temAudio.id=item.BroadcastId
                 this.temAudio.duration=item.VoicePlaySeconds
                 this.temAudio.curTime=item.VoicePlaySeconds