mama-box: reset H5 SPA to home on webview re-show (return from mall/后台) — fixes staying on 我的 after 商城→首页

This commit is contained in:
2026-09-07 17:16:15 +08:00
parent fe32c6ef78
commit 0c1f11ac6b

View File

@@ -4131,6 +4131,21 @@
b.addEventListener('click', goMall);
});
/* 从商城/后台切回小程序首页时,webview 会再次可见 —— 把 H5 重置回「首页」屏。
⚠️ 若不处理:切到商城再点「首页」tab,仍是同一个 webview 实例,
SPA 还停留在切走前的屏(如「我的」),与"回到首页"的预期不符。
只在"当前不是首页"时才切,避免打断用户在首页上的浏览/滚动。 */
function resetScreenOnShow() {
var cur = document.querySelector('.screen.is-active');
if (cur && cur.dataset.screen && cur.dataset.screen !== 'home') go('home');
}
document.addEventListener('visibilitychange', function () {
if (document.visibilityState === 'visible') resetScreenOnShow();
});
window.addEventListener('pageshow', function () {
if (document.visibilityState !== 'hidden') resetScreenOnShow();
});
if (document.readyState === 'complete') init();
else window.addEventListener('load', init);
})();