Bladeren bron

172.20.10.2改localhost

mazhenhang 3 weken geleden
bovenliggende
commit
5116903484

+ 1 - 1
LiangZhiYUMao/App.vue

@@ -91,7 +91,7 @@ export default {
 			
 			// 获取UserSig
 			const res = await uni.request({
-				url: `http://172.20.10.2:8083/api/im/getUserSig?userId=${userId}`,
+				url: `http://localhost:8083/api/im/getUserSig?userId=${userId}`,
 				method: 'GET'
 			});
 			

+ 1 - 1
LiangZhiYUMao/config/match-config.js

@@ -6,7 +6,7 @@
 const getBaseUrl = () => {
 	// 开发环境:使用本地地址
 	if (process.env.NODE_ENV === 'development') {
-		return 'http://172.20.10.2:8083';
+		return 'http://localhost:8083';
 	}
 	
 	// 生产环境:使用服务器地址

+ 4 - 4
LiangZhiYUMao/utils/api.js

@@ -5,7 +5,7 @@
 // 开发环境和生产环境的 API 基础地址
 // 所有请求通过网关转发
 const BASE_URL = process.env.NODE_ENV === 'development' 
-  ? 'http://172.20.10.2:8083/api'  // 开发环境 - 通过网关
+  ? 'http://localhost:8083/api'  // 开发环境 - 通过网关
   : 'https://your-domain.com/api'  // 生产环境
 
 /**
@@ -148,7 +148,7 @@ export default {
     // 密码登录(手机号+密码)
     loginByPassword: (phone, password) => request({
       // 直连 login 服务(开发环境),避免网关未配置导致未路由
-      url: 'http://172.20.10.2:8087/api/login/password',
+      url: 'http://localhost:8087/api/login/password',
       method: 'POST',
       data: { phone, password }
     }),
@@ -169,14 +169,14 @@ export default {
 
     // 微信登录(直连 login 服务)
     wechatLogin: (data) => request({
-      url: 'http://172.20.10.2:8087/api/login/wechat/login',
+      url: 'http://localhost:8087/api/login/wechat/login',
       method: 'POST',
       data: data  // ✅ 传递完整的登录数据对象(包含code, nickname, avatarUrl, phoneCode)
     }),
 
     // 获取微信手机号(直连 login 服务)
     wechatPhone: (code) => request({
-      url: 'http://172.20.10.2:8087/api/login/wechat/phone',
+      url: 'http://localhost:8087/api/login/wechat/phone',
       method: 'POST',
       data: { code }
     })

+ 2 - 2
LiangZhiYUMao/utils/chat-api.js

@@ -2,7 +2,7 @@
  * 聊天相关API接口封装
  */
 
-const CHAT_BASE_URL = 'http://172.20.10.2:8083/api/chat';
+const CHAT_BASE_URL = 'http://localhost:8083/api/chat';
 
 /**
  * 统一的聊天请求封装
@@ -105,7 +105,7 @@ export function checkOnlineStatus(userId) {
 export function uploadChatMedia(filePath) {
   return new Promise((resolve, reject) => {
     uni.uploadFile({
-      url: 'http://172.20.10.2:8083/api/upload',  // 使用homePage服务的上传接口
+      url: 'http://localhost:8083/api/upload',  // 使用homePage服务的上传接口
       filePath: filePath,
       name: 'file',
       success: (res) => {

+ 29 - 29
LiangZhiYUMao/utils/tim-presence-manager.js

@@ -20,7 +20,7 @@ class TIMPresenceManager {
     this.userId = null;
     this.statusCallbacks = new Map(); // 存储状态变化回调
     this.onlineStatusCache = new Map(); // 缓存在线状态
-    this.wsUrl = 'ws://172.20.10.2:8083/ws/chat';
+    this.wsUrl = 'ws://localhost:8083/ws/chat';
     
     // TIM 状态监听器引用(用于清理)
     this.timStatusListener = null;
@@ -44,13 +44,13 @@ class TIMPresenceManager {
     this.userId = userId;
     
     if (DEBUG_WS) {
-      console.log('🚀 ========== 初始化 tim-presence-manager ==========');
-      console.log('🚀 用户ID:', userId);
-      console.log('🚀 WebSocket URL:', this.wsUrl);
+      console.log('?? ========== 初始化 tim-presence-manager ==========');
+      console.log('?? 用户ID:', userId);
+      console.log('?? WebSocket URL:', this.wsUrl);
     }
     
     // 连接 WebSocket(接收服务端推送的状态变更)
-    if (DEBUG_WS) console.log('🚀 开始连接 WebSocket...');
+    if (DEBUG_WS) console.log('?? 开始连接 WebSocket...');
     this.connectWebSocket();
     
     console.log('✅ tim-presence-manager 初始化完成(WebSocket连接中...)');
@@ -64,7 +64,7 @@ class TIMPresenceManager {
     try {
       const wsUrl = `${this.wsUrl}?userId=${this.userId}`;
       if (DEBUG_WS) {
-        console.log('🔌 准备连接 WebSocket:', wsUrl);
+        console.log('?? 准备连接 WebSocket:', wsUrl);
         console.log('   当前用户ID:', this.userId);
         console.log('   WebSocket URL:', wsUrl);
       }
@@ -93,7 +93,7 @@ class TIMPresenceManager {
       // 使用 SocketTask 对象的监听器(推荐方式)
       this.ws.onOpen((res) => {
         if (DEBUG_WS) {
-          console.log('🎉 ========== WebSocket 连接成功 ==========');
+          console.log('?? ========== WebSocket 连接成功 ==========');
           console.log('   响应数据:', res);
           console.log('   用户ID:', this.userId);
           console.log('   连接URL:', wsUrl);
@@ -120,7 +120,7 @@ class TIMPresenceManager {
       
       // 监听消息
       this.ws.onMessage((res) => {
-        if (DEBUG_WS) console.log('📨 收到WebSocket消息:', res.data);
+        if (DEBUG_WS) console.log('?? 收到WebSocket消息:', res.data);
         this.handleMessage(res.data);
       });
       
@@ -146,7 +146,7 @@ class TIMPresenceManager {
       // 监听关闭
       this.ws.onClose((res) => {
         if (DEBUG_WS) {
-          console.log('🔌 ========== WebSocket 连接关闭 ==========');
+          console.log('?? ========== WebSocket 连接关闭 ==========');
           console.log('   关闭信息:', res);
           console.log('   关闭码:', res?.code);
           console.log('   关闭原因:', res?.reason);
@@ -184,7 +184,7 @@ class TIMPresenceManager {
     
     // 监听 IM 连接状态变化
     this.timConnectListener = (event) => {
-      if (DEBUG_WS) console.log('📡 TIM 连接状态变更:', event.data.state);
+      if (DEBUG_WS) console.log('?? TIM 连接状态变更:', event.data.state);
       
       let imStatus = 'offline';
       
@@ -220,7 +220,7 @@ class TIMPresenceManager {
     
     // 监听用户状态更新事件
     this.timStatusListener = (event) => {
-      console.log('=== 👥 收到 TIM 用户状态更新事件 ===');
+      console.log('=== ?? 收到 TIM 用户状态更新事件 ===');
       console.log('   - 事件数据:', JSON.stringify(event.data, null, 2));
       
       const { userStatusList } = event.data;
@@ -290,7 +290,7 @@ class TIMPresenceManager {
       timestamp: Date.now()
     });
     
-    console.log(`📤 已上报 IM 状态: ${status}`);
+    console.log(`?? 已上报 IM 状态: ${status}`);
   }
   
   /**
@@ -322,12 +322,12 @@ class TIMPresenceManager {
       console.warn('   - timManager.isLogin:', timManager.isLogin);
       
       // 使用 HTTP 轮询作为备用方案
-      console.log('💡 启用 HTTP 轮询备用方案');
+      console.log('?? 启用 HTTP 轮询备用方案');
       this.startHttpPolling(userIdList);
       return;
     }
     
-    console.log('📡 开始订阅用户状态...');
+    console.log('?? 开始订阅用户状态...');
     console.log('   - 订阅用户列表:', userIdList);
     console.log('   - TIM SDK 版本:', timManager.tim.VERSION);
     
@@ -341,7 +341,7 @@ class TIMPresenceManager {
       
       // 订阅成功后,初始化这些用户的状态
       if (result.data && result.data.successUserList) {
-        console.log('📋 成功订阅的用户列表:', result.data.successUserList.length, '个');
+        console.log('?? 成功订阅的用户列表:', result.data.successUserList.length, '个');
         
         result.data.successUserList.forEach(user => {
           console.log(`   - 用户 ${user.userID}:`);
@@ -370,7 +370,7 @@ class TIMPresenceManager {
       
       // 如果订阅失败,启用 HTTP 轮询备用方案
       if (error.code === 70402 || error.code === 70403) {
-        console.log('💡 TIM 在线状态功能未开启,启用 HTTP 轮询备用方案');
+        console.log('?? TIM 在线状态功能未开启,启用 HTTP 轮询备用方案');
         this.startHttpPolling(userIdList);
       }
       
@@ -383,7 +383,7 @@ class TIMPresenceManager {
    * @param {Array<String>} userIdList 用户ID列表
    */
   startHttpPolling(userIdList) {
-    console.log('🔄 启动 HTTP 轮询,间隔 30 秒');
+    console.log('?? 启动 HTTP 轮询,间隔 30 秒');
     
     // 立即查询一次
     this.pollUserStatus(userIdList);
@@ -401,7 +401,7 @@ class TIMPresenceManager {
     for (const userId of userIdList) {
       try {
         const [err, res] = await uni.request({
-          url: 'http://172.20.10.2:8083/api/online/checkStatus',
+          url: 'http://localhost:8083/api/online/checkStatus',
           method: 'GET',
           data: { userId }
         });
@@ -429,7 +429,7 @@ class TIMPresenceManager {
     if (this.pollingTimer) {
       clearInterval(this.pollingTimer);
       this.pollingTimer = null;
-      console.log('🛑 已停止 HTTP 轮询');
+      console.log('?? 已停止 HTTP 轮询');
     }
   }
   
@@ -462,7 +462,7 @@ class TIMPresenceManager {
       switch (message.type) {
         case 'pong':  // 改为小写,匹配后端
           // 心跳响应
-          console.log('💓 收到心跳响应');
+          console.log('?? 收到心跳响应');
           break;
           
         case 'ONLINE':
@@ -499,10 +499,10 @@ class TIMPresenceManager {
     
     this.heartbeatTimer = setInterval(() => {
       if (this.isConnected) {
-        console.log('💓 ========== 发送心跳PING ==========');
-        console.log('💓 用户ID:', this.userId);
-        console.log('💓 WebSocket连接状态:', this.isConnected);
-        console.log('💓 发送消息:', {
+        console.log('?? ========== 发送心跳PING ==========');
+        console.log('?? 用户ID:', this.userId);
+        console.log('?? WebSocket连接状态:', this.isConnected);
+        console.log('?? 发送消息:', {
           type: 'ping',
           fromUserId: this.userId,
           timestamp: Date.now()
@@ -514,7 +514,7 @@ class TIMPresenceManager {
           timestamp: Date.now()
         });
         
-        console.log('💓 ====================================');
+        console.log('?? ====================================');
       } else {
         console.warn('⚠️ WebSocket未连接,跳过心跳');
       }
@@ -589,7 +589,7 @@ class TIMPresenceManager {
    * 通知状态变化
    */
   notifyStatusChange(userId, status) {
-    console.log(`👤 用户 ${userId} 状态变更: ${status}`);
+    console.log(`?? 用户 ${userId} 状态变更: ${status}`);
     
     const callbacks = this.statusCallbacks.get(userId);
     if (callbacks && callbacks.length > 0) {
@@ -620,11 +620,11 @@ class TIMPresenceManager {
       return;
     }
     
-    console.log('🔄 将在5秒后重连...');
+    console.log('?? 将在5秒后重连...');
     this.reconnectTimer = setTimeout(() => {
       this.reconnectTimer = null;
       if (!this.isConnected && this.userId) {
-        console.log('🔄 尝试重连...');
+        console.log('?? 尝试重连...');
         this.connectWebSocket();
       }
     }, this.reconnectInterval);
@@ -638,7 +638,7 @@ class TIMPresenceManager {
       return;
     }
     
-    console.log(`📤 发送队列中的 ${this.messageQueue.length} 条消息`);
+    console.log(`?? 发送队列中的 ${this.messageQueue.length} 条消息`);
     
     while (this.messageQueue.length > 0) {
       const message = this.messageQueue.shift();

+ 5 - 5
LiangZhiYUMao/utils/websocket.js

@@ -33,7 +33,7 @@ class WebSocketManager {
    * @param {Number} userId 用户ID
    * @param {String} baseUrl WebSocket服务地址
    */
-  connect(userId, baseUrl = 'ws://172.20.10.2:8083') {
+  connect(userId, baseUrl = 'ws://localhost:8083') {
     if (this.isConnected) {
       if (DEBUG_WS) console.log('WebSocket已连接');
       return;
@@ -76,9 +76,9 @@ class WebSocketManager {
     // 监听消息接收
     uni.onSocketMessage((res) => {
       try {
-        if (DEBUG_WS) console.log('🔵 收到原始WebSocket消息:', res.data);
+        if (DEBUG_WS) console.log('?? 收到原始WebSocket消息:', res.data);
         const message = JSON.parse(res.data);
-        if (DEBUG_WS) console.log('🔵 解析后的消息对象:', JSON.stringify(message, null, 2));
+        if (DEBUG_WS) console.log('?? 解析后的消息对象:', JSON.stringify(message, null, 2));
         this.handleMessage(message);
       } catch (e) {
         console.error('❌ 解析消息失败', e);
@@ -264,7 +264,7 @@ class WebSocketManager {
    * 发送数据到WebSocket
    */
   send(data) {
-    console.log('🔷 准备发送WebSocket消息');
+    console.log('?? 准备发送WebSocket消息');
     console.log('   消息类型:', data.type);
     console.log('   isConnected:', this.isConnected);
     console.log('   完整数据:', JSON.stringify(data, null, 2));
@@ -280,7 +280,7 @@ class WebSocketManager {
 
     try {
       const jsonStr = JSON.stringify(data);
-      console.log('🔷 JSON字符串长度:', jsonStr.length);
+      console.log('?? JSON字符串长度:', jsonStr.length);
       
       uni.sendSocketMessage({
         data: jsonStr,