From a600dc05f76e4fea15bc50efcecf916fef31c746 Mon Sep 17 00:00:00 2001 From: Karlcarlo Date: Fri, 31 Jul 2026 11:37:35 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=86=B7=E5=90=AF=E5=8A=A8=E7=AB=9E?= =?UTF-8?q?=E6=80=81=20=E2=80=94=20=E6=97=A0=20token=20=E6=97=B6=E5=BB=B6?= =?UTF-8?q?=E8=BF=9F=E9=87=8D=E8=AF=95=E7=AD=89=E5=BE=85=E9=9D=99=E9=BB=98?= =?UTF-8?q?=E6=8E=88=E6=9D=83=EF=BC=8C=E4=BB=8D=E6=97=A0=E5=88=99=E5=8C=BF?= =?UTF-8?q?=E5=90=8D=E7=9B=B4=E8=BE=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/annex/web_view/index.vue | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/pages/annex/web_view/index.vue b/pages/annex/web_view/index.vue index 4276719..abb722e 100644 --- a/pages/annex/web_view/index.vue +++ b/pages/annex/web_view/index.vue @@ -265,10 +265,30 @@ export default { this._applyIdentity(targetUrl, openid, unionid, urlOpenid); return; // _applyIdentity 内部已调用 _finalizeUrl,避免163重复覆盖 } else { - // 无 token:不拦截,匿名直达 H5(openid 为空) - // 用户需要手机号/头像/昵称时,由 H5 调 bridge.requireAuth() 再授权 - console.log('[auth-flow] 🔓 无 token,匿名直达 H5(不弹授权,按需授权由 H5 requireAuth 触发)'); - this._finalizeUrl(targetUrl); + // 无 token:可能是冷启动竞态(onLaunch 静默授权尚未完成) + // 延迟重试等待 token,最多 3 次;仍无则匿名直达(不弹授权) + let retryCount = 0; + const maxRetry = 3; + const tryLoad = () => { + const t2 = store.state.app.token; + console.log('[auth-flow] ⏳ 无 token,第 ' + (retryCount + 1) + ' 次等待静默授权...'); + if (t2) { + let { openid, unionid } = getCurrentUser(); + console.log('[auth-flow] ✅ 静默授权完成: token=有, openid=' + (openid || '(空)') + ', unionid=' + (unionid || '(空)')); + if (openid) { + this._applyIdentity(targetUrl, openid, unionid, getUrlParam(targetUrl, 'openid')); + return; + } + } + retryCount++; + if (retryCount < maxRetry) { + setTimeout(tryLoad, 800); + } else { + console.warn('[auth-flow] ⚠️ 等待 ' + maxRetry + ' 次仍无 token,匿名直达 H5(按需授权由 H5 requireAuth 触发)'); + this._finalizeUrl(targetUrl); + } + }; + tryLoad(); return; } } else {