更改语音

This commit is contained in:
zoujiandong 2024-05-27 09:13:02 +08:00
parent 0c06201451
commit 9649d0a651
6 changed files with 47 additions and 6 deletions

View File

@ -37,6 +37,7 @@ Component({
lifetimes: { lifetimes: {
detached() { detached() {
myaudio.stop(); myaudio.stop();
wx.setStorageSync('currentAudioId', '')
}, },
}, },
@ -80,6 +81,8 @@ Component({
const { id } = e.currentTarget.dataset; const { id } = e.currentTarget.dataset;
const { audioSave } = this.data; const { audioSave } = this.data;
console.log(id);
wx.setStorageSync('currentAudioId',id)
this.triggerEvent("closeAudio",false) this.triggerEvent("closeAudio",false)
// 设置状态 // 设置状态
audioSave.forEach((message, index) => { audioSave.forEach((message, index) => {
@ -128,7 +131,9 @@ Component({
return; return;
}); });
}, },
stopmy(){
myaudio.stop();
},
// 音频停止 // 音频停止
audioStop(e) { audioStop(e) {
const { key } = e.currentTarget.dataset; const { key } = e.currentTarget.dataset;

View File

@ -120,6 +120,7 @@ Component({
serviceInfo:{}, serviceInfo:{},
baseInfo:{}, baseInfo:{},
family_id:'', family_id:'',
fresh:true,
patient_user_id:'', patient_user_id:'',
extensionArea: false, extensionArea: false,
sendMessageBtn: false, sendMessageBtn: false,
@ -188,10 +189,16 @@ Component({
lifetimes: { lifetimes: {
attached() { attached() {
let _this = this; let _this = this;
// 加载声音录制管理器 // 加载声音录制管理器
this.recorderManager = wx.getRecorderManager(); this.recorderManager = wx.getRecorderManager();
this.recorderManager.onStop(async(resData) => { this.recorderManager.onStop(async(resData) => {
this.setData({
fresh:!this.data.fresh
})
wx.hideLoading(); wx.hideLoading();
if (this.data.canSend) { if (this.data.canSend) {
if (resData.duration < 1000) { if (resData.duration < 1000) {
wx.showToast({ wx.showToast({
@ -596,6 +603,10 @@ this.setData({
}, },
// 长按录音 // 长按录音
handleLongPress(e) { handleLongPress(e) {
this.triggerEvent('closeAudio',false);
if(this.timer){
clearInterval(this.timer)
}
this.openRecord(e,this.recording) this.openRecord(e,this.recording)
}, },
recording(e,THIS){ recording(e,THIS){
@ -612,11 +623,11 @@ this.setData({
encodeBitRate: 192000, // 编码码率 encodeBitRate: 192000, // 编码码率
format: 'aac', // 音频格式,选择此格式创建的音频消息,可以在即时通信 IM 全平台Android、iOS、微信小程序和Web互通 format: 'aac', // 音频格式,选择此格式创建的音频消息,可以在即时通信 IM 全平台Android、iOS、微信小程序和Web互通
}); });
THIS.timer=setInterval(()=>{ THIS.timer=setInterval(()=>{
if(THIS.data.recordtime>=60){ if(THIS.data.recordtime>=60){
THIS.handleTouchEnd(); THIS.handleTouchEnd();
clearInterval(THIS.timer); //clearInterval(THIS.timer);
}; };
THIS.setData({ THIS.setData({

View File

@ -22,11 +22,21 @@
bindlinechange="inputBindLinechange" bindlinechange="inputBindLinechange"
/> />
</view> </view>
<view wx:if="{{isAudio}}" class="TUI-message-input-main" <view wx:if="{{isAudio && fresh}}"
id="talk1"
class="TUI-message-input-main"
catchlongpress="handleLongPress"
catchtouchmove="handleTouchMove"
catchtouchend="handleTouchEnd"
catchtouchcancel="handleTouchCancel"
style="display: flex; justify-content: center; font-size: 32rpx; font-family: PingFangSC-Regular; height: 30px">
<text >{{text}}</text>
</view>
<view wx:elif="{{isAudio && !fresh}}"
id="talk2" class="TUI-message-input-main"
catchlongpress="handleLongPress" catchlongpress="handleLongPress"
catchtouchmove="handleTouchMove" catchtouchmove="handleTouchMove"
catchtouchend="handleTouchEnd" catchtouchend="handleTouchEnd"
catchtap="handleTouchCancel"
catchtouchcancel="handleTouchCancel" catchtouchcancel="handleTouchCancel"
style="display: flex; justify-content: center; font-size: 32rpx; font-family: PingFangSC-Regular; height: 30px"> style="display: flex; justify-content: center; font-size: 32rpx; font-family: PingFangSC-Regular; height: 30px">
<text >{{text}}</text> <text >{{text}}</text>

View File

@ -320,12 +320,21 @@ Component({
}, },
closeAudio(data){ closeAudio(data){
//关闭其他语音 //关闭其他语音
let currentAudioId= wx.getStorageSync('currentAudioId');
this.data.messageList.forEach((item)=>{ this.data.messageList.forEach((item)=>{
if(item.type=="TIMSoundElem"){ if(item.type=="TIMSoundElem"){
let ele=this.selectComponent('#audio'+item.ID); let ele=this.selectComponent('#audio'+item.ID);
if(item.ID!=currentAudioId){
ele.stopmy();
}
ele.setData({ ele.setData({
isPlay:false isPlay:false
}) })
//console.log(ele);
//ele.stopmy();
//console.log(ele)
} }

View File

@ -234,6 +234,9 @@ Component({
* 组件的方法列表 * 组件的方法列表
*/ */
methods: { methods: {
closeAudio(){
this.selectComponent('#MessageList').closeAudio();
},
checkChuFang(order_inquiry_id){ checkChuFang(order_inquiry_id){
api.getDoctorPrescriptionCheck({order_inquiry_id: order_inquiry_id}).then(response => { api.getDoctorPrescriptionCheck({order_inquiry_id: order_inquiry_id}).then(response => {
let status = response.data.status let status = response.data.status

View File

@ -73,8 +73,11 @@
<!-- wx:if="{{baseInfo.inquiry_status==4}}" --> <!-- wx:if="{{baseInfo.inquiry_status==4}}" -->
<view class="input-area" style="{{input_area_style}}" > <view class="input-area" style="{{input_area_style}}" >
<!-- wx:if="{{showChat}}" --> <!-- wx:if="{{showChat}}" -->
<!-- bind:closeAudio="closeAudio" -->
<view class="message-input" style="{{viewData.style}}" > <view class="message-input" style="{{viewData.style}}" >
<MessageInput bind:myhandleExtensions="myhandleExtensions" id="MessageInput" inquiry_type="{{inquiry_type}}" baseInfo="{{baseInfo}}" order_inquiry_id="{{order_inquiry_id}}" conversation="{{conversation}}" from="{{from}}" hasCallKit="{{hasCallKit}}" <MessageInput bind:myhandleExtensions="myhandleExtensions"
bind:closeAudio="closeAudio"
id="MessageInput" inquiry_type="{{inquiry_type}}" baseInfo="{{baseInfo}}" order_inquiry_id="{{order_inquiry_id}}" conversation="{{conversation}}" from="{{from}}" hasCallKit="{{hasCallKit}}"
serviceInfo="{{serviceInfo}}" serviceInfo="{{serviceInfo}}"
isEditTime="{{isEditTime}}" isEditTime="{{isEditTime}}"
videoInfo="{{videoInfo}}" videoInfo="{{videoInfo}}"