身份注入支持 hash 开关: 应用 identityHash=false 时跳转只带 query 不追加#(修复baobao-yingji hash路由被破坏) (v26090815)

This commit is contained in:
2026-09-08 11:49:08 +08:00
parent 3cfe08cd73
commit bd82944f18
2 changed files with 13 additions and 9 deletions

View File

@@ -7,8 +7,8 @@
<meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-capable" content="yes">
<title>兜爸心选 · 孕育陪伴</title>
<!-- V:26090814 缓存版本标记:改 css/js 时同步 bump 该值,并给下方资源引用加 ?v= 以强制 webview 刷新子资源 -->
<link rel="stylesheet" href="mama-box.css?v=26090814">
<!-- V:26090815 缓存版本标记:改 css/js 时同步 bump 该值,并给下方资源引用加 ?v= 以强制 webview 刷新子资源 -->
<link rel="stylesheet" href="mama-box.css?v=26090815">
<script src="https://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
</head>
<body>
@@ -1774,7 +1774,7 @@
加载失败/离线时 window.wx 为 undefined,goMall() 会降级为 toast 提示,
不影响应用其余功能。 -->
<script src="js/app.js?v=26090814"></script>
<script src="js/app.js?v=26090815"></script>
</body>
</html>

View File

@@ -3,7 +3,7 @@
(function () {
'use strict';
/* 页面版本号(YYMMDD+序号):显示在「关于兜爸心选」页底部;bump 时同步 head 注释与 ?v= */
var VER = '26090814';
var VER = '26090815';
const $ = (s, c) => (c || document).querySelector(s);
const $$ = (s, c) => Array.from((c || document).querySelectorAll(s));
@@ -182,7 +182,7 @@
for (let i = 0; i < (name || '').length; i++) h = (h * 31 + name.charCodeAt(i)) >>> 0;
return PALETTE[h % PALETTE.length];
}
function jumpApp(url) {
function jumpApp(url, app) {
haptic();
const oid = hashParam('openid');
const uid = hashParam('unionid');
@@ -190,7 +190,11 @@
if (oid) q.push('openid=' + encodeURIComponent(oid));
if (uid) q.push('unionid=' + encodeURIComponent(uid));
if (q.length) url += (url.indexOf('?') >= 0 ? '&' : '?') + q.join('&');
if (oid) url += '#openid=' + encodeURIComponent(oid);
/* ⚠️ 部分应用自身用 location.hash 做路由/页面跳转(如 /baobao-yingji):追加 #openid
会被当成非法路由 → 页面未找到。这类应用在 box_app 应用管理里 identityHash=false,
跳转时只走 query 身份、不再追加 hash。默认允许(大部分应用无 hash 路由)。 */
const canHash = !app || app.identityHash !== false;
if (oid && canHash) url += '#openid=' + encodeURIComponent(oid);
location.href = url;
}
function renderAppGrid(apps) {
@@ -203,12 +207,12 @@
⚠️ colorTheme 目前全是 'blue' 颜色名 —— 有图时别拿它当底色,否则清一色蓝。 */
const bg = ico ? 'background:#fff' : 'background:' + (a.colorTheme || appTileColor(name));
const img = ico ? '<img class="a-ico" src="' + ico + '" alt="" loading="lazy">' : '<span class="a-ico a-ico-letter" style="background:' + bg + '">' + name.slice(0, 1) + '</span>';
return '<button class="app ripple" data-url="' + encodeURIComponent(a.url) + '">' + img + name + '</button>';
return '<button class="app ripple" data-url="' + encodeURIComponent(a.url) + '" data-id="' + (a.identifier || '') + '">' + img + name + '</button>';
}).join('');
/* 磁贴点击(事件委托,innerHTML 重建后不用重绑) */
grid.onclick = function (e) {
const t = e.target.closest('.app');
if (t && t.dataset.url) jumpApp(decodeURIComponent(t.dataset.url));
if (t && t.dataset.url) jumpApp(decodeURIComponent(t.dataset.url), APP_BY_ID[t.dataset.id]);
};
/* 角标「共 N 个」同步真实数量 */
const cnt = $('.apps-head.for-all .sec-more');
@@ -499,7 +503,7 @@
$$('[data-mini]').forEach(b => b.addEventListener('click', () => {
const map = { kick: '数胎动', weight: '孕期体重', cal: '孕检日历', curve: '生长曲线', fweight: '胎儿估重' };
const app = APP_BY_ID[MINI_APP_MAP[b.dataset.mini]];
if (app && app.url) { jumpApp(app.url); return; }
if (app && app.url) { jumpApp(app.url, app); return; }
toast('「' + map[b.dataset.mini] + '」即将上线');
}));