From 09f1cc2f3892012c85381cc87240a039267fc1e0 Mon Sep 17 00:00:00 2001
From: shuishen <1109946754@qq.com>
Date: Wed, 24 Nov 2021 09:56:59 +0800
Subject: [PATCH] 语音发送修改

---
 pages/groupChat/chatingQZ.vue |   70 ++++++++++++++++++++++++++++------
 components/submit/submit.vue  |    2 -
 pages/groupChat/chating.vue   |   33 ++++++++--------
 3 files changed, 74 insertions(+), 31 deletions(-)

diff --git a/components/submit/submit.vue b/components/submit/submit.vue
index 7deab6e..583d649 100644
--- a/components/submit/submit.vue
+++ b/components/submit/submit.vue
@@ -235,7 +235,6 @@
 				clearInterval(this.timer)
 				recorderManager.stop()
 				recorderManager.onStop((res) => {
-					console.log(res, 4589)
 					let data = {
 						voice: res.tempFilePath,
 						time: this.vlength
@@ -262,7 +261,6 @@
 							latitude: res.latitude,
 							longitude: res.longitude
 						}
-						this.send(data, 3)
 						console.log('位置名称' + res.name)
 						console.log('详细地址' + res.address)
 						console.log('维度' + res.latitude)
diff --git a/pages/groupChat/chating.vue b/pages/groupChat/chating.vue
index 8c8f014..802467a 100644
--- a/pages/groupChat/chating.vue
+++ b/pages/groupChat/chating.vue
@@ -3,12 +3,12 @@
 
 		<!-- 头部 -->
 		<u-navbar style="position: relative;" :is-fixed="false" :border-bottom="true" :is-back="true" :title="recName"
-			back-icon-color="#fff" :background="{ background: '#0BB9C8' }" title-color="#fff">
+			back-icon-color="#fff" :background="{ background: '#0BB9C8' }" :placeholder="true" title-color="#fff">
 
-			<view slot='right'>
+			<!-- 	<view slot='right'>
 				<u-icon @click="chatMessageDetail" class="set-icon" name="more-dot-fill" color="#fff" size="28">
 				</u-icon>
-			</view>
+			</view> -->
 		</u-navbar>
 
 
@@ -36,7 +36,7 @@
 						</view>
 						<!-- voice -->
 						<view class="message" v-if="item.messageType == 2">
-							<view class="msg-text voice" :style="{width:item.postMessage.time * 4 + 50 + 'px'}"
+							<view class="msg-text voice" :style="{width:item.postMessage.time * 4 + 60 + 'px'}"
 								@tap="playVoice(item.postMessage)">
 
 								<image src="../../static/images/chatroom/sound.png" mode="" class="voice-img" />
@@ -66,7 +66,7 @@
 						</view>
 						<!-- voice -->
 						<view class="message" v-if="item.messageType == 2">
-							<view class="msg-text voice" :style="{width:item.postMessage.time * 4 + 50 + 'px'}"
+							<view class="msg-text voice" :style="{width:item.postMessage.time * 4 + 60 + 'px'}"
 								@tap="playVoice(item.postMessage)">
 								{{ item.postMessage.time }}"
 								<image src="@/static/images/chatroom/sound.png" mode="" class="voice-img" />
@@ -140,12 +140,10 @@
 
 			if (this.isJSON(option.data) == true) {
 				data = JSON.parse(option.data)
+
 			}
 
-
-			console.log(data, 55555555555555555555555)
 			this.name = ['wo', option.chatID];
-			// console.log(data)
 			if (typeof data.recipientName == "undefined") {
 				this.callName = data.realName;
 			} else {
@@ -158,7 +156,6 @@
 			let that = this;
 			uni.getSystemInfo({
 				success(e) {
-					// console.log(e);
 					let {
 						windowWidth,
 						windowHeight,
@@ -175,6 +172,12 @@
 						.exec();
 				}
 			});
+		},
+
+		onUnload() {
+			var innerAudioContext = this.innerAudioContext = uni.createInnerAudioContext()
+
+			innerAudioContext.destroy()
 		},
 
 		methods: {
@@ -247,6 +250,7 @@
 								that.recAvatar = resdata[i].avatar;
 								that.recName = resdata[i].realName;
 							}
+
 						}
 						let msg = res.data.data.chatRecordsIPage
 						that.getData = msg;
@@ -282,6 +286,7 @@
 							}
 
 							that.msgs.unshift(msg[i])
+
 						}
 
 						that.$nextTick(() => {
@@ -346,7 +351,6 @@
 			},
 			// 音频播放
 			playVoice(e) {
-				console.log(e, 'ok')
 
 				var innerAudioContext = this.innerAudioContext = uni.createInnerAudioContext()
 				// innerAudioContext.autoplay = false
@@ -360,9 +364,6 @@
 			},
 			// 接收输入内容
 			inputs(e) {
-
-				console.log(e, 999)
-
 				var that = this;
 				this.isanimation = true
 				let len = this.msgs.length - 1
@@ -390,7 +391,6 @@
 					mesagess = e.message
 				}
 
-
 				uni.request({
 					url: this.$store.state.piAPI + "/chat-records/insertSingleChat",
 					method: "post",
@@ -404,12 +404,14 @@
 					},
 					success: (res) => {
 
-						console.log(res, 89898)
 
 					}
 				});
 
 				this.msgs.push(sendMsg)
+
+				console.log(this.msgs, 789)
+
 				this.$nextTick(() => {
 					this.scrollToView = 'msg' + len
 				})
@@ -421,7 +423,6 @@
 			heights(e) {
 				this.inputh = e
 				this.goBottom()
-				// console.log('高度' + e)
 			},
 			// 滚动到底部
 			goBottom() {
diff --git a/pages/groupChat/chatingQZ.vue b/pages/groupChat/chatingQZ.vue
index 1aef314..08db0fc 100644
--- a/pages/groupChat/chatingQZ.vue
+++ b/pages/groupChat/chatingQZ.vue
@@ -37,10 +37,12 @@
 							</view>
 							<!-- voice -->
 							<view class="message" v-if="item.message_type == 2">
-								<view class="msg-text voice" :style="{width:item.post_message.time * 4 + 'px'}"
-									@tap="playVoice(item.post_message.voice)">
+								<view class="msg-text voice" :style="{width:item.post_message.time * 4 + 60 + 'px'}"
+									@tap="playVoice(item.post_message)">
+								
 									<image src="../../static/images/chatroom/sound.png" mode="" class="voice-img" />
-									{{ item.post_message.time }} "
+									{{ item.post_message.time }}"
+								
 								</view>
 							</view>
 							<!-- location -->
@@ -66,9 +68,9 @@
 						</view>
 						<!-- voice -->
 						<view class="message" v-if="item.message_type == 2">
-							<view class="msg-text voice" :style="{width:item.post_message.time * 4 + 'px'}"
-								@tap="playVoice(item.post_message.voice)">
-								{{ item.post_message.time }} "
+							<view class="msg-text voice" :style="{width:item.post_message.time * 4 + 60 + 'px'}"
+								@tap="playVoice(item.post_message)">
+								{{ item.post_message.time }}"
 								<image src="@/static/images/chatroom/sound.png" mode="" class="voice-img" />
 							</view>
 						</view>
@@ -101,7 +103,6 @@
 	import filter from '@/config/filter.js'
 	import submit from '@/components/submit/submit.vue'
 	import WxStorage from "../../static/lib/wxStorage.js"
-	const innerAudioContext = uni.createInnerAudioContext()
 
 	export default {
 		data() {
@@ -256,6 +257,12 @@
 								msg[i].message = '../../static/images/index/friend-list/' + msg[i].message
 								that.imgMsg.unshift(msg[i].message)
 							}
+							
+							if (that.isJSON(msg[i].post_message) == true) {
+								msg[i].post_message = JSON.parse(msg[i].post_message)
+							}
+							
+							
 							that.msgs.unshift(msg[i])
 						}
 
@@ -269,11 +276,32 @@
 						this.isload = true
 						// 开启加载
 						this.begainloading = true
+						
+						console.log(that.msgs, 456)
 
 					}
 				})
 
 			},
+			
+			isJSON(str) {
+			
+				if (typeof str == 'string') {
+					try {
+						var obj = JSON.parse(str);
+						if (typeof obj == 'object' && obj) {
+							return true;
+						} else {
+							return false;
+						}
+			
+					} catch (e) {
+						return false;
+					}
+				}
+			
+			},
+			
 			// 预览图片
 			previewImage(e) {
 
@@ -299,12 +327,20 @@
 			},
 			// 音频播放
 			playVoice(e) {
-				console.log('ok')
-				innerAudioContext.src = e
+			
+				var innerAudioContext = this.innerAudioContext = uni.createInnerAudioContext()
+				// innerAudioContext.autoplay = false
+				innerAudioContext.src = e.voice
 				innerAudioContext.play()
+			
+				setTimeout(() => {
+					innerAudioContext.destroy()
+				}, e.time * 1000)
+			
 			},
 			// 接收输入内容
 			inputs(e) {
+				console.log(e, 123)
 				var that = this;
 				this.isanimation = true
 				let len = this.msgs.length - 1
@@ -318,19 +354,27 @@
 				let sendMsg = {
 					sender_id: that.senId,
 					post_message: e.message,
-					message_type: 0,
+					message_type: e.types,
 					status: 0,
 					post_time: nowTime,
 					avatar: that.senAvatar
 				}
-
+				
+				var mesagess = null;
+				
+				if (e.message instanceof Object) {
+					mesagess = JSON.stringify(e.message)
+				} else {
+					mesagess = e.message
+				}
+				
 				uni.request({
 					url: this.$store.state.piAPI + "/chatgroupc/submit",
 					method: "post",
 					data: {
 						senderId: that.senId,
-						postMessage: e.message,
-						messageType: 0,
+						postMessage: mesagess,
+						messageType: e.types,
 						status: 0,
 						postTime: sentTime,
 						gid: that.recipientId

--
Gitblit v1.9.3