fix(auth): 授权回传落点改确定性通道 —— backUrl 经 navigateTo query 传递

- 授权页 onLoad 读 options.backUrl(H5 发起授权时带上的当前地址),成功时写进
  __AUTH_RESULT__.backUrl
- consumeAuthResult 优先用 res.backUrl 做回传基址(不再赌 postMessage 派发时机:
  微信只在后退/销毁/分享时批量派发,宫格 location.href 换应用后 shareHref 可能
  还是上一个应用的地址 → 授权后被踢回 mama-box 首页)
- 配套:mama-box wx-auth.js requestProfile / goAuth 已带 backUrl(mama-box d39e52c)

需重新发版生效
This commit is contained in:
2026-09-19 16:56:00 +08:00
parent 67eaae0ceb
commit 3df3e08252
2 changed files with 271 additions and 2 deletions

View File

@@ -88,8 +88,16 @@
openid: ''
}
},
onLoad() {
onLoad(options) {
this.openid = getOpenid();
/* H5 经 navigateTo query 带来的「发起授权的当前地址」(backUrl,已 encode):
成功时写进 __AUTH_RESULT__,宿主 onShow 优先按它回传 —— 从哪个 H5 触发的
授权就回到哪个 H5(宫格 location.href 换应用后,shareHref 可能还是旧应用的)。 */
let backUrl = (options && options.backUrl) || '';
if (backUrl) {
try { backUrl = decodeURIComponent(backUrl); } catch (e) { /* 已是原文 */ }
}
this._backUrl = backUrl;
if (!this.openid) uni.showToast({ title: '未获得 openid,请先登录', icon: 'none' });
},
methods: {
@@ -154,7 +162,8 @@
openid: openid,
phone: res.phone || '',
nickname: res.userName || this.authNickname || '',
avatar: res.avatar || this.authAvatar || ''
avatar: res.avatar || this.authAvatar || '',
backUrl: this._backUrl || ''
});
uni.showToast({ title: '授权成功', icon: 'success' });
setTimeout(() => {