bugfix: 取消onetap

This commit is contained in:
zhangyahui
2025-11-05 11:40:17 +08:00
parent 2e4b8f1661
commit 618e82bc95
2 changed files with 11 additions and 6 deletions

3
env.d.ts vendored
View File

@@ -8,8 +8,10 @@ interface GoogleAccounts {
client_id: string
auto_select?: boolean
callback: (response: { credential: string }) => void
context?: 'signin' | 'signup' | 'use'
ux_mode?: 'popup' | 'redirect'
itp_support?: boolean
cancel_on_tap_outside?: boolean
}) => void
renderButton: (element: Element | null, config: {
type?: 'standard' | 'icon'
@@ -18,6 +20,7 @@ interface GoogleAccounts {
size?: 'large' | 'medium' | 'small'
logo_alignment?: 'left' | 'center'
}) => void
disableAutoSelect?: () => void
}
}
}

View File

@@ -56,15 +56,17 @@ const createGmailLogin = async () => {
script.src = data.scriptSrc
})
}
window.google.accounts.id.initialize({
// 主要就是填写client_id
// 初始化Google登录禁用One Tap自动提示
const initConfig: Parameters<typeof window.google.accounts.id.initialize>[0] = {
client_id: GOOGLE_CLIENT_ID,
auto_select: false,
auto_select: false, // 禁用自动选择避免显示One Tap提示
callback: handleCredentialResponse,
// context:"signin",
context: 'signin', // 设置为signin模式避免显示个性化One Tap提示
ux_mode: 'popup',
itp_support: true
})
itp_support: true,
cancel_on_tap_outside: true // 点击外部时取消One Tap提示
}
window.google.accounts.id.initialize(initConfig as any)
console.log('创建谷歌登录按钮:', document.querySelector('.Container #g_id_signin'))
window.google.accounts.id.renderButton(document.querySelector('.Container #g_id_signin'), {
type: 'standard', //icon为只有一个icon