feat: streamline WeCom QR code login success handling with direct callback integration (#4526)
Some checks are pending
sync2gitee / repo-sync (push) Waiting to run
Typos Check / Spell Check with Typos (push) Waiting to run

This commit is contained in:
shaohuzhang1 2025-12-16 20:52:13 +08:00 committed by GitHub
parent 5ddd1db32d
commit 8d360b1c5f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -43,7 +43,7 @@ function createTransparentIFrame(el: string) {
iframeEl.referrerPolicy = 'origin'
iframeEl.setAttribute('frameborder', '0')
iframeEl.setAttribute('allowtransparency', 'true')
iframeEl.setAttribute('allow', 'local-network-access')
container.appendChild(iframeEl)
return iframeEl
}
@ -77,21 +77,18 @@ const init = async () => {
`&panel_size=small` +
`&redirect_type=self`
iframe.addEventListener('load', (e) => {
console.log('load', iframe)
if (iframe?.contentWindow) {
iframe.contentWindow.stop()
const searchParams = new URLSearchParams(iframe.contentWindow.location.search)
const code = searchParams.get('code')
if (code) {
chatUser.wecomCallback(code, accessToken).then((ok) => {
iframe.contentWindow.postMessage('getToken', '*')
}
})
window.addEventListener('message', (event) => {
if (event.data.type === 'token') {
chatUser.setToken(event.data.value)
router.push({
name: 'chat',
params: { accessToken },
query: route.query,
})
cleanup()
})
}
}
})
}