修复缓存戳污染 openid: bustReload 按 ?/& 正确拼接 + hashParam 剥离误粘片段 (v26090717)

This commit is contained in:
2026-09-08 01:04:54 +08:00
parent 7cd9d42583
commit 1e6eef781a
2 changed files with 18 additions and 9 deletions

View File

@@ -6,8 +6,8 @@
<meta name="theme-color" content="#F4593C">
<meta name="apple-mobile-web-app-capable" content="yes">
<title>妈妈盒子 · 孕育陪伴</title>
<!-- V:26090716 缓存版本标记:改 css/js 时同步 bump 该值,并给下方资源引用加 ?v= 以强制 webview 刷新子资源 -->
<link rel="stylesheet" href="mama-box.css?v=26090716">
<!-- V:26090717 缓存版本标记:改 css/js 时同步 bump 该值,并给下方资源引用加 ?v= 以强制 webview 刷新子资源 -->
<link rel="stylesheet" href="mama-box.css?v=26090717">
<script src="https://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
</head>
<body>
@@ -1761,8 +1761,8 @@
加载失败/离线时 window.wx 为 undefined,goMall() 会降级为 toast 提示,
不影响应用其余功能。 -->
<script src="js/app.js?v=26090716"></script>
<!-- 页面版本号(排查 webview 缓存):底部会显示 v26090716 -->
<div id="ver" style="position:fixed;left:0;right:0;bottom:10px;text-align:center;z-index:9999;pointer-events:none;color:#B3A69C;font-size:10px;letter-spacing:.5px">v26090716</div>
<script src="js/app.js?v=26090717"></script>
<!-- 页面版本号(排查 webview 缓存):底部会显示 v26090717 -->
<div id="ver" style="position:fixed;left:0;right:0;bottom:10px;text-align:center;z-index:9999;pointer-events:none;color:#B3A69C;font-size:10px;letter-spacing:.5px">v26090717</div>
</body>
</html>

View File

@@ -1662,6 +1662,13 @@
? '还没填预产期,孕周先锁着 —— 选好上面的预产期就会自动算出来。'
: '已按预产期自动算出,觉得不准可以自己微调。';
}
/* 缓存戳重载:URL 已有 query 时必须用 & 拼接 —— 直接拼 '?t=' 会把
第二个 ? 吃进已有参数值里(?openid=abc001?t=123 → openid 变脏)。 */
function bustReload() {
const b = location.href.split('#')[0];
location.replace(b + (b.indexOf('?') >= 0 ? '&' : '?') + 't=' + Date.now());
}
/* state.due / week / day 在 fetch 返回前是内置默认 —— 不能在脚本加载时
直接把默认值写进表单(新用户会看到「小汤圆/孕27周」假数据)。
改为:打开「我的资料」弹窗时按**当前档案**回填(fillProfileForm)。 */
@@ -2045,7 +2052,7 @@
body: JSON.stringify(body)
}).then(function () {
/* 新用户首次完善资料:重载页面 → pregnancy 出真实孕周、样例信播种 */
if (_wasEmpty) setTimeout(function () { location.replace(location.href.split('#')[0] + '?t=' + Date.now()); }, 700);
if (_wasEmpty) setTimeout(bustReload, 700);
}).catch(function () { /* 保持本地值 */ });
}
var newAvatarFile = (avFile.files && avFile.files[0]) || null;
@@ -4074,11 +4081,13 @@
/* 同时读 hash 和 query:浏览器直访(?openid=x)只有 query;
小程序 web-view 的授权回传在 hash(微信 webview 丢 query 不丢 hash)。
⚠️ 先在原始串上匹配、再对捕获值 decode —— 先 decode 整串会把
%26 之类的编码提前还原成 &,破坏参数切分。 */
%26 之类的编码提前还原成 &,破坏参数切分。
⚠️ split('?'):历史 bug 会把缓存戳粘进 openid(abc001?t=123),
真 openid 不含 ?,剥掉以兼容已被污染的旧链接。 */
try {
const h = (location.hash.slice(1) || '') + '&' + (location.search.slice(1) || '');
const m = h.match(new RegExp('(?:^|[&#])' + name + '=([^&#]*)'));
return m ? decodeURIComponent(m[1]) : '';
return m ? decodeURIComponent(m[1]).split('?')[0] : '';
} catch (e) { return ''; }
}
let _profileApplied = false;
@@ -4324,7 +4333,7 @@
.then(function (res) {
if (res.code === 200) {
toast('已退出登录');
setTimeout(function () { location.replace(location.href.split('#')[0] + '?t=' + Date.now()); }, 600);
setTimeout(bustReload, 600);
} else {
toast(res.message || '退出失败,请重试');
}