- 将 login.tsx 和 register.tsx 中登录请求从封装的 request 工具改回 Taro.request - 取消登录请求中自动注入 Authorization 头,避免携带过期/旧 token 导致认证失败 - 调整登录接口响应数据解析,适配 Taro.request 的数据结构 - fetchUserInfo 改回使用 Taro.request,手动携带 Authorization 头部 - 添加全局 getPhoneNumber 调用冷却机制,防止频繁调用导致微信报错 - 登录页新增手机授权冷却
54 lines
1.5 KiB
TypeScript
54 lines
1.5 KiB
TypeScript
/**
|
|
* 微信隐私协议授权全局管理器
|
|
* 用于在基础库 3.16.1+ 下处理 onNeedPrivacyAuthorization 回调。
|
|
* 必须在页面中渲染 <PrivacyModal /> 并绑定本管理器。
|
|
*/
|
|
|
|
type PrivacyResolve = (result: { event: 'agree' | 'disagree'; buttonId: string }) => void
|
|
|
|
let currentResolve: PrivacyResolve | null = null
|
|
let showCallback: ((show: boolean) => void) | null = null
|
|
let privacyContractName = '《用户隐私保护指引》'
|
|
|
|
export const privacyManager = {
|
|
/** 设置弹窗显示/隐藏回调 */
|
|
setShowCallback(cb: (show: boolean) => void) {
|
|
showCallback = cb
|
|
},
|
|
|
|
/** 设置隐私协议名称(从 getPrivacySetting 读取) */
|
|
setPrivacyContractName(name: string) {
|
|
privacyContractName = name || '《用户隐私保护指引》'
|
|
},
|
|
|
|
getPrivacyContractName() {
|
|
return privacyContractName
|
|
},
|
|
|
|
/** 展示隐私协议授权弹窗 */
|
|
show(resolve: PrivacyResolve) {
|
|
currentResolve = resolve
|
|
showCallback?.(true)
|
|
},
|
|
|
|
/** 隐私协议授权流程已结束,隐藏弹窗 */
|
|
hide() {
|
|
currentResolve = null
|
|
showCallback?.(false)
|
|
},
|
|
|
|
/** 用户点击同意(由 open-type=agreePrivacyAuthorization 的 button 触发) */
|
|
agree() {
|
|
currentResolve?.({ event: 'agree', buttonId: 'privacy-agree-btn' })
|
|
currentResolve = null
|
|
showCallback?.(false)
|
|
},
|
|
|
|
/** 用户点击拒绝 */
|
|
disagree() {
|
|
currentResolve?.({ event: 'disagree', buttonId: 'privacy-disagree-btn' })
|
|
currentResolve = null
|
|
showCallback?.(false)
|
|
},
|
|
}
|