v26110901 小程序里进应用改为打开容器页,「复制链接」直达应用
首页宫格/记一下/工具卡/档案/底栏跳应用:在小程序里 navigateTo pages/annex/web_view/index?url=<净地址>, 小程序当前页就是该应用,复制链接、转发都直达;url 去掉 openid/unionid/__no_identity/return_url, 不带分享人身份。不在小程序或 navigateTo 失败照旧 location.href。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
<title>兜爸心选 · 孕育陪伴</title>
|
||||
<!-- 11-04 UGC 总开关(孕妈广场 + 测一测,后台 /box_bm/plaza 顶部切换),见 js/ugc.js -->
|
||||
<script src="js/ugc.js?v=26110805"></script>
|
||||
<!-- V:26110805 缓存版本标记:改 css/js 时同步 bump 该值(与 js/app.js 的 VER 同源),静态资源按 mtime 走 ETag 自动刷新 -->
|
||||
<!-- V:26110901 缓存版本标记:改 css/js 时同步 bump 该值(与 js/app.js 的 VER 同源),静态资源按 mtime 走 ETag 自动刷新 -->
|
||||
<link rel="stylesheet" href="mama-box.css">
|
||||
<link rel="stylesheet" href="night.css?v=26110608">
|
||||
<link rel="stylesheet" href="js/wh-cm.css?v=26110642">
|
||||
@@ -2692,7 +2692,7 @@ html.night .rs-pan .rp-card{background:rgba(255,255,255,.06);border-color:rgba(2
|
||||
<script src="js/kit.js?v=26110605"></script>
|
||||
<!-- 11-05 用户:孕期百问加上跟趣味小测试一样的底部 Tab(孕期百问 / 记一下 / 返回首页)。挂在 #detailQA 里,面板关着时跟着滑出屏外;
|
||||
「记一下」直接开首页自己的记一下弹层(z 95 盖在百问 z 80 上),「返回首页」= 关掉百问面板 -->
|
||||
<script src="js/mb-tabbar.js?v=26110487"></script>
|
||||
<script src="js/mb-tabbar.js?v=26110901"></script>
|
||||
<script>
|
||||
(function () {
|
||||
var d = document.getElementById('detailQA'); if (!d || !window.MBTab) return;
|
||||
|
||||
39
js/app.js
39
js/app.js
@@ -3,7 +3,7 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
/* 页面版本号(YYMMDD+序号):显示在「关于兜爸心选」页底部;bump 时同步 head 注释与 ?v= */
|
||||
var VER = '26110805';
|
||||
var VER = '26110901';
|
||||
const $ = (s, c) => (c || document).querySelector(s);
|
||||
const $$ = (s, c) => Array.from((c || document).querySelectorAll(s));
|
||||
|
||||
@@ -161,6 +161,39 @@
|
||||
if (window.wxAuth && window.wxAuth.reportLocation) window.wxAuth.reportLocation({ href: url });
|
||||
}
|
||||
|
||||
/* 小程序里进应用:开一个小程序容器页,不在首页 web-view 里换地址(2026-11-09 用户)。
|
||||
「在任何一个子页面点小程序『复制链接』,打开应该进到那个子页面,现在都进首页」——
|
||||
「复制链接」复制的是**小程序当前页面**的路径和参数;首页壳里 location.href 换应用,小程序页面一直是首页壳,
|
||||
复制出来永远是首页。改为 navigateTo 通用容器 pages/annex/web_view/index?url=<净地址>
|
||||
(分享卡片落地、冷启动恢复用的同一个页,容器按打开者自己的身份注入),小程序当前页就是那个应用。
|
||||
⚠️ url 只放净地址:去掉 openid/unionid/__no_identity,复制出去的链接不能带分享人身份。
|
||||
不在小程序里、navigateTo 失败(页面栈满 10 层等)→ 返回 false / 走 fail,照旧 location.href。 */
|
||||
const HOST_VIEW = '/pages/annex/web_view/index';
|
||||
let hostNavAt = 0;
|
||||
function inMiniProgram() {
|
||||
return window.__wxjs_environment === 'miniprogram' || /miniProgram/i.test(navigator.userAgent);
|
||||
}
|
||||
function hostCleanUrl(url) {
|
||||
const u = new URL(url, location.href);
|
||||
/* return_url 也去掉:它是首页地址、hash 里带身份;没有它时应用的返回按规范走 goHome() */
|
||||
['openid', 'unionid', '__no_identity', 'return_url'].forEach(k => u.searchParams.delete(k));
|
||||
if (/(^|[#&])(openid|unionid|phone|nickname|avatar)=/.test(u.hash)) u.hash = '';
|
||||
return u.href;
|
||||
}
|
||||
function openInHost(target) {
|
||||
const mp = window.wx && window.wx.miniProgram;
|
||||
if (!inMiniProgram() || !mp || typeof mp.navigateTo !== 'function') return false;
|
||||
if (Date.now() - hostNavAt < 1000) return true; // 连点:上一次 navigateTo 还在路上
|
||||
let clean;
|
||||
try { clean = hostCleanUrl(target); } catch (e) { return false; }
|
||||
hostNavAt = Date.now();
|
||||
mp.navigateTo({
|
||||
url: HOST_VIEW + '?url=' + encodeURIComponent(clean),
|
||||
fail: function () { hostNavAt = 0; location.href = target; }
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
/* ================= H5 宿主恢复:冷启动回到上次进入的 H5 应用(2026-09-22) =================
|
||||
需求:在小程序里进入某个 H5 应用后退出小程序,再次进入要恢复那个应用。
|
||||
数据源:box_app GET /api/mp/public/last-app?openid=(Redis,per-openid,7 天 TTL)
|
||||
@@ -353,6 +386,7 @@
|
||||
if (q.length) u += '?' + q.join('&');
|
||||
reportLastApp(ARCHIVE_H5, 'chengzhangdangan');
|
||||
reportHostLocation(u);
|
||||
if (openInHost(u)) return;
|
||||
location.href = u;
|
||||
}
|
||||
|
||||
@@ -677,6 +711,7 @@
|
||||
const target = withIdentity(url);
|
||||
reportLastApp(url, identifier); // 净地址:恢复时身份按当前用户重新注入
|
||||
reportHostLocation(target);
|
||||
if (openInHost(target)) return;
|
||||
location.href = target;
|
||||
}
|
||||
function renderAppGrid(apps) {
|
||||
@@ -6201,7 +6236,7 @@
|
||||
const app = APP_BY_ID[MINI_APP_MAP[k]];
|
||||
if (app && app.url) { jumpApp(app.url, app.identifier); return; }
|
||||
const path = { kick: '/taidong/', weight: '/yunqi-tizhong/', bp: '/yunqi-xueya/', glu: '/yunqi-xuetang/', curve: '/gongsuo-pinlv/', fweight: '/taier-guzhong/' }[k];
|
||||
haptic(); location.href = withIdentity(location.origin + path);
|
||||
haptic(); const t = withIdentity(location.origin + path); if (!openInHost(t)) location.href = t;
|
||||
}));
|
||||
document.addEventListener('visibilitychange', function () {
|
||||
if (document.visibilityState === 'visible' && _vtAt && Date.now() - _vtAt > 3000) loadVitals();
|
||||
|
||||
@@ -105,6 +105,16 @@
|
||||
}
|
||||
if (window.wxAuth && wxAuth.reportLocation) wxAuth.reportLocation({ href: target });
|
||||
} catch (e) {}
|
||||
/* 11-09:小程序里开容器页,「复制链接」才能直达这个应用(同 js/app.js openInHost,url 只放净地址) */
|
||||
var mp = window.wx && window.wx.miniProgram;
|
||||
if ((window.__wxjs_environment === 'miniprogram' || /miniProgram/i.test(navigator.userAgent)) && mp && typeof mp.navigateTo === 'function') {
|
||||
try {
|
||||
var c = new URL(url, location.origin);
|
||||
['openid', 'unionid', '__no_identity', 'return_url'].forEach(function (k) { c.searchParams.delete(k); });
|
||||
mp.navigateTo({ url: '/pages/annex/web_view/index?url=' + encodeURIComponent(c.href), fail: function () { location.href = target; } });
|
||||
return;
|
||||
} catch (e) {}
|
||||
}
|
||||
location.href = target;
|
||||
}
|
||||
var tt;
|
||||
|
||||
@@ -149,7 +149,7 @@ button{font:inherit;border:0;background:none;color:inherit;cursor:pointer}
|
||||
})();
|
||||
</script>
|
||||
<!-- 11-05 用户:底部加上跟趣味小测试一样的 Tab(孕期计算器 / 记一下 / 返回首页) -->
|
||||
<script src="../../js/mb-tabbar.js?v=26110464"></script>
|
||||
<script src="../../js/mb-tabbar.js?v=26110901"></script>
|
||||
<script>MBTab.init({ root: '../../', first: { t: '孕期计算器', ic: 'calc' } });</script>
|
||||
<script src="../../js/share-card.js?v=26110464"></script>
|
||||
<script>window.mbShare('../../assets/share/t/jisuan.jpg', '孕期计算器:生娃花费、预产期、产假天数,一算就知道'); /* 11-04 微信转发图 */</script>
|
||||
|
||||
Reference in New Issue
Block a user