fix(privacy): 修复微信隐私协议导致的chooseImage错误

- 在 app.config.ts 的requiredPrivateInfos中添加chooseImage和chooseMedia权限声明
- 在上传文件接口uploadFile中调用ensurePrivacyAuthorized函数,预先检查用户隐私授权
- 在 app.tsx 的 useLaunch 钩子中注册 onNeedPrivacyAuthorization 回调,自定义弹窗提示用户协议
- ensurePrivacyAuthorized兼容旧版本微信基础库,未提供隐私授权函数时默认放行
- 更新文档说明隐私协议错误码errno:112的原因及修复方案
- 提醒绕过uploadFile调用chooseImage的页面需单独添加隐私授权预检机制
This commit is contained in:
2026-07-14 23:26:49 +08:00
parent 1fcfcdec73
commit a353bc9ea8
5 changed files with 83 additions and 1 deletions

View File

@@ -22,4 +22,14 @@
4. **登录页面**`passport/login.tsx``passport/register.tsx``pages/store/login/index.tsx` 在保存登录态前检查 status被禁用则弹窗拦截
- 用户状态约定:`status === 0` 正常,`status === 1` 禁用(通过 `updateUserStatus(userId, status)` 接口控制)
## 微信隐私协议chooseImage errno:112修复
- 报错:`MiniProgramError {errMsg:"chooseImage:fail api scope is not declared in the privacy agreement", errno:112}`(基础库 3.16.1+ 强制)
- 影响范围:所有调用 `Taro.chooseImage` 的地方,本轮修复统一入口 `uploadFile`(商品管理页、订单评价、售后申请、门店订单都走这个)
- 修复三处:
1. **`src/app.config.ts`** — `requiredPrivateInfos` 补齐 `chooseImage``chooseMedia`
2. **`src/api/system/file/index.ts`** — `uploadFile``ensurePrivacyAuthorized()` 预检(`getPrivacySetting` + `requirePrivacyAuthorize`
3. **`src/app.tsx`** — `useLaunch` 里注册 `Taro.onNeedPrivacyAuthorization` 回调,弹自定义 showModal 协议弹窗,同意 resolve({event:'agree'}) 拒绝 resolve({event:'disagree'})
- 旧基础库兼容:`typeof wxAny.requirePrivacyAuthorize !== 'function'` 时直接放行
- 后续若别的页面直接调 `Taro.chooseImage`(如 `evaluate/index.tsx``after-sale/apply/index.tsx``store/orders/index.tsx`),仍要单独加 `ensurePrivacyAuthorized` 预检