v26110605 退出登录后只看不写:js/login-gate.js(首页/广场/专题页共用),首页按访客显示,记录/评论/点赞/收藏/投稿/兑换/改档案弹登录提示;退出确认文案更新
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
22
js/app.js
22
js/app.js
@@ -3,7 +3,7 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
/* 页面版本号(YYMMDD+序号):显示在「关于兜爸心选」页底部;bump 时同步 head 注释与 ?v= */
|
||||
var VER = '26110604';
|
||||
var VER = '26110605';
|
||||
const $ = (s, c) => (c || document).querySelector(s);
|
||||
const $$ = (s, c) => Array.from((c || document).querySelectorAll(s));
|
||||
|
||||
@@ -325,8 +325,8 @@
|
||||
非法路由 → 页面未找到。宿主每次加载/onShow 会重新注入身份兜底;
|
||||
hash 仅保留作为「授权回传结果」(#phone/nickname/avatar)的通道。 */
|
||||
function withIdentity(url) {
|
||||
const oid = hashParam('openid');
|
||||
const uid = hashParam('unionid');
|
||||
const oid = rawParam('openid');
|
||||
const uid = rawParam('unionid');
|
||||
const q = [];
|
||||
if (oid) q.push('openid=' + encodeURIComponent(oid));
|
||||
if (uid) q.push('unionid=' + encodeURIComponent(uid));
|
||||
@@ -3809,7 +3809,14 @@
|
||||
⚠️ 只在「后台有值」时覆盖:后台该字段为空(未建档)就维持内置默认,不把页面
|
||||
打回白板。同样静默失败,不打断用户。
|
||||
⚠️ 竞态:fetch 异步,回来时 init() 已跑完,这里只需回刷那些读 state 的展示。 */
|
||||
/* 2026-11-07 用户:退出登录后按访客显示(js/login-gate.js 的 mbGate.out)——身份两键对页面「不存在」,
|
||||
页面各处现成的访客分支自动生效(不出孕周、记录、来信……)。
|
||||
跳到别的应用(withIdentity)和授权仍用真身份(rawParam):授权页要认人,其他应用由各自处理退出状态。 */
|
||||
function hashParam(name) {
|
||||
if ((name === 'openid' || name === 'unionid') && window.mbGate && window.mbGate.out) return '';
|
||||
return rawParam(name);
|
||||
}
|
||||
function rawParam(name) {
|
||||
/* 同时读 hash 和 query:浏览器直访(?openid=x)只有 query;
|
||||
小程序 web-view 的授权回传在 hash(微信 webview 丢 query 不丢 hash)。
|
||||
⚠️ 先在原始串上匹配、再对捕获值 decode —— 先 decode 整串会把
|
||||
@@ -3956,8 +3963,10 @@
|
||||
全部切占位/引导;宿主拿到身份后会带 openid 重载本页,届时自动切真实数据。 */
|
||||
if (!openid) {
|
||||
/* ⚠️ 可见提示(2026-09-20):宿主没注入身份时别静默装正常。
|
||||
排查路径见 showIdNotice() 上方那段注释。 */
|
||||
showIdNotice();
|
||||
排查路径见 showIdNotice() 上方那段注释。
|
||||
11-07:退出登录(mbGate.out)也走这里,但身份其实在 → 不出「未获取到微信身份」,「我的」按未登录显示 */
|
||||
if (window.mbGate && window.mbGate.out) { state.authorized = false; hideIdNotice(); }
|
||||
else showIdNotice();
|
||||
state.pregEmpty = true;
|
||||
state.due = null; state.week = null; state.day = null;
|
||||
state.babyName = ''; state.userName = '';
|
||||
@@ -6709,13 +6718,14 @@
|
||||
}
|
||||
function confirmLogout() {
|
||||
closeModal();
|
||||
var openid = hashParam('openid');
|
||||
var openid = rawParam('openid');
|
||||
if (!openid) { toast('未获得身份,无法退出'); return; }
|
||||
fetch('/api/mp/public/auth/logout?openid=' + encodeURIComponent(openid), { method: 'POST' })
|
||||
.then(function (r) { return r.json(); })
|
||||
.then(function (res) {
|
||||
if (res.code === 200) {
|
||||
toast('已退出登录');
|
||||
if (window.mbGate) window.mbGate.set(true); /* 11-07:本机立刻记下,重载后首屏就是访客样子 */
|
||||
setTimeout(bustReload, 600);
|
||||
} else {
|
||||
toast(res.message || '退出失败,请重试');
|
||||
|
||||
Reference in New Issue
Block a user