fix: 添加更详细的调试日志
This commit is contained in:
@@ -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('免登失败,请重试')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user