From 04a859aa95b231c032c71d06518497a973c2f4e8 Mon Sep 17 00:00:00 2001
From: 罗广辉 <guanghui.luo@foxmail.com>
Date: Thu, 15 Jan 2026 17:41:07 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 uniapps/work-app/src/pages/login/index.vue |   53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 53 insertions(+), 0 deletions(-)

diff --git a/uniapps/work-app/src/pages/login/index.vue b/uniapps/work-app/src/pages/login/index.vue
index 618cd64..4dc8802 100644
--- a/uniapps/work-app/src/pages/login/index.vue
+++ b/uniapps/work-app/src/pages/login/index.vue
@@ -45,6 +45,7 @@
 import md5 from "js-md5";
 import { loginByUsername } from "@/api/user/index.js";
 import { useUserStore } from "@/store/index.js";
+import websocketService from "@/utils/websocket.js";
 
 import { HOME_PATH, LOGIN_PATH, removeQueryString } from "@/router";
 
@@ -134,7 +135,59 @@
       userInfo.key,
       userInfo.code
     );
+    console.log('登录成功,用户信息:', res.data.data);
     userStore.setUserInfo(res.data.data);
+
+
+    // 初始化WebSocket连接
+    try {
+      const wsUrl = 'wss://wrj.shuixiongit.com/ws/chat?userId=';
+      // 设置默认用户ID为3
+      const defaultUserId = '3';
+      // 使用默认用户ID初始化WebSocket连接
+      websocketService.init(defaultUserId, wsUrl);
+      console.log('登录成功,WebSocket已初始化,默认用户ID:', defaultUserId);
+      
+      // 设置来电消息回调
+      websocketService.setOnMessageCallback((message) => {
+        if (message.type === 'call') {
+          console.log('收到来电,准备跳转到语音通话页面');
+          // 构建来电参数
+          const callParams = {
+            peerUid: message.from,
+            from: message.from,
+            type: 'incoming'
+          };
+          
+          // 转义参数以便在URL中传递
+          const encodedParams = encodeURIComponent(JSON.stringify(callParams));
+          
+          try {
+            // 优先使用uni-app的导航API(适用于同应用内跳转)
+            if (typeof uni !== 'undefined' && uni.navigateTo) {
+              console.log('使用uni-app导航API跳转到语音通话页面');
+              uni.navigateTo({
+                url: `/subPackages/voiceCallDetail/index?params=${encodedParams}`
+              });
+            } 
+            // 否则使用window.location跳转(适用于Web环境)
+            else if (typeof window !== 'undefined' && window.location) {
+              console.log('使用window.location跳转到语音通话页面');
+              // 注意:实际部署时需要使用正确的URL
+              const voiceCallUrl = `http://localhost:8080/appPages/voiceCallDetail/index.html?params=${encodedParams}`;
+              window.location.href = voiceCallUrl;
+            } else {
+              console.error('无法跳转到语音通话页面:当前环境不支持导航');
+            }
+          } catch (error) {
+            console.error('跳转到语音通话页面失败:', error);
+          }
+        }
+      });
+    } catch (error) {
+      console.error('WebSocket初始化失败:', error);
+    }
+
     uni.reLaunch({
       url: "/pages/work/index",
     });

--
Gitblit v1.9.3