fix: 移除 H5 JSSDK,直接使用飞书客户端注入的 tt 对象
- H5 JSSDK 与 tt 对象冲突,导致警告 - tt 对象由飞书客户端自动注入,无需额外 SDK - 使用 tt.requestAuthCode 进行免登
This commit is contained in:
@@ -7,8 +7,6 @@
|
|||||||
<title>企业工具台</title>
|
<title>企业工具台</title>
|
||||||
<!-- 飞书扫码登录 SDK(飞书外扫码登录用) -->
|
<!-- 飞书扫码登录 SDK(飞书外扫码登录用) -->
|
||||||
<script src="https://lf-package-cn.feishucdn.com/obj/feishu-static/lark/passport/qrcode/LarkSSOSDKWebQRCode-1.0.3.js"></script>
|
<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>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="root"></div>
|
<div id="root"></div>
|
||||||
|
|||||||
@@ -9,9 +9,6 @@ import styles from './login.module.css'
|
|||||||
declare global {
|
declare global {
|
||||||
interface Window {
|
interface Window {
|
||||||
tt?: any
|
tt?: any
|
||||||
h5sdk?: {
|
|
||||||
ready: (callback: () => void) => void
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,24 +79,6 @@ export default function Login() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 如果 h5sdk 存在,使用 h5sdk.ready() 等待
|
|
||||||
if (window.h5sdk?.ready) {
|
|
||||||
let readyCalled = false
|
|
||||||
const timeoutId = setTimeout(() => {
|
|
||||||
if (!readyCalled) {
|
|
||||||
console.error('h5sdk.ready() 超时')
|
|
||||||
setLoading(false)
|
|
||||||
}
|
|
||||||
}, 5000)
|
|
||||||
|
|
||||||
window.h5sdk.ready(() => {
|
|
||||||
readyCalled = true
|
|
||||||
clearTimeout(timeoutId)
|
|
||||||
performFeishuLogin(companyParam)
|
|
||||||
})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 轮询等待 tt 对象(最多 5 秒)
|
// 轮询等待 tt 对象(最多 5 秒)
|
||||||
let attempts = 0
|
let attempts = 0
|
||||||
const maxAttempts = 50
|
const maxAttempts = 50
|
||||||
@@ -143,22 +122,25 @@ export default function Login() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!appId) {
|
if (!appId) {
|
||||||
|
console.error('appId 获取失败')
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
Toast.show('飞书应用配置错误')
|
Toast.show('飞书应用配置错误')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 调用飞书免登(使用 tt.requestAccess)
|
console.log('开始免登,appId:', appId)
|
||||||
window.tt.requestAccess({
|
|
||||||
appID: appId,
|
// 调用飞书免登
|
||||||
scopeList: [],
|
window.tt.requestAuthCode({
|
||||||
|
appId: appId,
|
||||||
success: (res: any) => {
|
success: (res: any) => {
|
||||||
|
console.log('免登成功,code:', res.code)
|
||||||
handleFeishuLogin(res.code, companyParam)
|
handleFeishuLogin(res.code, companyParam)
|
||||||
},
|
},
|
||||||
fail: (error: any) => {
|
fail: (error: any) => {
|
||||||
console.error('requestAccess 失败:', error)
|
console.error('免登失败:', error)
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
Toast.show('免登失败:' + (error.errMsg || JSON.stringify(error)))
|
Toast.show('免登失败:' + (error.errMsg || error.errorMessage || JSON.stringify(error)))
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user