Browse Source

修复聊天记录

yanjie 4 năm trước cách đây
mục cha
commit
7e8c3f86b7

+ 1 - 1
pages/conversation/conversation.vue

xqd
@@ -210,12 +210,12 @@
 				let data = this.list[e];
 				var index = data.flag.lastIndexOf("\_");
 				var user_id = data.flag.substring(index + 1, data.flag.length);
-
 				let obj = {
 					'user_id': user_id,
 					'user_name': data.nickname,
 					'user_avatar': data.avatar,
 				}
+				console.log(data)
 				var urls = "";
 				if (data.order_status == 3) {
 					urls = "../conversation/conversationWindow?patient=" + JSON.stringify(obj) + "&type=1"

+ 40 - 41
pages/conversation/conversationWindow.vue

xqd xqd xqd xqd xqd xqd
@@ -1,8 +1,8 @@
 <template>
 	<view class="main">
-		<view class="cu-chat" v-for="(item,index) in messages" :key="index">
-			<view class="cu-item self" v-if="item.receiverId!=currentUser.uuid">
-				<view class="time-lag">
+		<view class="cu-chat" style="position: relative;" v-for="(item,index) in messages" :key="index">
+			<view class="cu-item self" v-if="item.senderId==currentUser.uuid">
+				<view class="time-lag" style="position: absolute;top: 6rpx; right: 43%;">
 					{{renderMessageDate(item, index)}}
 				</view>
 				<view class="main" style="width: 500rpx;word-break:break-all;display: flex;justify-content: flex-end;" v-if="item.type=='text'">
@@ -42,7 +42,7 @@
 			</view>
 			<input v-if="!isvoice" v-model="keyword" class="solid-bottom" @focus="InputFocus" @blur="InputBlur" :disabled="isinput"
 			 :adjust-position="false" :focus="false" maxlength="300" :placeholder="textinput" cursor-spacing="10"></input>
-			<button class="flex-sub" style="font-size: 30rpx; height: 64rpx;padding: 0;" @touchstart.stop="onRecordStart"
+			<button class="flex-sub" style="font-size: 30rpx; height: 64rpx;padding: 0;"  @touchstart.stop="onRecordStart"
 			 @touchend.stop="onRecordEnd" v-else>{{audio.recording ? '松开发送':'按住发送语音'}}</button>
 			<view class="action" style="margin-right: 20rpx;" @click="sendImage">
 				<text class="cuIcon-picfill text-grey"></text>
@@ -65,15 +65,15 @@
 			GoEasyAudioPlayer
 		},
 		onLoad: function(op) {
-			this.messages = []
-			this.self_messages = []
+			// this.messages = []
+			// this.self_messages = []
 			console.log('聊天状态',op)
 			if (op.type == 2) {
 				this.sures = false;
 			}
 			this.imService = getApp().globalData.imService;
 			this.doctorInfo = JSON.parse(op.patient)
-			this.getMessage("member_" + this.doctorInfo.user_id)
+			// this.getMessage("member_" + this.doctorInfo.user_id)
 			//对话数据
 			this.friend = {
 				uuid: "member_" + this.doctorInfo.user_id,
@@ -89,8 +89,6 @@
 			uni.setNavigationBarTitle({
 				title: this.friend.name
 			});
-			console.log('打印数据:', this.messages)
-			console.log('打印数据:', this.pendingMessages)
 			this.initialListeners();
 			//每次进入聊天页面,总是滚动到底部
 
@@ -137,21 +135,21 @@
 		},
 		methods: {
 
-			getMessage: async function(flag) {
-				let res = await this.$request.post("doctor/getImList", {
-					'flag': flag
-				});
-				if (res.status == 0) {
-					if (res.data.length != 0) {
-						let newList = [];
-						for (let i = 0; i < res.data.length; i++) {
-							this.messages.push(res.data[i]);
-							// newList.push(res.data[i]);
-						}
-					}
-					this.scrollToBottom()
-				}
-			},
+			// getMessage: async function(flag) {
+			// 	let res = await this.$request.post("doctor/getImList", {
+			// 		'flag': flag
+			// 	});
+			// 	if (res.status == 0) {
+			// 		if (res.data.length != 0) {
+			// 			let newList = [];
+			// 			for (let i = 0; i < res.data.length; i++) {
+			// 				this.messages.push(res.data[i]);
+			// 				// newList.push(res.data[i]);
+			// 			}
+			// 		}
+			// 		this.scrollToBottom()
+			// 	}
+			// },
 			renderMessageDate(message, index) {
 				if (index === 0) {
 					return this.formatDate(message.timestamp)
@@ -258,23 +256,24 @@
 				})
 			},
 			loadMoreHistoryMessage() { //历史消息
-				// let lastMessageTimeStamp = Date.now();
-				// let lastMessage = this.messages[0];
-				// if (lastMessage) {
-				// 	lastMessageTimeStamp = lastMessage.timestamp;
-				// }
-				// var currentLength = this.messages.length;
-				// let promise = this.imService.loadPrivateHistoryMessage(this.friend.uuid, lastMessageTimeStamp);
-				// promise.then(messages => {
-				// 	if (messages.length == currentLength) {
-				// 		this.allHistoryLoaded = true
-				// 	}
-				// 	this.messages = messages;
-				// 	uni.stopPullDownRefresh();
-				// }).catch(e => {
-				// 	console.log(e)
-				// 	uni.stopPullDownRefresh();
-				// })
+				let lastMessageTimeStamp = Date.now();
+				let lastMessage = this.messages[0];
+				if (lastMessage) {
+					lastMessageTimeStamp = lastMessage.timestamp;
+				}
+				var currentLength = this.messages.length;
+				let promise = this.imService.loadPrivateHistoryMessage(this.friend.uuid, lastMessageTimeStamp);
+				promise.then(messages => {
+					if (messages.length == currentLength) {
+						this.allHistoryLoaded = true
+					}
+					this.messages = messages;
+					uni.stopPullDownRefresh();
+				}).catch(e => {
+					console.log(e)
+					uni.stopPullDownRefresh();
+				})
+				console.log(this.messages)
 			},
 		}
 	};