fix: 重新添加 H5 JSSDK 并使用 h5sdk.ready() 等待 tt 对象

- H5 JSSDK 是飞书网页应用免登必需的
- 使用 h5sdk.ready() 确保 tt 对象被注入后再调用 API
This commit is contained in:
root
2026-02-28 10:25:04 +08:00
parent fdb030cba0
commit 6f7ac6c40b
2 changed files with 19 additions and 0 deletions
+2
View File
@@ -7,6 +7,8 @@
<title>企业工具台</title>
<!-- 飞书扫码登录 SDK(飞书外扫码登录用) -->
<script src="https://lf-package-cn.feishucdn.com/obj/feishu-static/lark/passport/qrcode/LarkSSOSDKWebQRCode-1.0.3.js"></script>
<!-- 飞书 H5 JSSDK(网页应用免登用) -->
<script src="https://lf1-cdn-tos.bytegoofy.com/goofy/lark/op/h5-js-sdk-1.5.19.js"></script>
</head>
<body>
<div id="root"></div>
+17
View File
@@ -9,6 +9,9 @@ import styles from './login.module.css'
declare global {
interface Window {
tt?: any
h5sdk?: {
ready: (callback: () => void) => void
}
}
}
@@ -73,6 +76,20 @@ export default function Login() {
// 飞书内免登
const attemptFeishuAutoLogin = async (companyParam?: string) => {
// 如果 h5sdk 存在,使用 h5sdk.ready() 等待环境就绪
if (window.h5sdk?.ready) {
window.h5sdk.ready(() => {
console.log('h5sdk ready, tt对象:', !!window.tt)
if (window.tt) {
performFeishuLogin(companyParam)
} else {
console.error('h5sdk ready 后 tt 对象仍不存在')
setLoading(false)
}
})
return
}
// 如果 tt 对象已存在,直接使用
if (window.tt) {
performFeishuLogin(companyParam)