From f18a21ea73db0cd2ce4b74cf427405e7d451dfba Mon Sep 17 00:00:00 2001 From: Karlcarlo Date: Wed, 8 Jul 2026 17:45:58 +0800 Subject: [PATCH] =?UTF-8?q?refactor(web=5Fview):=20=E6=8A=8A=20=5FresolveA?= =?UTF-8?q?ppScene=20=E5=92=8C=20=5FinitWebView=20=E7=A7=BB=E5=88=B0=20met?= =?UTF-8?q?hods=20=E5=9D=97=E5=86=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit HBuilderX 编译错误"Unexpected token (350:0)" 根因:Vue 2 Options API 要求所有方法在 methods: { ... } 块内 之前把这两个方法放在 export default 顶层,违反规范 修复:把 _resolveAppScene 和 _initWebView 移到 methods 块开头 Node.js --check 验证:语法通过 --- pages/annex/web_view/index.vue | 37 +++++++++++++++++----------------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/pages/annex/web_view/index.vue b/pages/annex/web_view/index.vue index 8a6e109..6d40aac 100644 --- a/pages/annex/web_view/index.vue +++ b/pages/annex/web_view/index.vue @@ -120,6 +120,24 @@ export default { this._initWebView(option); }, + onShow() { + // 登录返回后:页面仍在栈中,onLoad 不会再次触发 + // 检查是否有保存的 URL 和 token,重新处理身份 + if (this.savedUrl && store.state.app.token && !this.url) { + console.log('[web_view] onShow: 登录返回,重新处理 URL:', this.savedUrl.substring(0, 80)); + this.debugMsg = '[web_view] 登录返回...\n' + this.savedUrl.substring(0, 100); + const targetUrl = this.savedUrl; + const { openid, unionid } = getCurrentUser(); + const urlOpenid = getUrlParam(targetUrl, 'openid'); + if (openid) { + this._applyIdentity(targetUrl, openid, unionid, urlOpenid); + } else { + console.warn('[web_view] onShow: 仍无 openid,加载原始URL'); + this._finalizeUrl(targetUrl); + } + } + }, + methods: { /** * 太阳码 scene 解析:调 box_app /api/mp/apps 找 url,找到后注入到 option.url * 然后调用 _initWebView(option) 走标准 web_view 加载流程 @@ -229,24 +247,7 @@ export default { } catch (_) {} } }, - onShow() { - // 登录返回后:页面仍在栈中,onLoad 不会再次触发 - // 检查是否有保存的 URL 和 token,重新处理身份 - if (this.savedUrl && store.state.app.token && !this.url) { - console.log('[web_view] onShow: 登录返回,重新处理 URL:', this.savedUrl.substring(0, 80)); - this.debugMsg = '[web_view] 登录返回...\n' + this.savedUrl.substring(0, 100); - const targetUrl = this.savedUrl; - const { openid, unionid } = getCurrentUser(); - const urlOpenid = getUrlParam(targetUrl, 'openid'); - if (openid) { - this._applyIdentity(targetUrl, openid, unionid, urlOpenid); - } else { - console.warn('[web_view] onShow: 仍无 openid,加载原始URL'); - this._finalizeUrl(targetUrl); - } - } - }, - methods: { + _applyIdentity(targetUrl, openid, unionid, urlOpenid) { if (urlOpenid && urlOpenid !== openid) { targetUrl = stripAuthParams(targetUrl);