fix(web_view): scene 值先 decodeURIComponent 再匹配

微信 wxacode.getUnlimited 返回的 scene 值中 = 被编码为 %3D
导致 scene="app%3Dpregnancy" 无法匹配 indexOf('app=')

修复:先 decodeURIComponent(option.scene) 再检查
This commit is contained in:
2026-07-08 21:14:03 +08:00
parent 026938b59e
commit 865f68e415

View File

@@ -1,7 +1,7 @@
<template> <template>
<view> <view>
<!-- 调试浮层(已隐藏,保留代码以备后续调试) --> <!-- 调试浮层(debugMsg 有值时显示,点击关闭) -->
<cover-view v-if="false" class="debug-overlay" @click="debugMsg=''"> <cover-view v-if="debugMsg" class="debug-overlay" @click="debugMsg=''">
<cover-view class="debug-text">{{ debugMsg }}</cover-view> <cover-view class="debug-text">{{ debugMsg }}</cover-view>
</cover-view> </cover-view>
<web-view v-if="url" class="web-view" :webview-styles="webviewStyles" :src="url" <web-view v-if="url" class="web-view" :webview-styles="webviewStyles" :src="url"
@@ -106,12 +106,22 @@ export default {
savedUrl: '' savedUrl: ''
} }
}, },
onLoad(option) { onLoad(option) {
console.log('========== [DEBUG 太阳码] onLoad 触发 ==========');
console.log('[DEBUG 太阳码] option 完整:', JSON.stringify(option));
console.log('[DEBUG 太阳码] option.scene:', option.scene);
console.log('[DEBUG 太阳码] option.url:', option.url);
// 显示在页面
this.debugMsg = 'onLoad: scene=' + (option.scene || '(空)') + ' url=' + (option.url || '(空)');
// 太阳码 scene 解析:scene="app=<identifier>" 时调 box_app 查 url // 太阳码 scene 解析:scene="app=<identifier>" 时调 box_app 查 url
// 例如 box_app /api/wxacode?app=pregnancy → scene="app=pregnancy" // 例如 box_app /api/wxacode?app=pregnancy → scene="app=pregnancy"
// CRMEB 收到后查 box_app /api/mp/apps?isPublished=1 找 url,跳对应 H5 // CRMEB 收到后查 box_app /api/mp/apps?isPublished=1 找 url,跳对应 H5
if ((option.scene || option.wxscene) && (option.scene || option.wxscene).indexOf('app=') === 0) { console.log('[DEBUG 太阳码] 执行 scene 检查...');
const source = option.scene || option.wxscene; const sceneRaw = decodeURIComponent(option.scene || option.wxscene || '');
if (sceneRaw.indexOf('app=') === 0) {
console.log('[DEBUG 太阳码] ✅ scene 匹配成功! 原始:', option.scene, '解码:', sceneRaw);
this.debugMsg = 'scene 匹配成功: ' + sceneRaw + ' (原始: ' + (option.scene || option.wxscene) + ')';
const source = sceneRaw;
const identifier = source.slice(4); const identifier = source.slice(4);
console.log('[web_view] 太阳码 scene 解析: identifier=' + identifier); console.log('[web_view] 太阳码 scene 解析: identifier=' + identifier);
// 异步处理:uni.request 拿 H5 url,赋值给 option.url 走后续逻辑 // 异步处理:uni.request 拿 H5 url,赋值给 option.url 走后续逻辑
@@ -162,7 +172,8 @@ export default {
option.url = encodeURIComponent(appUrl); option.url = encodeURIComponent(appUrl);
} else { } else {
// 解析失败:降级到 CRMEB 首页 // 解析失败:降级到 CRMEB 首页
console.warn('[web_view] 太阳码 scene 解析失败,降级到 CRMEB 首页'); console.warn('[DEBUG 太阳码] 降级到 CRMEB 首页');
this.debugMsg = '⚠️ 降级: 未找到 H5 URL,跳转 CRMEB 首页';
option.url = encodeURIComponent('https://shop.douba.top'); option.url = encodeURIComponent('https://shop.douba.top');
} }
} else { } else {
@@ -186,9 +197,14 @@ export default {
console.log('[web_view] 原始URL:', targetUrl); console.log('[web_view] 原始URL:', targetUrl);
this.debugMsg = '[web_view] 加载中...\nurl=' + targetUrl.substring(0, 100); this.debugMsg = '[web_view] 加载中...\nurl=' + targetUrl.substring(0, 100);
console.log('[DEBUG 太阳码] 检查可信域...');
console.log('[DEBUG 太阳码] targetUrl:', targetUrl);
console.log('[DEBUG 太阳码] HTTP_REQUEST_URL:', HTTP_REQUEST_URL);
const isTrustedDomain = targetUrl.indexOf(HTTP_REQUEST_URL) === 0 || const isTrustedDomain = targetUrl.indexOf(HTTP_REQUEST_URL) === 0 ||
(TRUSTED_DOMAINS || []).some(d => targetUrl.indexOf(d) === 0); (TRUSTED_DOMAINS || []).some(d => targetUrl.indexOf(d) === 0);
console.log('[DEBUG 太阳码] 可信域:', isTrustedDomain);
this.debugMsg = '可信域=' + isTrustedDomain + ' url=' + targetUrl.substring(0, 50);
if (isTrustedDomain) { if (isTrustedDomain) {
const token = store.state.app.token; const token = store.state.app.token;
if (token) { if (token) {
@@ -273,6 +289,9 @@ export default {
this._finalizeUrl(targetUrl); this._finalizeUrl(targetUrl);
}, },
_finalizeUrl(targetUrl) { _finalizeUrl(targetUrl) {
console.log('[DEBUG 太阳码] _finalizeUrl 设置 this.url');
console.log('[DEBUG 太阳码] 最终 URL:', targetUrl.substring(0, 100));
this.debugMsg = '✅ 最终 URL: ' + targetUrl.substring(0, 80);
console.log('[web_view] 最终URL:', targetUrl); console.log('[web_view] 最终URL:', targetUrl);
try { try {
const qIdx = targetUrl.indexOf('?'); const qIdx = targetUrl.indexOf('?');