@tarojs/taro 3.8.0-canary.0 → 4.0.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/html.css +9 -0
  2. package/package.json +16 -4
  3. package/types/api/ad/index.d.ts +6 -18
  4. package/types/api/ai/inference.d.ts +4 -8
  5. package/types/api/ai/visionkit.d.ts +625 -54
  6. package/types/api/base/debug.d.ts +8 -8
  7. package/types/api/base/env.d.ts +1 -1
  8. package/types/api/base/index.d.ts +3 -3
  9. package/types/api/base/performance.d.ts +5 -5
  10. package/types/api/base/system.d.ts +6 -6
  11. package/types/api/base/weapp/app-event.d.ts +10 -10
  12. package/types/api/base/weapp/life-cycle.d.ts +1 -1
  13. package/types/api/canvas/index.d.ts +389 -72
  14. package/types/api/data-analysis/index.d.ts +51 -1
  15. package/types/api/device/accelerometer.d.ts +8 -6
  16. package/types/api/device/accessibility.d.ts +1 -1
  17. package/types/api/device/battery.d.ts +3 -3
  18. package/types/api/device/bluetooth-ble.d.ts +40 -17
  19. package/types/api/device/bluetooth-peripheral.d.ts +26 -26
  20. package/types/api/device/bluetooth.d.ts +37 -13
  21. package/types/api/device/calendar.d.ts +11 -1
  22. package/types/api/device/clipboard.d.ts +17 -17
  23. package/types/api/device/compass.d.ts +5 -5
  24. package/types/api/device/gyroscope.d.ts +4 -4
  25. package/types/api/device/iBeacon.d.ts +10 -8
  26. package/types/api/device/keyboard.d.ts +7 -5
  27. package/types/api/device/memory.d.ts +3 -4
  28. package/types/api/device/motion.d.ts +8 -6
  29. package/types/api/device/network.d.ts +12 -6
  30. package/types/api/device/nfc.d.ts +13 -13
  31. package/types/api/device/phone.d.ts +1 -1
  32. package/types/api/device/scan.d.ts +5 -3
  33. package/types/api/device/screen.d.ts +28 -12
  34. package/types/api/device/sms.d.ts +1 -1
  35. package/types/api/device/vibrate.d.ts +5 -5
  36. package/types/api/device/wifi.d.ts +25 -13
  37. package/types/api/files/index.d.ts +73 -43
  38. package/types/api/framework/index.d.ts +2 -2
  39. package/types/api/location/index.d.ts +167 -19
  40. package/types/api/media/audio.d.ts +71 -42
  41. package/types/api/media/background-audio.d.ts +1 -1
  42. package/types/api/media/camera.d.ts +6 -3
  43. package/types/api/media/image.d.ts +5 -5
  44. package/types/api/media/video.d.ts +11 -11
  45. package/types/api/navigate/index.d.ts +3 -1
  46. package/types/api/network/download.d.ts +7 -15
  47. package/types/api/network/request.d.ts +7 -7
  48. package/types/api/network/upload.d.ts +9 -17
  49. package/types/api/network/websocket.d.ts +8 -8
  50. package/types/api/open-api/account.d.ts +1 -1
  51. package/types/api/open-api/address.d.ts +13 -5
  52. package/types/api/open-api/authorize.d.ts +1 -1
  53. package/types/api/open-api/channels.d.ts +16 -0
  54. package/types/api/open-api/device-voip.d.ts +42 -2
  55. package/types/api/open-api/invoice.d.ts +1 -1
  56. package/types/api/open-api/login.d.ts +16 -3
  57. package/types/api/open-api/my-miniprogram.d.ts +2 -2
  58. package/types/api/open-api/privacy.d.ts +107 -0
  59. package/types/api/open-api/settings.d.ts +3 -2
  60. package/types/api/open-api/sticker.d.ts +83 -0
  61. package/types/api/open-api/subscribe-message.d.ts +148 -6
  62. package/types/api/open-api/user-info.d.ts +6 -1
  63. package/types/api/qq/index.d.ts +306 -1
  64. package/types/api/route/index.d.ts +8 -5
  65. package/types/api/skyline/index.d.ts +59 -0
  66. package/types/api/storage/background-fetch.d.ts +63 -11
  67. package/types/api/storage/cache-manager.d.ts +61 -10
  68. package/types/api/storage/index.d.ts +125 -10
  69. package/types/api/swan/bookshelf.d.ts +307 -0
  70. package/types/api/swan/download-package.d.ts +80 -0
  71. package/types/api/swan/index.d.ts +151 -0
  72. package/types/api/swan/pay.d.ts +139 -0
  73. package/types/api/taro.extend.d.ts +15 -6
  74. package/types/api/taro.hooks.d.ts +9 -9
  75. package/types/api/ui/animation.d.ts +32 -32
  76. package/types/api/ui/custom-component.d.ts +1 -1
  77. package/types/api/ui/fonts.d.ts +4 -3
  78. package/types/api/ui/interaction.d.ts +6 -6
  79. package/types/api/ui/menu.d.ts +1 -1
  80. package/types/api/ui/navigation-bar.d.ts +5 -5
  81. package/types/api/ui/pull-down-refresh.d.ts +2 -2
  82. package/types/api/ui/scroll.d.ts +1 -1
  83. package/types/api/ui/tab-bar.d.ts +8 -8
  84. package/types/api/ui/window.d.ts +2 -2
  85. package/types/api/wxml/index.d.ts +19 -19
  86. package/types/compile/compiler.d.ts +9 -4
  87. package/types/compile/config/h5.d.ts +23 -10
  88. package/types/compile/config/harmony.d.ts +82 -0
  89. package/types/compile/config/index.d.ts +1 -0
  90. package/types/compile/config/mini.d.ts +58 -30
  91. package/types/compile/config/plugin.d.ts +34 -0
  92. package/types/compile/config/project.d.ts +26 -13
  93. package/types/compile/config/util.d.ts +22 -8
  94. package/types/compile/viteCompilerContext.d.ts +155 -0
  95. package/types/global.d.ts +3 -1
  96. package/types/index.d.ts +92 -44
  97. package/types/taro.api.d.ts +24 -13
  98. package/types/taro.component.d.ts +2 -1
  99. package/types/taro.config.d.ts +47 -6
  100. package/types/taro.lifecycle.d.ts +3 -0
  101. package/types/taro.runtime.d.ts +9 -0
@@ -21,9 +21,148 @@ declare module '../../index' {
21
21
  type MediaType = 'photo' | 'video'
22
22
  }
23
23
 
24
+ namespace getQQRunData {
25
+ interface Option {
26
+ /** 接口调用结束的回调函数(调用成功、失败都会执行) */
27
+ complete?: (res: TaroGeneral.CallbackResult) => void
28
+ /** 接口调用失败的回调函数 */
29
+ fail?: (res: TaroGeneral.CallbackResult) => void
30
+ /** 接口调用成功的回调函数 */
31
+ success?: (result: SuccessCallbackResult) => void
32
+ }
33
+ interface SuccessCallbackResult extends TaroGeneral.CallbackResult {
34
+ /**
35
+ * 包括敏感数据在内的完整用户信息的加密数据,详细见加密数据解密算法。
36
+ */
37
+ encryptedData: string
38
+ /**
39
+ * 加密算法的初始向量,详细见加密数据解密算法
40
+ */
41
+ iv: string
42
+ }
43
+ }
44
+
45
+ namespace setOfficialDress {
46
+ interface Option {
47
+ /** 方法名,设置头像填"setAvatar",其他方法后续开放 */
48
+ action: string
49
+ /** openid,给自己设置头像填"self" */
50
+ uin: string
51
+ /** 物品id */
52
+ item_id?: string
53
+ /** 设置头像"setAvatar"此处不用填 */
54
+ busi_info?: string
55
+ /** 接口调用结束的回调函数(调用成功、失败都会执行) */
56
+ complete?: (res: TaroGeneral.CallbackResult) => void
57
+ /** 接口调用失败的回调函数 */
58
+ fail?: (res: TaroGeneral.CallbackResult) => void
59
+ /** 接口调用成功的回调函数 */
60
+ success?: (res: TaroGeneral.CallbackResult) => void
61
+ }
62
+ }
63
+
64
+ namespace setCustomDress {
65
+ interface Option {
66
+ /** 方法名,设置头像填"uploadAvatar",其他方法后续开放 */
67
+ action: string
68
+ /** 素材路径,必须为本地文件,路径为 wxfile:// 的形式 */
69
+ path: string
70
+ /** 接口调用结束的回调函数(调用成功、失败都会执行) */
71
+ complete?: (res: TaroGeneral.CallbackResult) => void
72
+ /** 接口调用失败的回调函数 */
73
+ fail?: (res: TaroGeneral.CallbackResult) => void
74
+ /** 接口调用成功的回调函数 */
75
+ success?: (res: TaroGeneral.CallbackResult) => void
76
+ }
77
+ }
78
+
79
+ namespace updateQQApp {
80
+ interface Option {
81
+ /** 接口调用结束的回调函数(调用成功、失败都会执行) */
82
+ complete?: (res: TaroGeneral.CallbackResult) => void
83
+ /** 接口调用失败的回调函数 */
84
+ fail?: (res: TaroGeneral.CallbackResult) => void
85
+ /** 接口调用成功的回调函数 */
86
+ success?: (res: TaroGeneral.CallbackResult) => void
87
+ }
88
+ }
89
+
90
+ namespace addRecentColorSign {
91
+ interface Option {
92
+ /**
93
+ * 做为点击最近彩签打开的小程序页面的启动参数,如 a=1&b=2
94
+ * 默认值:当前页面的查询参数
95
+ */
96
+ query?: string
97
+ /** 接口调用结束的回调函数(调用成功、失败都会执行) */
98
+ complete?: (res: TaroGeneral.CallbackResult) => void
99
+ /** 接口调用失败的回调函数 */
100
+ fail?: (res: TaroGeneral.CallbackResult) => void
101
+ /** 接口调用成功的回调函数 */
102
+ success?: (res: TaroGeneral.CallbackResult) => void
103
+ }
104
+ }
105
+
106
+ namespace getGuildInfo {
107
+ interface Option {
108
+ /** 频道id */
109
+ open_guild_id: string
110
+ /** 子频道Id */
111
+ channel_id?: string
112
+ /** 接口调用结束的回调函数(调用成功、失败都会执行) */
113
+ complete?: (res: TaroGeneral.CallbackResult) => void
114
+ /** 接口调用失败的回调函数 */
115
+ fail?: (res: TaroGeneral.CallbackResult) => void
116
+ /** 接口调用成功的回调函数 */
117
+ success?: (res: SuccessCallbackResult) => void
118
+ }
119
+ interface SuccessCallbackResult extends TaroGeneral.CallbackResult {
120
+ /** 加密之后的数据,需要解密 */
121
+ encryptedData: string
122
+ /** 对称解密算法初始向量(base64) */
123
+ iv: string
124
+ /** 签名(base64) */
125
+ signature: string
126
+ }
127
+ }
128
+
129
+ namespace applyAddToMyApps {
130
+ interface Option {
131
+ /** 接口调用结束的回调函数(调用成功、失败都会执行) */
132
+ complete?: (res: TaroGeneral.CallbackResult) => void
133
+ /** 接口调用失败的回调函数 */
134
+ fail?: (res: TaroGeneral.CallbackResult) => void
135
+ /** 接口调用成功的回调函数 */
136
+ success?: (res: SuccessCallbackResult) => void
137
+ }
138
+ interface SuccessCallbackResult {
139
+ /** true 代表用户选择了同意 */
140
+ confirm: boolean
141
+ /** true 代表用户选择了不同意 */
142
+ cancel: boolean
143
+ }
144
+ }
145
+
146
+ namespace isAddedToMyApps {
147
+ interface Option {
148
+ /** 接口调用结束的回调函数(调用成功、失败都会执行) */
149
+ complete?: (res: TaroGeneral.CallbackResult) => void
150
+ /** 接口调用失败的回调函数 */
151
+ fail?: (res: TaroGeneral.CallbackResult) => void
152
+ /** 接口调用成功的回调函数 */
153
+ success?: (res: SuccessCallbackResult) => void
154
+ }
155
+ interface SuccessCallbackResult extends TaroGeneral.CallbackResult {
156
+ /** true 代表用户已经添加,false 则还没添加 */
157
+ isAdded: boolean
158
+ }
159
+ }
160
+
24
161
  interface TaroStatic {
25
162
  /**
26
163
  * 此接口可打开手Q说说发表界面,并将文字内容和图片/视频内容传递到手Q说说发表界面。
164
+ * @supported qq
165
+ * @example
27
166
  * ```tsx
28
167
  * Taro.openQzonePublish({
29
168
  * footnote: '使用同款滤镜',
@@ -41,9 +180,175 @@ declare module '../../index' {
41
180
  * ]
42
181
  * })
43
182
  * ```
44
- * @supported qq
45
183
  * @see https://q.qq.com/wiki/develop/miniprogram/API/open_port/port_openQzonePublish.html
46
184
  */
47
185
  openQzonePublish(option: openQzonePublish.Option): void
186
+ /**
187
+ * 获取用户过去三十天QQ运动步数。需要先调用 qq.login 接口。步数信息会在用户主动进入小程序时更新。
188
+ * @supported qq
189
+ * @example
190
+ * ```tsx
191
+ * Taro.getQQRunData({
192
+ * success(res) {
193
+ * // 拿 encryptedData 到开发者后台解密开放数据
194
+ * const encryptedData = res.encryptedData
195
+ * }
196
+ * })
197
+ * ```
198
+ *
199
+ * **开放数据 JSON 结构**
200
+ * 敏感数据有两种获取方式,一是使用 加密数据解密算法 。 获取得到的开放数据为以下 json 结构:
201
+ *
202
+ * ```json
203
+ * {
204
+ * "stepInfoList": [
205
+ * {
206
+ * "timestamp": 1445866601,
207
+ * "step": 100
208
+ * },
209
+ * {
210
+ * "timestamp": 1445876601,
211
+ * "step": 120
212
+ * }
213
+ * ]
214
+ * }
215
+ * ```
216
+ * * stepInfoList 中,每一项结构如下:
217
+ *
218
+ * | 属性 | 类型 | 说明 |
219
+ * | --- | ---- | --- |
220
+ * | timestamp | number | 时间戳,表示数据对应的时间 |
221
+ * | step | number | QQ运动步数 |
222
+ *
223
+ * @see https://q.qq.com/wiki/develop/miniprogram/API/open_port/port_sport.html
224
+ */
225
+ getQQRunData(option: getQQRunData.Option): void
226
+ /**
227
+ * QQ美化平台内测阶段,仅被邀请的商户可使用此接口。
228
+ * @supported qq
229
+ * @example
230
+ * ```tsx
231
+ * Taro.setOfficialDress({
232
+ * action: "setAvatar",
233
+ * uin: "self",
234
+ * item_id: "2740",
235
+ * success(res) {
236
+ * console.log("success"+res);
237
+ * },
238
+ * fail(res) {
239
+ * console.log("fail"+res);
240
+ * }
241
+ * })
242
+ * ```
243
+ * @see https://q.qq.com/wiki/develop/miniprogram/API/open_port/personalize.html#qq-setofficialdress
244
+ */
245
+ setOfficialDress(option: setOfficialDress.Option): void
246
+ /**
247
+ * QQ美化平台内测阶段,仅被邀请的商户可使用此接口。
248
+ * @supported qq
249
+ * @example
250
+ * ```tsx
251
+ * Taro.setCustomDress({
252
+ * action: "uploadAvatar",
253
+ * path:"wxfile://images/1.png"
254
+ * success(res) {
255
+ * console.log("success"+res);
256
+ * },
257
+ * fail(res) {
258
+ * console.log("fail"+res);
259
+ * }
260
+ * })
261
+ * ```
262
+ * @see https://q.qq.com/wiki/develop/miniprogram/API/open_port/personalize.html#qq-setcustomdress
263
+ */
264
+ setCustomDress(option: setCustomDress.Option): void
265
+ /**
266
+ * 更新 QQ 版本
267
+ * @supported qq
268
+ * @example
269
+ * ```tsx
270
+ * Taro.updateQQApp({
271
+ * success: function(res) {
272
+ * console.log('updateQQApp success',res)
273
+ * },
274
+ * fail: function(err) {
275
+ * console.log('updateQQApp fail',err)
276
+ * },
277
+ * complete: function(res) {
278
+ * console.log('updateQQApp info',res)
279
+ * }
280
+ * })
281
+ * ```
282
+ * @see https://q.qq.com/wiki/develop/miniprogram/API/open_port/port_updateQQ.html#qq-updateqqapp
283
+ */
284
+ updateQQApp(option: updateQQApp.Option): void
285
+ /**
286
+ * 添加当前小程序页面到最近浏览彩签,需要授权基础库 1.20.0 开始支持。
287
+ * 提示:在手 Q 8.9.0 前的版本,当系统未授予手 Q 悬浮穿权限时,每次调用该接口都会弹出系统授权窗口。自手 Q 8.9.0 起交互调整如下:
288
+ * 1. 系统没有授予手 Q 悬浮窗权限时,接口执行 fail 回调函数并附带 ”No floating window permission“的错误信息,开发者可针对此信息在业务代码里弹窗提示用户手动授予手 Q 悬浮窗权限。
289
+ * 2. 安卓系统部分机型存在获取悬浮窗权限不准确情况。
290
+ * @supported qq
291
+ * @example
292
+ * ```tsx
293
+ * Taro.addRecentColorSign({
294
+ * query: 'a=1&b=2',
295
+ * success(res) {
296
+ * console.log('addRecentColorSign success: ', res)
297
+ * },
298
+ * fail(err) {
299
+ * console.log('addRecentColorSign fail: ', err)
300
+ * },
301
+ * complete(res) {
302
+ * console.log('addRecentColorSign complete: ', res)
303
+ * }
304
+ * })
305
+ * ```
306
+ * @see https://q.qq.com/wiki/develop/miniprogram/API/open_port/port_addColorSign.html#qq-addrecentcolorsign
307
+ */
308
+ addRecentColorSign(option: addRecentColorSign.Option): void
309
+ /**
310
+ * 获取频道信息与当前人身份(FOR 机器人服务入口)
311
+ * @supported qq
312
+ * @see https://q.qq.com/wiki/develop/miniprogram/API/open_port/port_guild.html
313
+ */
314
+ getGuildInfo(option: getGuildInfo.Option): void
315
+ /**
316
+ * 申请用户将本小程序添加到下拉页面中“我的小程序”当中,手Q8.9.13及以上版本支持
317
+ * @supported qq
318
+ * @example
319
+ * ```tsx
320
+ * Taro.applyAddToMyApps({
321
+ * success(res) {
322
+ * if (res.confirm) {
323
+ * // 用户同意添加
324
+ * }
325
+ * if (res.cancel) {
326
+ * // 用户不同意添加
327
+ * }
328
+ * // 原则上,confirm和cancel是互斥的
329
+ * }
330
+ * })
331
+ * ```
332
+ * @see https://q.qq.com/wiki/develop/miniprogram/API/open_port/port_addToMyApps.html#qq-applyaddtomyapps
333
+ */
334
+ applyAddToMyApps(option: applyAddToMyApps.Option): void
335
+ /**
336
+ * 查询用户是否已经将本小程序添加到下拉页面中“我的小程序”当中,手Q8.9.13及以上版本支持,建议使用qq.applyAddToMyApps之前先调用qq.isAddedToMyApps来作前置判断
337
+ * @supported qq
338
+ * @example
339
+ * ```tsx
340
+ * Taro.isAddedToMyApps({
341
+ * success(res) {
342
+ * if (res.isAdded) {
343
+ * // 用户已经添加
344
+ * } else {
345
+ * // 用户还未添加
346
+ * }
347
+ * }
348
+ * })
349
+ * ```
350
+ * @see https://q.qq.com/wiki/develop/miniprogram/API/open_port/port_addToMyApps.html#qq-isaddedtomyapps
351
+ */
352
+ isAddedToMyApps(option: isAddedToMyApps.Option): void
48
353
  }
49
354
  }
@@ -117,7 +117,7 @@ declare module '../../index' {
117
117
 
118
118
  interface TaroStatic {
119
119
  /** 跳转到 tabBar 页面,并关闭其他所有非 tabBar 页面
120
- * @supported weapp, h5, rn, tt
120
+ * @supported weapp, h5, rn, tt, harmony, harmony_hybrid
121
121
  * @example
122
122
  * ```json
123
123
  * {
@@ -143,7 +143,7 @@ declare module '../../index' {
143
143
  switchTab(option: switchTab.Option): Promise<TaroGeneral.CallbackResult>
144
144
 
145
145
  /** 关闭所有页面,打开到应用内的某个页面
146
- * @supported weapp, h5, rn, tt
146
+ * @supported weapp, h5, rn, tt, harmony, harmony_hybrid
147
147
  * @example
148
148
  * ```tsx
149
149
  * Taro.reLaunch({
@@ -155,7 +155,8 @@ declare module '../../index' {
155
155
  reLaunch(option: reLaunch.Option): Promise<TaroGeneral.CallbackResult>
156
156
 
157
157
  /** 关闭当前页面,跳转到应用内的某个页面。但是不允许跳转到 tabbar 页面。
158
- * @supported weapp, h5, rn, tt
158
+ * @supported weapp, h5, rn, tt, harmony, harmony_hybrid
159
+ * @h5 未针对 tabbar 页面做限制处理
159
160
  * @example
160
161
  * ```tsx
161
162
  * Taro.redirectTo({
@@ -167,7 +168,8 @@ declare module '../../index' {
167
168
  redirectTo(option: redirectTo.Option): Promise<TaroGeneral.CallbackResult>
168
169
 
169
170
  /** 保留当前页面,跳转到应用内的某个页面。但是不能跳到 tabbar 页面。使用 Taro.navigateBack 可以返回到原页面。小程序中页面栈最多十层。
170
- * @supported weapp, h5, rn, tt
171
+ * @supported weapp, h5, rn, tt, harmony, harmony_hybrid
172
+ * @h5 未针对 tabbar 页面做限制处理
171
173
  * @example
172
174
  * ```tsx
173
175
  * Taro.navigateTo({
@@ -193,7 +195,8 @@ declare module '../../index' {
193
195
  navigateTo(option: navigateTo.Option): Promise<TaroGeneral.CallbackResult>
194
196
 
195
197
  /** 关闭当前页面,返回上一页面或多级页面。可通过 getCurrentPages 获取当前的页面栈,决定需要返回几层。
196
- * @supported weapp, h5, rn, tt
198
+ * @supported weapp, h5, rn, tt, harmony, harmony_hybrid
199
+ * @h5 若入参 delta 大于现有页面数时,返回应用打开的第一个页面(如果想要返回首页请使用 reLaunch 方法)。
197
200
  * @example
198
201
  * ```tsx
199
202
  * // 注意:调用 navigateTo 跳转时,调用该方法的页面会被加入堆栈,而 redirectTo 方法则不会。见下方示例代码
@@ -0,0 +1,59 @@
1
+ import Taro from '../../index'
2
+
3
+ declare module '../../index' {
4
+ /**
5
+ * Snapshot 实例,可通过 SelectorQuery 获取。
6
+ *
7
+ * Snapshot 通过 id 跟一个 snapshot 组件绑定,操作对应的 snapshot 组件。
8
+ * @supported weapp
9
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/skyline/Snapshot.html
10
+ */
11
+ interface Snapshot {
12
+ /**
13
+ * 画布宽度
14
+ */
15
+ width: number
16
+ /**
17
+ * 画布高度
18
+ */
19
+ height: number
20
+ /**
21
+ * 对 snapshot 组件子树进行截图
22
+ * @param option
23
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/skyline/Snapshot.takeSnapshot.html
24
+ */
25
+ takeSnapshot(option: Snapshot.TakeSnapshot.Option): Promise<TaroGeneral.CallbackResult>
26
+ }
27
+
28
+ namespace Snapshot {
29
+ namespace TakeSnapshot {
30
+ interface Option {
31
+ /**
32
+ * 截图导出类型,'file' 保存到临时文件目录或 'arraybuffer' 返回图片二进制数据,默认值为 'file'
33
+ */
34
+ type: string
35
+ /**
36
+ * 截图文件格式,'rgba' 或 'png',默认值为 'png'
37
+ */
38
+ format: string
39
+ /** 接口调用结束的回调函数(调用成功、失败都会执行) */
40
+ complete?: (res: TaroGeneral.CallbackResult) => void
41
+ /** 接口调用失败的回调函数 */
42
+ fail?: (res: TaroGeneral.CallbackResult) => void
43
+ /** 接口调用成功的回调函数 */
44
+ success?: (res: SuccessCallbackResult) => void
45
+ }
46
+
47
+ interface SuccessCallbackResult {
48
+ /**
49
+ * 截图保存的临时文件路径,当 type 为 file 该字段生效
50
+ */
51
+ tempFilePath: string
52
+ /**
53
+ * 截图对应的二进制数据,当 type 为 arraybuffer 该字段生效
54
+ */
55
+ data: string
56
+ }
57
+ }
58
+ }
59
+ }
@@ -25,6 +25,25 @@ declare module '../../index' {
25
25
  /** 接口调用成功的回调函数 */
26
26
  success?: (res: TaroGeneral.CallbackResult) => void
27
27
  }
28
+
29
+ type Callback = (
30
+ result: CallbackResult,
31
+ ) => void
32
+
33
+ interface CallbackResult {
34
+ /** 缓存数据类别,取值为 periodic 或 pre */
35
+ fetchType: string
36
+ /** 缓存数据 */
37
+ fetchedData: string
38
+ /** 客户端拿到缓存数据的时间戳 */
39
+ timeStamp: number
40
+ /** 小程序页面路径 */
41
+ path: string
42
+ /** 传给页面的 query 参数 */
43
+ query: string
44
+ /** 进入小程序的场景值 */
45
+ scene: number
46
+ }
28
47
  }
29
48
 
30
49
  namespace getBackgroundFetchToken {
@@ -34,46 +53,79 @@ declare module '../../index' {
34
53
  /** 接口调用失败的回调函数 */
35
54
  fail?: (res: TaroGeneral.CallbackResult) => void
36
55
  /** 接口调用成功的回调函数 */
37
- success?: (res: TaroGeneral.CallbackResult) => void
56
+ success?: (res: SuccessCallbackResult) => void
57
+ }
58
+ interface SuccessCallbackResult extends TaroGeneral.CallbackResult {
59
+ /** 自定义的登录态 */
60
+ token: string
61
+ /** 接口调用结果 */
62
+ errMsg: string
38
63
  }
39
64
  }
40
65
 
41
66
  namespace getBackgroundFetchData {
42
67
  interface Option {
43
- /** 取值为 periodic */
68
+ /** 缓存数据类别
69
+ * @weapp 取值为 periodic
70
+ * @qq 取值为 periodic
71
+ * @alipay 取值为 pre: 数据预拉取; jsapiPre: API 预调用(目前仅支持地理位置预拉取)
72
+ */
44
73
  fetchType: string
45
74
  /** 接口调用结束的回调函数(调用成功、失败都会执行) */
46
75
  complete?: (res: TaroGeneral.CallbackResult) => void
47
76
  /** 接口调用失败的回调函数 */
48
77
  fail?: (res: TaroGeneral.CallbackResult) => void
49
78
  /** 接口调用成功的回调函数 */
50
- success?: (res: TaroGeneral.CallbackResult) => void
79
+ success?: (res: SuccessCallbackResult) => void
80
+ }
81
+
82
+ interface SuccessCallbackResult extends TaroGeneral.CallbackResult {
83
+ /** 缓存数据
84
+ * @alipay Object
85
+ */
86
+ fetchedData: string | Object
87
+ /** 客户端拿到缓存数据的时间戳 ms。(iOS 时间戳存在异常,8.0.27 修复) */
88
+ timeStamp: number
89
+ /** 小程序页面路径 */
90
+ path: string
91
+ /** 传给页面的 query 参数 */
92
+ query: string
93
+ /** 进入小程序的场景值 */
94
+ scene: number
95
+ /** 缓存数据类型,与入参 fetchType 一致
96
+ * @supported alipay
97
+ */
98
+ fetchType?: string
99
+ /** 缓存数据的时间戳。单位:ms。
100
+ * @supported alipay
101
+ */
102
+ timestamp?: number
51
103
  }
52
104
  }
53
105
 
54
106
  interface TaroStatic {
55
107
  /** 设置自定义登录态,在周期性拉取数据时带上,便于第三方服务器验证请求合法性
56
- * @supported weapp
108
+ * @supported weapp, qq
57
109
  * @see https://developers.weixin.qq.com/miniprogram/dev/api/storage/background-fetch/wx.setBackgroundFetchToken.html
58
110
  */
59
- setBackgroundFetchToken(option: setBackgroundFetchToken.Option): void
111
+ setBackgroundFetchToken(option: setBackgroundFetchToken.Option): Promise<TaroGeneral.CallbackResult>
60
112
 
61
113
  /** 收到 backgroundFetch 数据时的回调
62
- * @supported weapp
114
+ * @supported weapp, qq
63
115
  * @see https://developers.weixin.qq.com/miniprogram/dev/api/storage/background-fetch/wx.onBackgroundFetchData.html
64
116
  */
65
- onBackgroundFetchData(option?: onBackgroundFetchData.Option): void
117
+ onBackgroundFetchData(option?: onBackgroundFetchData.Option | onBackgroundFetchData.Callback): void
66
118
 
67
119
  /** 获取设置过的自定义登录态。若无,则返回 fail。
68
- * @supported weapp
120
+ * @supported weapp, qq
69
121
  * @see https://developers.weixin.qq.com/miniprogram/dev/api/storage/background-fetch/wx.getBackgroundFetchToken.html
70
122
  */
71
- getBackgroundFetchToken(option?: getBackgroundFetchToken.Option): void
123
+ getBackgroundFetchToken(option?: getBackgroundFetchToken.Option): Promise<TaroGeneral.CallbackResult>
72
124
 
73
125
  /** 拉取 backgroundFetch 客户端缓存数据
74
- * @supported weapp
126
+ * @supported weapp, alipay, qq
75
127
  * @see https://developers.weixin.qq.com/miniprogram/dev/api/storage/background-fetch/wx.getBackgroundFetchData.html
76
128
  */
77
- getBackgroundFetchData(option: getBackgroundFetchData.Option): void
129
+ getBackgroundFetchData(option: getBackgroundFetchData.Option): Promise<getBackgroundFetchData.SuccessCallbackResult>
78
130
  }
79
131
  }
@@ -2,8 +2,42 @@ import Taro from '../../index'
2
2
 
3
3
  declare module '../../index' {
4
4
  interface CacheManager {
5
+ /** 当前缓存模式 */
6
+ mode: keyof CacheManager.Mode
7
+ /** 全局 origin */
8
+ origin: string
9
+ /** 全局缓存有效时间 */
10
+ maxAge: number
11
+ /** 当前缓存管理器状态 */
12
+ state: keyof CacheManager.State
5
13
  /** 添加规则
6
14
  * @supported weapp
15
+ * @example
16
+ * ```tsx
17
+ * const ruleId = cacheManager.addRule({
18
+ * id: 'haha-rule',
19
+ * method: 'GET',
20
+ * url: '/haha',
21
+ * maxAge: 123455,
22
+ * dataSchema: [
23
+ * // data 字段的匹配,默认为空,表示不匹配
24
+ * // 类型可以是:string、number、boolean、null、object、any(表示任意类型均可),以及这些类型的数组表示方式
25
+ * {name: 'aaa', schema: {type: 'string'}}, // 类型为 string
26
+ * {name: 'bbb', schema: [{type: 'number'}, {type: 'string'}]}, // 类型为 number, string
27
+ * {name: 'ccc', schema: {type: 'string', value: 'abc'}}, // 值为 abc
28
+ * {name: 'ddd', schema: {type: 'string', value: /(abc|cba)/ig}}, // 值符合该正则匹配,如果该值不是字符串类型,则会被尝试转成字符串后再进行比较
29
+ * {name: 'ddd', schema: {type: 'string', value: val => val === '123'}}, // 传入函数来校验值
30
+ * {name: 'eee', schema: {type: 'object', value: [{ // 类型为对象,则通过嵌套的方式来逐层校验
31
+ * name: 'aaa', schema: {type: 'string'},
32
+ * // ...
33
+ * // 嵌套 dataSchema,同上面的方式一样来匹配嵌套的对象
34
+ * }]}},
35
+ * {name: 'fff', schema: {type: 'string[]'}}, // 类型为 string 数组
36
+ * {name: 'ggg', schema: {type: 'any'}}, // 类型为任意类型
37
+ * {name: 'hhh', schema: {type: 'any[]'}}, // 类型为任意类型的数组
38
+ * ]
39
+ * })
40
+ * ```
7
41
  * @see https://developers.weixin.qq.com/miniprogram/dev/api/storage/cachemanager/CacheManager.addRule.html
8
42
  */
9
43
  addRule(option: CacheManager.AddRuleOption): string
@@ -26,7 +60,7 @@ declare module '../../index' {
26
60
  * @supported weapp
27
61
  * @see https://developers.weixin.qq.com/miniprogram/dev/api/storage/cachemanager/CacheManager.deleteCache.html
28
62
  */
29
- deleteCache(
63
+ deleteCache(
30
64
  /** 缓存 id */
31
65
  id: string
32
66
  ): void
@@ -40,7 +74,7 @@ declare module '../../index' {
40
74
  ): void
41
75
  /** 删除规则,同时会删除对应规则下所有缓存
42
76
  * @supported weapp
43
- * @see https://developers.weixin.qq.com/miniprogram/dev/api/storage/cachemanager/CacheManager.deleteRule.html
77
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/storage/cachemanager/CacheManager.deleteRule.html
44
78
  */
45
79
  deleteRule(
46
80
  /** 规则 id */
@@ -67,17 +101,17 @@ declare module '../../index' {
67
101
  /** 事件名称 */
68
102
  eventName: string,
69
103
  /** 事件监听函数 */
70
- handler: Function
104
+ handler: TaroGeneral.EventCallback
71
105
  ): void
72
106
  /** 监听事件
73
107
  * @supported weapp
74
108
  * @see https://developers.weixin.qq.com/miniprogram/dev/api/storage/cachemanager/CacheManager.on.html
75
109
  */
76
- on(
110
+ on(
77
111
  /** 事件名称 */
78
112
  eventName: keyof CacheManager.OnEventName,
79
113
  /** 事件监听函数 */
80
- handler: Function
114
+ handler: TaroGeneral.EventCallback
81
115
  ): void
82
116
  /** 开启缓存,仅在 mode 为 none 时生效,调用后缓存管理器的 state 会置为 1
83
117
  * @supported weapp
@@ -92,6 +126,22 @@ declare module '../../index' {
92
126
  }
93
127
 
94
128
  namespace CacheManager {
129
+ interface Mode {
130
+ /** 默认值,弱网/离线使用缓存返回 */
131
+ weakNetwork
132
+ /** 总是使用缓存返回 */
133
+ always
134
+ /** 不开启,后续可手动开启/停止使用缓存返回 */
135
+ none
136
+ }
137
+ interface State {
138
+ /** 不使用缓存返回 */
139
+ 0
140
+ /** 使用缓存返回 */
141
+ 1
142
+ /** 未知 */
143
+ 2
144
+ }
95
145
  interface DataSchema {
96
146
  /** 需要匹配的 data 对象的参数类型
97
147
  * string、number、boolean、null、object、any(表示任意类型),
@@ -117,7 +167,7 @@ declare module '../../index' {
117
167
  method: string
118
168
  /** uri 匹配规则,可参考规则字符串写法和正则写法 */
119
169
  url: any
120
- /**
170
+ /**
121
171
  * 缓存有效时间,单位为 ms,不填则默认取缓存管理器全局的缓存有效时间
122
172
  * @default 7 * 24 * 60 * 60 * 1000
123
173
  */
@@ -135,6 +185,7 @@ declare module '../../index' {
135
185
  rule: Rule
136
186
  }
137
187
  interface AddRulesOption {
188
+ /** 规则列表 */
138
189
  rules: Rule[]
139
190
  }
140
191
  interface MatchOption {
@@ -189,10 +240,10 @@ declare module '../../index' {
189
240
  }
190
241
 
191
242
  interface TaroStatic {
192
- /** 拉起手机发送短信界面
193
- * @supported weap
194
- * @see declare module '../../index'
243
+ /** 创建缓存管理器
244
+ * @supported weapp
245
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/storage/cachemanager/wx.createCacheManager.html
195
246
  */
196
247
  createCacheManager(option: createCacheManager.Option): CacheManager
197
248
  }
198
- }
249
+ }