feat: 添加飞书免登自动登录功能
修改内容: 1. approval/detail.tsx - 在加载详情前检查登录状态,如果在飞书内则自动免登 2. login/index.tsx - 改进飞书环境检测和tt对象注入逻辑 业务流程: 1. 用户在飞书中点击消息按钮 2. 打开审批详情页 → 检测未登录 3. 如果在飞书客户端内 → 自动调用 tt.requestAuthCode 4. 免登成功 → 自动加载详情 5. 免登失败 → 跳转到登录页面 相关文件: - frontend/src/pages/approval/detail.tsx - frontend/src/pages/login/index.tsx Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -49,19 +49,30 @@ export default function Login() {
|
||||
|
||||
console.log('=== 环境检测 ===')
|
||||
console.log('当前 URL:', currentUrl)
|
||||
console.log('User Agent:', ua)
|
||||
console.log('在飞书中:', isInFeishu)
|
||||
console.log('window.tt:', window.tt)
|
||||
|
||||
// 关键修复:在飞书中但 tt 对象不存在时,刷新页面让飞书注入 tt 对象
|
||||
if (isInFeishu && !window.tt && currentUrl.indexOf('reloaded=1') === -1) {
|
||||
console.log('⚠️ 在飞书中但 tt 对象不存在,刷新页面')
|
||||
window.location.href = currentUrl + (currentUrl.indexOf('?') > 0 ? '&' : '?') + 'reloaded=1'
|
||||
return
|
||||
}
|
||||
|
||||
// 检查 URL 中是否有 auth_code 参数(飞书授权回调)
|
||||
// 检查 URL 中是否来自飞书消息通知
|
||||
const urlParams = new URLSearchParams(window.location.search)
|
||||
const authCode = urlParams.get('auth_code')
|
||||
const fromFeishu = urlParams.get('from') === 'feishu'
|
||||
|
||||
// 关键修复:在飞书中但 tt 对象不存在时,刷新页面让飞书注入 tt 对象
|
||||
// 增加多次重试机制
|
||||
if (isInFeishu && !window.tt) {
|
||||
const reloadCount = parseInt(urlParams.get('reload') || '0')
|
||||
if (reloadCount < 3) {
|
||||
console.log(`⚠️ 在飞书中但 tt 对象不存在,第 ${reloadCount + 1} 次刷新页面`)
|
||||
const separator = currentUrl.indexOf('?') > 0 ? '&' : '?'
|
||||
// 清除旧的 reload 参数并添加新的
|
||||
const newUrl = currentUrl.split('?')[0] + '?' + urlParams.toString().replace(/reload=\d+/g, '').replace(/^&+/, '')
|
||||
window.location.href = newUrl + (newUrl.includes('?') ? '&' : '?') + `reload=${reloadCount + 1}`
|
||||
return
|
||||
} else {
|
||||
console.log('❌ 多次刷新后 tt 对象仍不存在,放弃自动登录')
|
||||
}
|
||||
}
|
||||
|
||||
if (authCode) {
|
||||
// 有授权码,直接处理登录
|
||||
@@ -69,10 +80,18 @@ export default function Login() {
|
||||
handleFeishuLogin(authCode)
|
||||
} else if (isInFeishu && window.tt) {
|
||||
// 飞书内且有 tt 对象:静默授权
|
||||
console.log('✅ 飞书内环境,tt 对象可用,开始免登')
|
||||
setEnvironment('feishu')
|
||||
handleFeishuAutoLogin()
|
||||
} else if (isInFeishu) {
|
||||
// 飞书内但 tt 对象不可用:提示用户
|
||||
console.log('⚠️ 在飞书内但 tt 对象不可用')
|
||||
setEnvironment('feishu')
|
||||
setLoading(false)
|
||||
Toast.show('请在飞书客户端中打开,或使用扫码登录')
|
||||
} else {
|
||||
// 飞书外或 tt 对象不可用:显示登录选项
|
||||
// 飞书外:显示登录选项
|
||||
console.log('📱 飞书外环境,显示登录选项')
|
||||
setEnvironment('external')
|
||||
setLoading(false)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user