feat: bridge 增加 requireAuth() 按需触发小程序授权登录
This commit is contained in:
@@ -92,6 +92,32 @@ const bridge = {
|
|||||||
title,
|
title,
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 触发小程序授权登录(手机号/头像/昵称)
|
||||||
|
* H5 需要用户身份信息时调用,跳转小程序登录页
|
||||||
|
* 登录完成后返回 web-view,小程序会刷新 H5 并带上新身份参数
|
||||||
|
*/
|
||||||
|
requireAuth(opts?: { redirectUrl?: string }) {
|
||||||
|
const mp = getMiniProgram()
|
||||||
|
if (!mp) {
|
||||||
|
console.warn('[bridge.requireAuth] 不在小程序 web-view 环境中')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const loginPage = '/pages/users/wechat_login/index'
|
||||||
|
const redirectUrl = opts?.redirectUrl || window.location.href
|
||||||
|
console.log('[bridge.requireAuth] 跳转小程序登录页:', loginPage)
|
||||||
|
mp.navigateTo({
|
||||||
|
url: loginPage,
|
||||||
|
success: () => {
|
||||||
|
// 记录返回地址,登录成功后回跳
|
||||||
|
try {
|
||||||
|
window.sessionStorage.setItem('bridge_auth_back', redirectUrl)
|
||||||
|
} catch (e) { /* ignore */ }
|
||||||
|
},
|
||||||
|
fail: (err: any) => console.warn('[bridge.requireAuth] 跳转失败:', err),
|
||||||
|
})
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
export default bridge
|
export default bridge
|
||||||
|
|||||||
Reference in New Issue
Block a user