v26110905 容器页:复制链接直接打开的页返回回小程序首页;首页广场笔记开容器页;首页回前台重载后回到原位置;容器页不记上次子页面

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
deploy
2026-11-09 14:32:16 +00:00
parent a9f57b4807
commit 74dc28c903
132 changed files with 223 additions and 149 deletions

View File

@@ -3,7 +3,7 @@
(function () {
'use strict';
/* 页面版本号(YYMMDD+序号):显示在「关于兜爸心选」页底部;bump 时同步 head 注释与 ?v= */
var VER = '26110904';
var VER = '26110906';
const $ = (s, c) => (c || document).querySelector(s);
const $$ = (s, c) => Array.from((c || document).querySelectorAll(s));
@@ -283,6 +283,45 @@
/* 脚本一加载就判断,不等 init(init 挂在 load 上,要等图片全下完,太晚:用户已经刷新走了、记录还没清;跳转也会先闪首页) */
const SUB_GONE = resumeSub();
/* ================= 回到首页原位置(2026-11-09 用户)=================
「首页滑到孕妈广场点开一篇笔记,点返回没回到孕妈广场那个位置,而是重新加载了小程序」——
小程序首页壳每次回前台(含从容器页 navigateBack 回来)都会给 web-view 换一个带 ?t= 的地址,首页整页重载(壳的代码在小程序里)。
H5 这边能做的:MBHost.open 跳走前(onLeave)记下当前屏、滚动位置和最靠近屏幕顶的带 id 模块;
首页再加载时(30 分钟内、只用一次)按那个模块对齐回去。数据陆续渲染会撑高页面,前 6 秒分几次对齐,用户一摸屏就停。 */
const POS_KEY = 'mmbox.homepos.v1';
function saveHomePos() {
try {
const sc = document.querySelector('.screen.is-active');
if (!sc) return;
const top = sc.getBoundingClientRect().top;
let a = null, bd = 1e9;
sc.querySelectorAll('[id]').forEach(el => {
const r = el.getBoundingClientRect();
if (r.height < 60 || r.bottom <= top) return;
const d = Math.abs(r.top - top);
if (d < bd) { bd = d; a = { id: el.id, off: r.top - top }; }
});
localStorage.setItem(POS_KEY, JSON.stringify({ s: sc.dataset.screen, y: sc.scrollTop, a, p: location.pathname, at: Date.now() }));
} catch (e) {}
}
if (window.MBHost) window.MBHost.onLeave = saveHomePos;
(function restoreHomePos() {
let m = null;
try { m = JSON.parse(localStorage.getItem(POS_KEY) || 'null'); localStorage.removeItem(POS_KEY); } catch (e) { return; }
if (SUB_GONE || !m || m.p !== location.pathname || m.s !== 'home' || Date.now() - m.at > 30 * 60e3 || !(m.y > 0)) return;
const sc = document.getElementById('screen-home');
if (!sc) return;
let stop = false;
['touchstart', 'pointerdown', 'wheel'].forEach(ev => sc.addEventListener(ev, () => { stop = true; }, { once: true, passive: true }));
const apply = () => {
if (stop) return;
const el = m.a && document.getElementById(m.a.id);
if (el && el.getBoundingClientRect().height) sc.scrollTop += el.getBoundingClientRect().top - sc.getBoundingClientRect().top - m.a.off;
else sc.scrollTop = m.y;
};
[0, 150, 400, 800, 1400, 2200, 3200, 4500, 6000].forEach(t => setTimeout(apply, t));
})();
/* 首屏恢复:读一次 last_app,命中就带着当前身份 replace 过去。 */
function resumeLastApp() {
try {