From 6eb621cd959f1a18d850526a14b9d13b80432b8d Mon Sep 17 00:00:00 2001 From: root Date: Thu, 26 Feb 2026 11:19:46 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=9C=A8=20HTML=20=E4=B8=AD=E7=9B=B4?= =?UTF-8?q?=E6=8E=A5=E5=BC=95=E5=85=A5=E9=A3=9E=E4=B9=A6=20QR=20SDK?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 根据官方文档,SDK 应该在 HTML 中通过 script 标签引入, 而不是动态加载。 Co-Authored-By: Claude Opus 4.6 --- frontend/index.html | 2 + frontend/src/pages/login/QRCodeLogin.tsx | 57 +++--------------------- 2 files changed, 7 insertions(+), 52 deletions(-) diff --git a/frontend/index.html b/frontend/index.html index 072a57e..2d555fe 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -5,6 +5,8 @@ frontend + +
diff --git a/frontend/src/pages/login/QRCodeLogin.tsx b/frontend/src/pages/login/QRCodeLogin.tsx index f9a1223..2caa33c 100644 --- a/frontend/src/pages/login/QRCodeLogin.tsx +++ b/frontend/src/pages/login/QRCodeLogin.tsx @@ -24,52 +24,6 @@ interface QRCodeLoginProps { onClose: () => void } -// 动态加载飞书 QR SDK -const loadFeishuQRSDK = (): Promise => { - return new Promise((resolve) => { - // 检查是否已经加载 - if (window.QR) { - console.log('✅ Feishu QR SDK already loaded') - resolve(true) - return - } - - console.log('📦 Loading Feishu QR SDK...') - - const script = document.createElement('script') - script.id = 'feishu-qr-sdk' - script.src = 'https://lf-package-cn.feishucdn.com/obj/feishu-static/lark/passport/qrcode/LarkSSOSDKWebQRCode-1.0.3.js' - script.async = true - script.timeout = 5000 // 5秒超时 - - const timeoutId = setTimeout(() => { - console.warn('⚠️ Feishu QR SDK load timeout, using fallback') - resolve(false) - }, 5000) - - script.onload = () => { - clearTimeout(timeoutId) - setTimeout(() => { - if (window.QR) { - console.log('✅ Feishu QR SDK loaded successfully') - resolve(true) - } else { - console.warn('⚠️ QR SDK loaded but window.QR not found, using fallback') - resolve(false) - } - }, 100) - } - - script.onerror = () => { - clearTimeout(timeoutId) - console.warn('⚠️ Failed to load Feishu QR SDK, using fallback') - resolve(false) // 不 reject,而是返回 false 使用降级方案 - } - - document.head.appendChild(script) - }) -} - export default function QRCodeLogin({ visible, onClose }: QRCodeLoginProps) { const navigate = useNavigate() const [status, setStatus] = useState<'loading' | 'pending' | 'scanning' | 'success'>('loading') @@ -105,9 +59,6 @@ export default function QRCodeLogin({ visible, onClose }: QRCodeLoginProps) { setQrcodeUrl('') try { - // 尝试加载飞书 QR SDK - const sdkLoaded = await loadFeishuQRSDK() - // 生成登录会话 const response = await fetch('/api/v1/auth/qrcode-login', { method: 'POST', @@ -123,7 +74,9 @@ export default function QRCodeLogin({ visible, onClose }: QRCodeLoginProps) { const authUrl = result.data.auth_url sessionIdRef.current = result.data.session_id - if (sdkLoaded && window.QR) { + // 检查飞书 QR SDK 是否已加载(在 index.html 中引入) + if (window.QR) { + console.log('✅ Using Feishu QR SDK') // 使用飞书官方 QR SDK if (qrContainerRef.current) { qrContainerRef.current.innerHTML = '' @@ -139,8 +92,8 @@ export default function QRCodeLogin({ visible, onClose }: QRCodeLoginProps) { setStatus('pending') startPolling(result.data.session_id) } else { - // SDK 加载失败,使用普通二维码 - console.log('📱 Using fallback QR code') + // SDK 未加载,使用普通二维码 + console.warn('⚠️ Feishu QR SDK not loaded, using fallback') setQrcodeUrl(authUrl) setUseFallback(true) setStatus('pending')