From 7e7534ec13b4de746f539ba079e55a9a5b04e4e2 Mon Sep 17 00:00:00 2001 From: root Date: Sat, 28 Feb 2026 10:38:27 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=B7=BB=E5=8A=A0=E6=9B=B4=E8=AF=A6?= =?UTF-8?q?=E7=BB=86=E7=9A=84=E8=B0=83=E8=AF=95=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/pages/login/index.tsx | 96 +++++++++++++++--------------- 1 file changed, 49 insertions(+), 47 deletions(-) diff --git a/frontend/src/pages/login/index.tsx b/frontend/src/pages/login/index.tsx index daf4b8b..b45f0b0 100644 --- a/frontend/src/pages/login/index.tsx +++ b/frontend/src/pages/login/index.tsx @@ -76,7 +76,40 @@ export default function Login() { // 飞书内免登 const attemptFeishuAutoLogin = async (companyParam?: string) => { - // 先获取 appId + // 如果 h5sdk 存在,等待 ready 后再调用 + if (window.h5sdk?.ready) { + window.h5sdk.ready(() => { + console.log('h5sdk ready, 调用免登') + performFeishuLoginWithAppId(companyParam) + }) + return + } + + // 如果 tt 对象已存在,直接使用 + if (window.tt) { + performFeishuLoginWithAppId(companyParam) + return + } + + // 轮询等待 tt 对象(最多 5 秒) + let attempts = 0 + const maxAttempts = 50 + + const checkInterval = setInterval(() => { + attempts++ + if (window.tt) { + clearInterval(checkInterval) + performFeishuLoginWithAppId(companyParam) + } else if (attempts >= maxAttempts) { + clearInterval(checkInterval) + console.error('等待 tt 对象超时') + setLoading(false) + } + }, 100) + } + + // 获取 appId 并执行免登 + const performFeishuLoginWithAppId = async (companyParam?: string) => { let appId: string | undefined | null const urlParams = new URLSearchParams(window.location.search) appId = urlParams.get('app_id') @@ -99,47 +132,7 @@ export default function Login() { return } - // 如果 h5sdk 存在,先配置再等待 ready - if (window.h5sdk?.config) { - // 配置 h5sdk - window.h5sdk.config({ - appId: appId, - timestamp: Date.now(), - nonceStr: Math.random().toString(36).substring(2), - signature: '', // 网页应用模式下不需要签名 - }) - - // 等待环境就绪 - if (window.h5sdk.ready) { - window.h5sdk.ready(() => { - console.log('h5sdk ready, 调用免登') - performFeishuLogin(companyParam, appId) - }) - return - } - } - - // 如果 tt 对象已存在,直接使用 - if (window.tt) { - performFeishuLogin(companyParam, appId) - return - } - - // 轮询等待 tt 对象(最多 5 秒) - let attempts = 0 - const maxAttempts = 50 - - const checkInterval = setInterval(() => { - attempts++ - if (window.tt) { - clearInterval(checkInterval) - performFeishuLogin(companyParam, appId) - } else if (attempts >= maxAttempts) { - clearInterval(checkInterval) - console.error('等待 tt 对象超时') - setLoading(false) - } - }, 100) + performFeishuLogin(companyParam, appId) } // 执行飞书免登 @@ -157,23 +150,32 @@ export default function Login() { } try { - console.log('开始免登,appId:', appId) + console.log('=== 开始免登 ===') + console.log('appId:', appId) + console.log('appId长度:', appId.length) + console.log('appId前缀:', appId.substring(0, 4)) + console.log('当前URL:', window.location.href) + console.log('调用 tt.requestAuthCode') // 调用飞书免登 window.tt.requestAuthCode({ appId: appId, success: (res: any) => { - console.log('免登成功,code:', res.code) + console.log('✅ 免登成功') + console.log('code:', res.code) handleFeishuLogin(res.code, companyParam) }, fail: (error: any) => { - console.error('免登失败:', error) + console.error('❌ 免登失败') + console.error('完整错误对象:', JSON.stringify(error)) + console.error('errMsg:', error.errMsg) + console.error('errorCode:', error.errorCode) setLoading(false) - Toast.show('免登失败:' + (error.errMsg || error.errorMessage || JSON.stringify(error))) + Toast.show('免登失败:' + (error.errMsg || JSON.stringify(error))) }, }) } catch (e) { - console.error('免登异常:', e) + console.error('❌ 免登异常:', e) setLoading(false) Toast.show('免登失败,请重试') }