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

@@ -41,6 +41,14 @@
- 场景说明:下单提醒
- 新订单检测 Hook`src/hooks/useNewOrderDetector.ts`30秒轮询页面隐藏暂停
## 微信隐私协议(基础库 3.16.1+ 强制)
- 报错特征:`chooseImage:fail api scope is not declared in the privacy agreement` + `errno:112`
- 三处必改:
1. `src/app.config.ts``requiredPrivateInfos` 必含 `chooseImage``chooseMedia`(已经包含 `getLocation``chooseLocation`
2. 调用 `Taro.chooseImage` 前必须先 `getPrivacySetting``requirePrivacyAuthorize` 预检(封装在 `src/api/system/file/index.ts``ensurePrivacyAuthorized()` 里)
3. `src/app.tsx``useLaunch` 中注册 `Taro.onNeedPrivacyAuthorization` 回调(用 `showModal` 自定义弹窗)
- 直接调 `Taro.chooseImage` 的页面:`pages/order/evaluate/index.tsx``pages/after-sale/apply/index.tsx``pages/store/orders/index.tsx` —— 这些页面绕过了 `uploadFile`,需要单独加 `ensurePrivacyAuthorized` 预检
## 分享 / 朋友圈能力2026-07-13 接入)
- 统一封装:`src/hooks/useShare.ts``useShare({title, path?, query?, imageUrl?, enableTimeline?, enableCopyUrl?})`,一次注册 `useShareAppMessage` + `useShareTimeline` + 可选 `onCopyUrl` 复制链接;自动在 path/query 追加 `inviter=${当前用户id}` 做裂变归因;`isTimelineSinglePage()` 判断朋友圈单页模式 scene===1154
- 海报组件:`src/components/SharePoster/index.tsx`Canvas 2D 绘制封面+标题+价格+小程序码,返回临时图路径作 imageUrl