refactor(privacy): 调整隐私授权触发逻辑,登录页取消主动预检

- 移除登录页和注册页 `useDidShow` 中主动调用 `ensurePrivacyAuthorized()` 预检的逻辑
- 登录页不再主动弹出隐私协议弹窗,由微信在用户点击手机号登录按钮时强制触发授权
- 门店订单管理页面调用 `chooseProofImage` 前新增 `ensurePrivacyAuthorized()` 预检,确保上传凭证时授权
- 修改隐私弹窗文案为更通用描述,避免误导用户以为是相册授权
- 保留全局 `onNeedPrivacyAuthorization` 通过 `PrivacyModal` 处理,适配微信基础库强制机制
- 统一门店商品管理上传使用已内置预检的 `uploadFile()` 接口调用流程
This commit is contained in:
2026-07-16 01:40:16 +08:00
parent 1b72ae37a5
commit ce1e2bd4dd
7 changed files with 45 additions and 29 deletions

View File

@@ -50,13 +50,13 @@
## 微信隐私协议(基础库 3.16.1+ 强制)
- 报错特征:`chooseImage:fail api scope is not declared in the privacy agreement` / `getPhoneNumber:fail ... privacy ...` + `errno:112`
- 代码修复:
1. 调用 `Taro.chooseImage` / `getPhoneNumber` 等敏感 API 前,先 `getPrivacySetting``requirePrivacyAuthorize` 预检(封装在 `src/api/system/file/index.ts``ensurePrivacyAuthorized()` 里,已 export
1. 调用 `Taro.chooseImage` / `chooseMedia` / `getPhoneNumber` 等敏感 API 前,先 `getPrivacySetting``requirePrivacyAuthorize` 预检(封装在 `src/api/system/file/index.ts``ensurePrivacyAuthorized()` 里,已 export。**注意**:不应在登录页 `useDidShow` 中主动预检,避免用户一进入登录页就弹框;应由微信在用户点击 `getPhoneNumber` 时自行触发 `onNeedPrivacyAuthorization`
2. `src/app.tsx``useLaunch` 中注册 `Taro.onNeedPrivacyAuthorization` 回调,并通过 `src/components/PrivacyModal` 展示隐私协议授权弹窗。弹窗内的 Button 必须设置 `open-type="agreePrivacyAuthorization"`,用户点击后触发 `onAgreePrivacyAuthorization``resolve({ event: 'agree', button: 'agree' })``Taro.showModal` 的按钮无法被微信识别为有效的隐私授权
3. 登录/注册页在 `useDidShow` 中主动预检隐私协议,避免点击授权按钮时因未授权隐私协议而失败
3. 门店上传图片页面在调用 `chooseImage` 前主动预检:`src/pages/store/orders/index.tsx``chooseProofImage` 已加 `ensurePrivacyAuthorized()``src/pages/store/goods/index.tsx` 通过 `uploadFile()` 上传,`uploadFile()` 内部已预检。
- 手动配置:**小程序管理后台** → 设置 → 第三方设置 → 用户隐私保护指引 → 添加「开发者收集你的相册/摄像头」和「手机号」声明
- ⚠️ **`requiredPrivateInfos` 字段只接受位置类 API 白名单**chooseAddress/chooseLocation/choosePoi/getFuzzyLocation/getLocation/onLocationChange/startLocationUpdate/startLocationUpdateBackground不要加 `chooseImage`/`chooseMedia`/`getPhoneNumber` 等非位置类,会导致 app.json 解析失败
- 直接调 `Taro.chooseImage` 的页面:`pages/order/evaluate/index.tsx``pages/after-sale/apply/index.tsx``pages/store/orders/index.tsx` —— 这些页面绕过了 `uploadFile`,需要单独加 `ensurePrivacyAuthorized` 预检
- 直接调 `getPhoneNumber` 的页面:`passport/login.tsx``passport/register.tsx` —— 已增加隐私协议预检 + 降级短信登录
- 直接调 `getPhoneNumber` 的页面:`passport/login.tsx``passport/register.tsx` —— 不再主动预检,依赖微信点击按钮时自动触发 `onNeedPrivacyAuthorization`;保留降级短信登录
- 隐私授权弹窗组件:`src/components/PrivacyModal/index.tsx`(全局单例,通过 `src/utils/privacy.ts` 管理显隐与 resolve
## 手机号授权登录降级方案2026-07-15 ~ 07-16 修复)