v26110902(正式;预览为 v26110901) 小程序里进应用改为打开容器页,「复制链接」直达应用

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
deploy
2026-11-09 13:53:47 +00:00
parent c043262df1
commit 06edf9de62
4 changed files with 50 additions and 5 deletions

View File

@@ -3,7 +3,7 @@
(function () {
'use strict';
/* 页面版本号(YYMMDD+序号):显示在「关于兜爸心选」页底部;bump 时同步 head 注释与 ?v= */
var VER = '26110806';
var VER = '26110902';
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();

View File

@@ -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;