落地A: 应用间跳转统一query-only(去hash与identityHash开关), 简化契约 (v26090816)
This commit is contained in:
@@ -7,8 +7,8 @@
|
||||
<meta name="mobile-web-app-capable" content="yes">
|
||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||
<title>兜爸心选 · 孕育陪伴</title>
|
||||
<!-- V:26090815 缓存版本标记:改 css/js 时同步 bump 该值,并给下方资源引用加 ?v= 以强制 webview 刷新子资源 -->
|
||||
<link rel="stylesheet" href="mama-box.css?v=26090815">
|
||||
<!-- V:26090816 缓存版本标记:改 css/js 时同步 bump 该值,并给下方资源引用加 ?v= 以强制 webview 刷新子资源 -->
|
||||
<link rel="stylesheet" href="mama-box.css?v=26090816">
|
||||
<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=26090815"></script>
|
||||
<script src="js/app.js?v=26090816"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
20
js/app.js
20
js/app.js
@@ -3,7 +3,7 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
/* 页面版本号(YYMMDD+序号):显示在「关于兜爸心选」页底部;bump 时同步 head 注释与 ?v= */
|
||||
var VER = '26090815';
|
||||
var VER = '26090816';
|
||||
const $ = (s, c) => (c || document).querySelector(s);
|
||||
const $$ = (s, c) => Array.from((c || document).querySelectorAll(s));
|
||||
|
||||
@@ -168,7 +168,6 @@
|
||||
if (oid) q.push('openid=' + encodeURIComponent(oid));
|
||||
if (uid) q.push('unionid=' + encodeURIComponent(uid));
|
||||
if (q.length) u += '?' + q.join('&');
|
||||
if (oid) u += '#openid=' + encodeURIComponent(oid);
|
||||
location.href = u;
|
||||
}
|
||||
|
||||
@@ -182,7 +181,11 @@
|
||||
for (let i = 0; i < (name || '').length; i++) h = (h * 31 + name.charCodeAt(i)) >>> 0;
|
||||
return PALETTE[h % PALETTE.length];
|
||||
}
|
||||
function jumpApp(url, app) {
|
||||
/* 跳转到其它 H5 应用:身份只走 query(openid/unionid,原 URL 有 query 用 & 续接)。
|
||||
⚠️ 不再追加 #openid —— 部分应用自带 hash 路由(如 /baobao-yingji),追加 hash 会被当
|
||||
非法路由 → 页面未找到。宿主每次加载/onShow 会重新注入身份兜底;
|
||||
hash 仅保留作为「授权回传结果」(#phone/nickname/avatar)的通道。 */
|
||||
function jumpApp(url) {
|
||||
haptic();
|
||||
const oid = hashParam('openid');
|
||||
const uid = hashParam('unionid');
|
||||
@@ -190,11 +193,6 @@
|
||||
if (oid) q.push('openid=' + encodeURIComponent(oid));
|
||||
if (uid) q.push('unionid=' + encodeURIComponent(uid));
|
||||
if (q.length) url += (url.indexOf('?') >= 0 ? '&' : '?') + q.join('&');
|
||||
/* ⚠️ 部分应用自身用 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) {
|
||||
@@ -207,12 +205,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) + '" data-id="' + (a.identifier || '') + '">' + img + name + '</button>';
|
||||
return '<button class="app ripple" data-url="' + encodeURIComponent(a.url) + '">' + 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), APP_BY_ID[t.dataset.id]);
|
||||
if (t && t.dataset.url) jumpApp(decodeURIComponent(t.dataset.url));
|
||||
};
|
||||
/* 角标「共 N 个」同步真实数量 */
|
||||
const cnt = $('.apps-head.for-all .sec-more');
|
||||
@@ -503,7 +501,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, app); return; }
|
||||
if (app && app.url) { jumpApp(app.url); return; }
|
||||
toast('「' + map[b.dataset.mini] + '」即将上线');
|
||||
}));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user