mama-box: 我的页加「退出登录」按钮 + 授权卡改 navigateTo 授权页(替代非实时 postMessage)
This commit is contained in:
12
index.html
12
index.html
@@ -765,7 +765,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="page-body no-top">
|
<div class="page-body no-top">
|
||||||
<!-- 授权完善资料:H5 → postMessage → 宿主小程序弹原生授权面板(手机号/昵称/头像) → box_app /profile/auth 落库 -->
|
<!-- 授权完善资料:H5 → navigateTo → 小程序授权页(头像/昵称/手机号) → box_app /auth/profile 落库 -->
|
||||||
<div class="list-card" style="margin-top:12px" id="meAuthBox">
|
<div class="list-card" style="margin-top:12px" id="meAuthBox">
|
||||||
<button class="li ripple" id="meAuthCard">
|
<button class="li ripple" id="meAuthCard">
|
||||||
<span class="li-ico o"><svg viewBox="0 0 24 24" width="19" height="19" aria-hidden="true"><rect x="5" y="10.5" width="14" height="9.5" rx="2.5" fill="none" stroke="currentColor" stroke-width="1.8"/><path d="M8.5 10.5V8a3.5 3.5 0 0 1 7 0v2.5" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"/><path d="M12 15v2" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"/></svg></span>
|
<span class="li-ico o"><svg viewBox="0 0 24 24" width="19" height="19" aria-hidden="true"><rect x="5" y="10.5" width="14" height="9.5" rx="2.5" fill="none" stroke="currentColor" stroke-width="1.8"/><path d="M8.5 10.5V8a3.5 3.5 0 0 1 7 0v2.5" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"/><path d="M12 15v2" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"/></svg></span>
|
||||||
@@ -774,6 +774,16 @@
|
|||||||
<i class="chev">›</i>
|
<i class="chev">›</i>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- 退出登录:清除本机身份 → 跳授权页,便于直接测试授权流程 -->
|
||||||
|
<div class="list-card" id="meLogoutBox" style="margin-top:12px">
|
||||||
|
<button class="li ripple" id="meLogoutCard">
|
||||||
|
<span class="li-ico r"><svg viewBox="0 0 24 24" width="19" height="19" aria-hidden="true"><path d="M14 5h5a1.5 1.5 0 0 1 1.5 1.5v11A1.5 1.5 0 0 1 19 19h-5" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"/><path d="M10 12H3m0 0 3.5-3.5M3 12l3.5 3.5" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/></svg></span>
|
||||||
|
<span class="li-t">退出登录</span>
|
||||||
|
<span class="li-v">清除本机身份后重新授权</span>
|
||||||
|
<i class="chev">›</i>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
<!-- ⚠️ 这两处的 data-modal 从 modalPreg 改成了 modalProfile:
|
<!-- ⚠️ 这两处的 data-modal 从 modalPreg 改成了 modalProfile:
|
||||||
「编辑孕期信息」那张弹窗已整个并进「我的资料」(见文件末尾那段说明)。
|
「编辑孕期信息」那张弹窗已整个并进「我的资料」(见文件末尾那段说明)。
|
||||||
小名 / 性别 / 预产期现在只有一处能改,改完照样 syncPregnancy() 回刷这张卡。 -->
|
小名 / 性别 / 预产期现在只有一处能改,改完照样 syncPregnancy() 回刷这张卡。 -->
|
||||||
|
|||||||
37
js/app.js
37
js/app.js
@@ -4141,13 +4141,40 @@
|
|||||||
b.addEventListener('click', goMall);
|
b.addEventListener('click', goMall);
|
||||||
});
|
});
|
||||||
|
|
||||||
/* 「授权完善资料」:H5 → 宿主小程序弹原生授权面板(手机号/昵称/头像)
|
/* 「授权完善资料」:H5 → navigateTo → 小程序端独立授权页(pages/annex/auth/index)。
|
||||||
宿主授权后写 box_app /profile/auth,并更新 web-view src 带结果回传。 */
|
说明:微信 web-view 的 postMessage 非实时送达(只在分享/后退/onHide 等时机
|
||||||
|
才派发 bindmessage),点按钮时端上收不到 → 改用 wx.miniProgram.navigateTo
|
||||||
|
实时跳转到授权页,避开该限制。 */
|
||||||
|
function goAuth() {
|
||||||
|
haptic();
|
||||||
|
if (window.wx && window.wx.miniProgram) {
|
||||||
|
window.wx.miniProgram.navigateTo({ url: '/pages/annex/auth/index' });
|
||||||
|
} else {
|
||||||
|
toast('请在微信小程序中打开');
|
||||||
|
}
|
||||||
|
}
|
||||||
var meAuth = $('#meAuthCard');
|
var meAuth = $('#meAuthCard');
|
||||||
if (meAuth) meAuth.addEventListener('click', function () {
|
if (meAuth) meAuth.addEventListener('click', goAuth);
|
||||||
|
|
||||||
|
/* 「退出登录」:清除本机身份(openid/unionid/资料展示) → 重新加载页面回到未登录态。
|
||||||
|
入口跳到授权页,便于直接测试授权流程。 */
|
||||||
|
var meLogout = $('#meLogoutCard');
|
||||||
|
if (meLogout) meLogout.addEventListener('click', function () {
|
||||||
|
haptic();
|
||||||
if (!(window.wx && window.wx.miniProgram)) { toast('请在微信小程序中打开'); return; }
|
if (!(window.wx && window.wx.miniProgram)) { toast('请在微信小程序中打开'); return; }
|
||||||
window.wx.miniProgram.postMessage({ data: { action: 'requestProfile' } });
|
try { if (location.hash) location.hash = ''; } catch (e) {}
|
||||||
toast('请在弹出的小程序面板授权');
|
// 清除本地读取到的 openid/unionid,回到未登录态
|
||||||
|
try {
|
||||||
|
var base = location.href.split('#')[0];
|
||||||
|
// 保留 query 里的结构与版本戳,仅去掉身份参数
|
||||||
|
var q = (location.search || '').replace(/([?&])openid=[^&]*(&|$)/g, '$1')
|
||||||
|
.replace(/([?&])unionid=[^&]*(&|$)/g, '$1').replace(/\?&$/, '?').replace(/&$/, '');
|
||||||
|
var url = base + (q && q !== '?' ? q : '') ;
|
||||||
|
// 重新加载当前 H5(去掉身份)→ applyRemoteProfile 因无 openid 跳过,页面回到未登录占位
|
||||||
|
location.replace(url + '?t=' + Date.now());
|
||||||
|
} catch (e) {
|
||||||
|
toast('已清除身份');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
/* 从商城/后台切回小程序首页时,webview 会再次可见 —— 把 H5 重置回「首页」屏。
|
/* 从商城/后台切回小程序首页时,webview 会再次可见 —— 把 H5 重置回「首页」屏。
|
||||||
|
|||||||
@@ -1900,6 +1900,7 @@ a.skip:focus{left:16px;top:16px}
|
|||||||
.li-ico.p{background:#EFE9FA;color:#7B5FD4}
|
.li-ico.p{background:#EFE9FA;color:#7B5FD4}
|
||||||
.li-ico.o{background:#FBEDE3;color:#DE7443}
|
.li-ico.o{background:#FBEDE3;color:#DE7443}
|
||||||
.li-ico.b{background:#E6EFF8;color:#4478BC}
|
.li-ico.b{background:#E6EFF8;color:#4478BC}
|
||||||
|
.li-ico.r{background:#FBE9E7;color:#C33A2E}
|
||||||
.li-t{font-size:16.5px;font-weight:700}
|
.li-t{font-size:16.5px;font-weight:700}
|
||||||
.li-v{margin-left:auto;font-size:13px;color:var(--brand);font-weight:600}
|
.li-v{margin-left:auto;font-size:13px;color:var(--brand);font-weight:600}
|
||||||
.li .chev{margin-left:auto}
|
.li .chev{margin-left:auto}
|
||||||
|
|||||||
Reference in New Issue
Block a user