From 6ae85f8ddbae19f5586f4b0c37680fe21889ef14 Mon Sep 17 00:00:00 2001
From: quanwei <419654421@qq.com>
Date: Wed, 26 Nov 2025 18:48:23 +0800
Subject: [PATCH] 修改地图key

---
 mobile/pages/plus/business/chat/chat.vue |   64 ++++++++++++++++++--------------
 1 files changed, 36 insertions(+), 28 deletions(-)

diff --git a/mobile/pages/plus/business/chat/chat.vue b/mobile/pages/plus/business/chat/chat.vue
index 023ca6d..9a10aaa 100644
--- a/mobile/pages/plus/business/chat/chat.vue
+++ b/mobile/pages/plus/business/chat/chat.vue
@@ -20,7 +20,7 @@
 					</view>
 					<view class="user-details" v-else>
 						<text class="user-name">{{ card.name}}</text>
-						<text class="user-status" >
+						<text class="user-status">
 							{{ card.unit[0]+' . '+card.position[0]}}
 						</text>
 					</view>
@@ -192,7 +192,7 @@
 					nickName: '',
 					avatarUrl: ''
 				},
-				card:{},
+				card: {},
 
 				// 聊天数据
 				messages: [],
@@ -231,13 +231,9 @@
 				// 初始化会话
 				this.initConversation();
 			}
-
-
 			// 加载消息
 			this.loadMessages();
 
-			// 初始化WebSocket连接
-			this.initWebSocket();
 		},
 		onUnload() {
 			// 清理定时器
@@ -247,7 +243,6 @@
 			if (this.readTimer) {
 				clearTimeout(this.readTimer);
 			}
-
 			// 关闭WebSocket
 			this.closeWebSocket();
 		},
@@ -262,6 +257,8 @@
 				let self = this;
 				self._get('user.user/detail', {}, res => {
 					self.currentUser = res.data.userInfo;
+					// 初始化WebSocket连接
+					self.initWebSocket();
 				})
 			},
 
@@ -311,6 +308,10 @@
 
 						self.hasMore = self.messages.length < res.data.messages.total;
 						self.loadMore = false;
+						// 滚动到底部
+						self.$nextTick(() => {
+							self.scrollToBottom();
+						});
 						self.page++;
 						if (self.page == 2) {
 							// 获取目标用户信息
@@ -349,26 +350,26 @@
 				if (!this.inputMessage.trim()) return;
 
 				const content = self.inputMessage.trim();
-
-				self._post('plus.business.chat.chat/sendMessage', {
+				self.sendWebSocketMessage(content);
+				/* self._post('plus.business.chat.chat/sendMessage', {
 					conversation_id: self.conversationId,
 					business_card_id: self.businessCardId,
 					content: content
 				}, res => {
 					if (res.code === 1) {
 						// 添加到消息列表
-						self.messages.push(res.data);
+						self.messages.push(res.data.message);
 						self.inputMessage = '';
 						// 滚动到底部
 						self.$nextTick(() => {
 							self.scrollToBottom();
 						});
 						// 发送WebSocket消息
-						self.sendWebSocketMessage(res.data);
+						self.sendWebSocketMessage(res.data.ws_message);
 					} else {
 						self.showError(res.msg || '发送失败');
 					}
-				});
+				}); */
 			},
 
 			// WebSocket相关方法
@@ -378,12 +379,11 @@
 					console.log('WebSocket已连接');
 					return;
 				}
-
-				// 获取当前用户ID
+				// 获取当前用户ID	
 				const currentUserId = this.currentUser.user_id;
 
-				// 构建WebSocket连接URL
-				const wsUrl = `ws://localhost:8282?user_id=${currentUserId}`;
+				// 构建WebSocket连接URL - 使用名片聊天专用端口2349
+				const wsUrl = `ws://localhost:2349?user_id=${currentUserId}`;
 
 				try {
 					// 创建WebSocket连接
@@ -401,7 +401,6 @@
 					this.socketTask.onOpen(() => {
 						console.log('WebSocket已打开');
 						this.isOnline = true;
-
 						// 发送心跳包
 						this.startHeartbeat();
 					});
@@ -409,9 +408,13 @@
 					// 监听WebSocket消息事件
 					this.socketTask.onMessage((res) => {
 						console.log('收到WebSocket消息:', res.data);
-
 						try {
 							const data = JSON.parse(res.data);
+							if (data.Online == 'on') {
+								this.isOnline = false;
+							} else {
+								this.isOnline = true;
+							}
 							this.handleWebSocketMessage(data);
 						} catch (error) {
 							console.error('解析WebSocket消息失败:', error);
@@ -511,25 +514,28 @@
 
 			// 发送WebSocket消息
 			sendWebSocketMessage(message) {
+				let self = this;
 				if (!this.socketTask || !this.isOnline) {
 					console.warn('WebSocket未连接,无法发送消息');
+					self.initWebSocket();
 					return;
 				}
-
 				const wsMessage = {
 					type: 'message',
 					user_id: this.currentUser.user_id,
 					to_user_id: this.targetUserId,
-					content: message.content,
+					content: message,
 					conversation_id: this.conversationId,
 					business_card_id: this.businessCardId,
-					chat_id: message.chat_id
+					app_id: this.currentUser.grade.app_id
 				};
-
 				try {
-					this.socketTask.send({
+					self.socketTask.send({
 						data: JSON.stringify(wsMessage)
 					});
+					self.page = 1
+					self.loadMessages()
+					self.inputMessage = '';
 					console.log('WebSocket消息发送成功:', wsMessage);
 				} catch (error) {
 					console.error('发送WebSocket消息失败:', error);
@@ -551,7 +557,6 @@
 							user_id: this.currentUser.user_id,
 							to_user_id: this.targetUserId
 						};
-
 						try {
 							this.socketTask.send({
 								data: JSON.stringify(heartbeatMsg)
@@ -560,7 +565,7 @@
 							console.error('发送心跳失败:', error);
 						}
 					}
-				}, 30000); // 30秒
+				}, 3000); // 30秒
 			},
 
 			// 标记消息为已读
@@ -576,7 +581,7 @@
 					chat_id: chatId,
 					conversation_id: this.conversationId
 				};
-
+				console.log(readMsg);
 				try {
 					this.socketTask.send({
 						data: JSON.stringify(readMsg)
@@ -591,7 +596,8 @@
 					// 发送关闭消息
 					const closeMsg = {
 						type: 'close',
-						user_id: this.currentUser.user_id
+						user_id: this.currentUser.user_id,
+						to_user_id: this.targetUserId
 					};
 
 					try {
@@ -619,8 +625,10 @@
 
 			// 滚动相关方法
 			scrollToBottom() {
+				let self=this;
 				this.$nextTick(() => {
-					this.scrollTop = this.oldScrollTop + 1;
+					console.log(self.scrollTop);
+					self.scrollTop = self.oldScrollTop + 1;
 				});
 			},
 

--
Gitblit v1.9.2