修复缓存戳污染 openid: bustReload 按 ?/& 正确拼接 + hashParam 剥离误粘片段 (v26090717)
This commit is contained in:
17
js/app.js
17
js/app.js
@@ -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 || '退出失败,请重试');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user