diff --git a/frontend/src/pages/debug-feishu.tsx b/frontend/src/pages/debug-feishu.tsx index 1083a5a..5578c13 100644 --- a/frontend/src/pages/debug-feishu.tsx +++ b/frontend/src/pages/debug-feishu.tsx @@ -24,37 +24,70 @@ interface EnvInfo { export default function DebugFeishuPage() { const navigate = useNavigate() const [envInfo, setEnvInfo] = useState(null) + const [checking, setChecking] = useState(true) useEffect(() => { - // 延迟检测,等待 JSBridge 注入 - setTimeout(() => { + // 多次检测,等待 JSBridge 注入 + const checkEnvironment = (attempt: number) => { + console.log(`🔍 第 ${attempt} 次环境检测`) + const ua = navigator.userAgent const isInFeishu = ua.includes('Lark') || ua.includes('feishu') || ua.includes('lark') const ttMethods = window.tt ? Object.keys(window.tt) : [] + const h5sdk = (window as any).h5sdk + const bridge = (window as any).bridge + const ttjsBridge = window.ttjsBridge - setEnvInfo({ + const info = { ua, isInFeishu, hasTT: !!window.tt, - hasTTJSBridge: !!window.ttjsBridge, - hasH5SDK: !!(window as any).h5sdk, - hasBridge: !!(window as any).bridge, + hasTTJSBridge: !!ttjsBridge, + hasH5SDK: !!h5sdk, + hasBridge: !!bridge, ttMethods, - }) + } - console.log('=== 飞书环境调试 ===') + console.log('=== 飞书环境检测 ===') + console.log('尝试次数:', attempt) console.log('User Agent:', ua) console.log('在飞书中:', isInFeishu) console.log('window.tt:', window.tt) - console.log('window.h5sdk:', (window as any).h5sdk) - console.log('window.bridge:', (window as any).bridge) - console.log('window.ttjsBridge:', window.ttjsBridge) - console.log('tt 对象方法:', ttMethods) + console.log('window.h5sdk:', h5sdk) + console.log('window.bridge:', bridge) + console.log('window.ttjsBridge:', ttjsBridge) - // 检查所有全局对象 - console.log('所有全局对象:', Object.keys(window).filter(k => k.includes('tt') || k.includes('h5') || k.includes('bridge') || k.includes('lark') || k.includes('feishu'))) - }, 500) + // 检查所有可能的全局对象 + const allKeys = Object.keys(window) + const feishuKeys = allKeys.filter(k => + k.toLowerCase().includes('tt') || + k.toLowerCase().includes('h5') || + k.toLowerCase().includes('bridge') || + k.toLowerCase().includes('lark') || + k.toLowerCase().includes('feishu') || + k.toLowerCase().includes('jsbridge') + ) + console.log('飞书相关的全局对象:', feishuKeys) + + setEnvInfo(info) + setChecking(false) + + // 如果检测到任何 API 对象,停止重试 + if (window.tt || h5sdk || bridge || ttjsBridge) { + console.log('✅ 检测到飞书 API 对象') + return + } + + // 继续重试 + if (attempt < 5) { + setTimeout(() => checkEnvironment(attempt + 1), 500) + } else { + console.log('⚠️ 5次检测后仍未发现飞书 API 对象') + } + } + + checkEnvironment(1) }, []) const testFeishuLogin = async () => { @@ -138,32 +171,51 @@ export default function DebugFeishuPage() {

飞书环境调试页面

- {envInfo && ( - - - 在飞书客户端内 - - - window.tt 对象 - - - window.ttjsBridge 对象 - - - User Agent -
- {envInfo.ua} -
-
- - tt 对象方法 ({envInfo.ttMethods.length} 个) -
- {envInfo.ttMethods.length > 0 ? envInfo.ttMethods.join(', ') : '(无)'} -
-
-
+ {checking && ( + + )} + + {envInfo && !checking && ( + <> + + + 在飞书客户端内 + + + window.tt 对象 + + + window.ttjsBridge 对象 + + + window.h5sdk 对象 + + + window.bridge 对象 + + + User Agent +
+ {envInfo.ua} +
+
+ + tt 对象方法 ({envInfo.ttMethods.length} 个) +
+ {envInfo.ttMethods.length > 0 ? envInfo.ttMethods.join(', ') : '(无)'} +
+
+
+ + {!envInfo.hasTT && !envInfo.hasH5SDK && !envInfo.hasBridge && !envInfo.hasTTJSBridge && ( + + )} + )} @@ -174,6 +226,16 @@ export default function DebugFeishuPage() { > 测试飞书免登 + { + console.log('🔄 重新检测环境') + window.location.reload() + }} + clickable + arrow + > + 重新检测 + navigate(-1)} clickable @@ -183,13 +245,12 @@ export default function DebugFeishuPage() { - - - -

1. 在飞书客户端中发送此链接给自己

-

2. 点击链接打开此调试页面

-

3. 查看环境信息

-

4. 点击"测试飞书免登"按钮

+ +

如果飞书免登不可用,请使用以下方式登录:

+

1. 点击飞书消息中的"查看详情"按钮

+

2. 系统会跳转到登录页面

+

3. 使用邮箱/密码登录或扫码登录

+

4. 登录后返回即可进行审批操作

) diff --git a/frontend/src/pages/login/QRCodeLogin.tsx b/frontend/src/pages/login/QRCodeLogin.tsx index a88f07f..436fd69 100644 --- a/frontend/src/pages/login/QRCodeLogin.tsx +++ b/frontend/src/pages/login/QRCodeLogin.tsx @@ -234,9 +234,18 @@ export default function QRCodeLogin({ visible, onClose }: QRCodeLoginProps) { Toast.show('登录成功') setTimeout(() => { - console.log('🚀 Navigating to dashboard...') + console.log('🚀 Navigating...') onClose() - navigate('/dashboard') + + // 检查是否有 redirect 参数 + const urlParams = new URLSearchParams(window.location.search) + const redirect = urlParams.get('redirect') + if (redirect) { + console.log('🔗 登录成功,跳转到:', redirect) + window.location.href = redirect + } else { + navigate('/dashboard') + } }, 500) } else if (result.data.status === 'scanning') { console.log('📱 Status: scanning') diff --git a/frontend/src/pages/login/index.tsx b/frontend/src/pages/login/index.tsx index 333bfee..7d01f49 100644 --- a/frontend/src/pages/login/index.tsx +++ b/frontend/src/pages/login/index.tsx @@ -218,7 +218,16 @@ export default function Login() { if (result.code === 0) { login(result.data.user, result.data.token) Toast.show('登录成功') - navigate('/dashboard') + + // 检查是否有 redirect 参数 + const urlParams = new URLSearchParams(window.location.search) + const redirect = urlParams.get('redirect') + if (redirect) { + console.log('🔗 登录成功,跳转到:', redirect) + window.location.href = redirect + } else { + navigate('/dashboard') + } } else { Toast.show(result.message || '登录失败') setLoading(false)