@tarojs/taro 3.7.0-alpha.25 → 3.7.0-alpha.27

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 (53) hide show
  1. package/html.css +9 -0
  2. package/package.json +5 -5
  3. package/types/api/base/system.d.ts +2 -2
  4. package/types/api/data-analysis/index.d.ts +51 -1
  5. package/types/api/device/accelerometer.d.ts +8 -6
  6. package/types/api/device/accessibility.d.ts +1 -1
  7. package/types/api/device/battery.d.ts +3 -3
  8. package/types/api/device/bluetooth-ble.d.ts +40 -17
  9. package/types/api/device/bluetooth-peripheral.d.ts +26 -26
  10. package/types/api/device/bluetooth.d.ts +37 -13
  11. package/types/api/device/calendar.d.ts +11 -1
  12. package/types/api/device/clipboard.d.ts +17 -17
  13. package/types/api/device/compass.d.ts +5 -5
  14. package/types/api/device/gyroscope.d.ts +4 -4
  15. package/types/api/device/iBeacon.d.ts +10 -8
  16. package/types/api/device/keyboard.d.ts +7 -5
  17. package/types/api/device/memory.d.ts +3 -4
  18. package/types/api/device/motion.d.ts +8 -6
  19. package/types/api/device/network.d.ts +12 -6
  20. package/types/api/device/nfc.d.ts +13 -13
  21. package/types/api/device/phone.d.ts +1 -1
  22. package/types/api/device/scan.d.ts +5 -3
  23. package/types/api/device/screen.d.ts +28 -12
  24. package/types/api/device/sms.d.ts +1 -1
  25. package/types/api/device/vibrate.d.ts +5 -5
  26. package/types/api/device/wifi.d.ts +25 -13
  27. package/types/api/files/index.d.ts +71 -41
  28. package/types/api/location/index.d.ts +166 -18
  29. package/types/api/media/camera.d.ts +6 -3
  30. package/types/api/media/image.d.ts +1 -1
  31. package/types/api/navigate/index.d.ts +2 -0
  32. package/types/api/network/request.d.ts +1 -1
  33. package/types/api/route/index.d.ts +5 -5
  34. package/types/api/storage/background-fetch.d.ts +63 -11
  35. package/types/api/storage/cache-manager.d.ts +51 -0
  36. package/types/api/storage/index.d.ts +125 -10
  37. package/types/api/taro.extend.d.ts +1 -1
  38. package/types/api/ui/animation.d.ts +1 -1
  39. package/types/api/ui/fonts.d.ts +4 -3
  40. package/types/api/ui/interaction.d.ts +4 -4
  41. package/types/api/ui/pull-down-refresh.d.ts +2 -2
  42. package/types/api/ui/scroll.d.ts +1 -1
  43. package/types/api/ui/tab-bar.d.ts +7 -7
  44. package/types/api/wxml/index.d.ts +4 -4
  45. package/types/compile/config/h5.d.ts +7 -1
  46. package/types/compile/config/harmony.d.ts +77 -0
  47. package/types/compile/config/index.d.ts +1 -0
  48. package/types/compile/config/mini.d.ts +14 -8
  49. package/types/compile/config/plugin.d.ts +34 -0
  50. package/types/compile/config/project.d.ts +3 -0
  51. package/types/compile/config/util.d.ts +3 -1
  52. package/types/compile/viteCompilerContext.d.ts +24 -5
  53. package/types/taro.config.d.ts +6 -0
@@ -7,16 +7,23 @@ declare module '../../index' {
7
7
  latitude: number
8
8
  /** 经度,范围为-180~180,负数表示西经。使用 gcj02 国测局坐标系 */
9
9
  longitude: number
10
+ /** 缩放比例
11
+ * @weapp 范围 5~18,默认值18
12
+ * @alipay 范围 3~19,默认值15
13
+ */
14
+ scale?: number
15
+ /** 位置名 */
16
+ name?: string
10
17
  /** 地址的详细说明 */
11
18
  address?: string
19
+ /** 定义在拉起的地图 App 面板中需要被屏蔽的地图类 App
20
+ * @supported swan
21
+ */
22
+ ignoredApps?: Array<any>
12
23
  /** 接口调用结束的回调函数(调用成功、失败都会执行) */
13
24
  complete?: (res: TaroGeneral.CallbackResult) => void
14
25
  /** 接口调用失败的回调函数 */
15
26
  fail?: (res: TaroGeneral.CallbackResult) => void
16
- /** 位置名 */
17
- name?: string
18
- /** 缩放比例,范围5~18 */
19
- scale?: number
20
27
  /** 接口调用成功的回调函数 */
21
28
  success?: (res: TaroGeneral.CallbackResult) => void
22
29
  }
@@ -24,20 +31,32 @@ declare module '../../index' {
24
31
 
25
32
  namespace getLocation {
26
33
  interface Option {
27
- /** 传入 true 会返回高度信息,由于获取高度需要较高精确度,会减慢接口返回速度 */
28
- altitude?: string
34
+ /** 传入 true 会返回高度信息,由于获取高度需要较高精确度,会减慢接口返回速度
35
+ * @default false
36
+ */
37
+ altitude?: boolean
29
38
  /** 接口调用结束的回调函数(调用成功、失败都会执行) */
30
39
  complete?: (res: TaroGeneral.CallbackResult) => void
31
40
  /** 接口调用失败的回调函数 */
32
41
  fail?: (res: TaroGeneral.CallbackResult) => void
33
42
  /** 高精度定位超时时间(ms),指定时间内返回最高精度,该值3000ms以上高精度定位才有效果 */
34
43
  highAccuracyExpireTime?: number
35
- /** 开启高精度定位 */
44
+ /** 开启高精度定位
45
+ * @default false
46
+ */
36
47
  isHighAccuracy?: boolean
37
48
  /** 接口调用成功的回调函数 */
38
49
  success?: (result: SuccessCallbackResult) => void
39
- /** wgs84 返回 gps 坐标,gcj02 返回可用于 Taro.openLocation 的坐标 */
50
+ /** wgs84 返回 gps 坐标,gcj02 返回可用于 Taro.openLocation 的坐标
51
+ * @default "wgs84"
52
+ */
40
53
  type?: string
54
+ /** 针对 iOS14/Android12 及以上的新特性,其他情况本参数忽略。默认情况宿主是精确定位就返回精确定位信息。
55
+ * 传入 true 会强制使用精确定位信息,iOS14/Android12 及以上如果没有精确定位权限,会弹出精确定位授权弹框
56
+ * @supported swan
57
+ * @default false
58
+ */
59
+ needFullAccuracy?: boolean
41
60
  }
42
61
  interface SuccessCallbackResult extends TaroGeneral.CallbackResult {
43
62
  /** 位置的精确度 */
@@ -54,6 +73,42 @@ declare module '../../index' {
54
73
  speed: number
55
74
  /** 垂直精度,单位 m(Android 无法获取,返回 0) */
56
75
  verticalAccuracy: number
76
+ /** 城市名称
77
+ * @supported swan
78
+ */
79
+ street?: string
80
+ /** 国家代码
81
+ * @supported swan
82
+ */
83
+ cityCode?: string
84
+ /** 城市名称
85
+ * @supported swan, tt
86
+ */
87
+ city?: string
88
+ /** 国家
89
+ * @supported swan
90
+ */
91
+ country?: string
92
+ /** 国家代码
93
+ * @supported swan
94
+ */
95
+ countryCode?: string
96
+ /** 省份
97
+ * @supported swan
98
+ */
99
+ province?: string
100
+ /** 街道号码
101
+ * @supported swan
102
+ */
103
+ streetNumber?: string
104
+ /** 区
105
+ * @supported swan
106
+ */
107
+ district?: string
108
+ /** 是不是精确定位信息
109
+ * @supported swan
110
+ */
111
+ isFullAccuracy?: boolean
57
112
  /** 调用结果 */
58
113
  errMsg: string
59
114
  }
@@ -97,6 +152,12 @@ declare module '../../index' {
97
152
  * @see https://lbs.qq.com/webApi/component/componentGuide/componentPicker
98
153
  */
99
154
  mapOpts?: Record<string, unknown>
155
+ /** 页面显示标题
156
+ * @supported alipay
157
+ * @alipay 安卓默认值为 位置,iOS、IDE 默认值为 你在哪里?
158
+ * @see https://opendocs.alipay.com/mini/api/location?pathHash=951b46a1
159
+ */
160
+ title?: string
100
161
  /** 接口调用成功的回调函数 */
101
162
  success?: (result: SuccessCallbackResult) => void
102
163
  /** 接口调用失败的回调函数 */
@@ -114,6 +175,30 @@ declare module '../../index' {
114
175
  longitude: number
115
176
  /** 位置名称 */
116
177
  name: string
178
+ /** 区县代码
179
+ * @supported alipay
180
+ */
181
+ adCode?: number
182
+ /** 区县名称
183
+ * @supported alipay
184
+ */
185
+ adName?: string
186
+ /** 城市代码
187
+ * @supported alipay
188
+ */
189
+ cityCode?: string
190
+ /** 城市名称
191
+ * @supported alipay
192
+ */
193
+ cityName?: string
194
+ /** 省份代码
195
+ * @supported alipay
196
+ */
197
+ provinceCode?: number
198
+ /** 省份名称
199
+ * @supported alipay
200
+ */
201
+ provinceName?: string
117
202
  /** 调用结果 */
118
203
  errMsg: string
119
204
  }
@@ -132,6 +217,10 @@ declare module '../../index' {
132
217
 
133
218
  namespace startLocationUpdateBackground {
134
219
  interface Option {
220
+ /** wgs84 返回 gps 坐标,gcj02 返回可用于 wx.openLocation 的坐标
221
+ * @default "gcj02"
222
+ */
223
+ type?: string
135
224
  /** 接口调用结束的回调函数(调用成功、失败都会执行) */
136
225
  complete?: (res: TaroGeneral.CallbackResult) => void
137
226
  /** 接口调用失败的回调函数 */
@@ -143,6 +232,16 @@ declare module '../../index' {
143
232
 
144
233
  namespace startLocationUpdate {
145
234
  interface Option {
235
+ /** wgs84 返回 gps 坐标,gcj02 返回可用于 wx.openLocation 的坐标
236
+ * @default "gcj02"
237
+ */
238
+ type?: string
239
+ /** 针对 iOS14/Android12 及以上的新特性,其他情况本参数忽略。默认情况宿主是精确定位就返回精确定位信息。
240
+ * 传入 true 会强制使用精确定位信息,iOS14/Android12 及以上如果没有精确定位权限,会弹出精确定位授权弹框
241
+ * @supported swan
242
+ * @default false
243
+ */
244
+ needFullAccuracy?: boolean
146
245
  /** 接口调用结束的回调函数(调用成功、失败都会执行) */
147
246
  complete?: (res: TaroGeneral.CallbackResult) => void
148
247
  /** 接口调用失败的回调函数 */
@@ -161,6 +260,11 @@ declare module '../../index' {
161
260
  interface CallbackResult {
162
261
  /** 错误码 */
163
262
  errCode: number
263
+ /** 错误信息
264
+ * @supported tt
265
+ * @tt 最低支持版本 2.48.0
266
+ */
267
+ errMsg?: string
164
268
  }
165
269
  }
166
270
 
@@ -185,13 +289,50 @@ declare module '../../index' {
185
289
  speed: number
186
290
  /** 垂直精度,单位 m(Android 无法获取,返回 0) */
187
291
  verticalAccuracy: number
292
+ /** 街道名称
293
+ * @supported swan
294
+ */
295
+ street?: string
296
+ /** 城市编码
297
+ * @supported swan
298
+ */
299
+ cityCode?: string
300
+ /** 城市名称
301
+ * @supported swan, tt
302
+ * @tt iOS 不支持
303
+ */
304
+ city?: string
305
+ /** 国家
306
+ * @supported swan
307
+ */
308
+ country?: string
309
+ /** 国家代码
310
+ * @supported swan
311
+ */
312
+ countryCode?: string
313
+ /** 省份
314
+ * @supported swan
315
+ */
316
+ province?: string
317
+ /** 街道号码
318
+ * @supported swan
319
+ */
320
+ streetNumber?: string
321
+ /** 区
322
+ * @supported swan
323
+ */
324
+ district?: string
325
+ /** 是不是精确定位信息
326
+ * @supported swan
327
+ */
328
+ isFullAccuracy?: boolean
188
329
  }
189
330
  }
190
331
 
191
332
  namespace getFuzzyLocation {
192
333
  interface Option {
193
334
  /** wgs84 返回 gps 坐标,gcj02 返回可用于 Taro.openLocation 的坐标 */
194
- type?: 'wgs84' | 'gcj02'
335
+ type?: keyof Type
195
336
  /** 接口调用结束的回调函数(调用成功、失败都会执行) */
196
337
  complete?: (res: TaroGeneral.CallbackResult) => void
197
338
  /** 接口调用失败的回调函数 */
@@ -200,6 +341,13 @@ declare module '../../index' {
200
341
  success?: (result: SuccessCallbackResult) => void
201
342
  }
202
343
 
344
+ interface Type {
345
+ /** 返回 gps 坐标 */
346
+ wgs84
347
+ /** 返回 gcj02 坐标*/
348
+ gcj02
349
+ }
350
+
203
351
  interface SuccessCallbackResult extends TaroGeneral.CallbackResult {
204
352
  /** 纬度,范围为 -90~90,负数表示南纬 */
205
353
  latitude: number
@@ -210,7 +358,7 @@ declare module '../../index' {
210
358
 
211
359
  interface TaroStatic {
212
360
  /** 关闭监听实时位置变化,前后台都停止消息接收
213
- * @supported weapp, rn, tt
361
+ * @supported weapp, swan, tt, rn
214
362
  * @see https://developers.weixin.qq.com/miniprogram/dev/api/location/wx.stopLocationUpdate.html
215
363
  */
216
364
  stopLocationUpdate(option?: stopLocationUpdate.Option): void
@@ -232,13 +380,13 @@ declare module '../../index' {
232
380
  *
233
381
  * **注意**
234
382
  * - 获取位置信息需配置[地理位置用途说明](https://developers.weixin.qq.com/miniprogram/dev/reference/configuration/app.html#permission)。
235
- * @supported weapp, rn, tt
383
+ * @supported weapp, swan, tt, rn
236
384
  * @see https://developers.weixin.qq.com/miniprogram/dev/api/location/wx.startLocationUpdate.html
237
385
  */
238
386
  startLocationUpdate(option?: startLocationUpdate.Option): void
239
387
 
240
388
  /** 使用微信内置地图查看位置
241
- * @supported weapp, h5, tt
389
+ * @supported weapp, alipay, swan, jd, tt, h5
242
390
  * @example
243
391
  * ```tsx
244
392
  * Taro.getLocation({
@@ -268,7 +416,7 @@ declare module '../../index' {
268
416
  ): void
269
417
 
270
418
  /** 监听实时地理位置变化事件,需结合 Taro.startLocationUpdateBackground、Taro.startLocationUpdate 使用。
271
- * @supported weapp, rn, tt
419
+ * @supported weapp, swan, tt, rn
272
420
  * @example
273
421
  * ```tsx
274
422
  * const _locationChangeFn = function (res) {
@@ -290,16 +438,16 @@ declare module '../../index' {
290
438
  */
291
439
  offLocationChangeError(
292
440
  /** 监听持续定位接口返回失败时触发的回调函数 */
293
- callback: onLocationChangeError.Callback,
441
+ callback?: onLocationChangeError.Callback,
294
442
  ): void
295
443
 
296
444
  /** 取消监听实时地理位置变化事件
297
- * @supported weapp, rn, tt
445
+ * @supported weapp, swan, tt, rn
298
446
  * @see https://developers.weixin.qq.com/miniprogram/dev/api/location/wx.offLocationChange.html
299
447
  */
300
448
  offLocationChange(
301
449
  /** 实时地理位置变化事件的回调函数 */
302
- callback: (res: TaroGeneral.CallbackResult) => void,
450
+ callback?: onLocationChange.Callback,
303
451
  ): void
304
452
 
305
453
  /** 获取当前的地理位置、速度。当用户离开小程序后,此接口无法调用。开启高精度定位,接口耗时会增加,可指定 highAccuracyExpireTime 作为超时时间。
@@ -307,7 +455,7 @@ declare module '../../index' {
307
455
  * **注意**
308
456
  * - 工具中定位模拟使用IP定位,可能会有一定误差。且工具目前仅支持 gcj02 坐标。
309
457
  * - 使用第三方服务进行逆地址解析时,请确认第三方服务默认的坐标系,正确进行坐标转换。
310
- * @supported weapp, rn, tt
458
+ * @supported weapp, swan, jd, qq, tt, rn
311
459
  * @example
312
460
  * ```tsx
313
461
  * Taro.getLocation({
@@ -333,7 +481,7 @@ declare module '../../index' {
333
481
  /** 打开地图选择位置。
334
482
  *
335
483
  * `chooseLocation` api功能是依赖于腾讯位置服务,所以需要使用 api 密钥。如果您没有,可以前往腾讯位置服务[开发者控制台](https://lbs.qq.com/console/mykey.html?console=mykey)进行申请。
336
- * @supported weapp, h5, tt
484
+ * @supported weapp, alipay, swan, jd, tt, h5
337
485
  * @example
338
486
  * ```tsx
339
487
  * // config/index.js
@@ -90,15 +90,15 @@ declare module '../../index' {
90
90
  * @supported alipay
91
91
  */
92
92
  height: string
93
- /** 视频文件的宽度。
93
+ /** 视频文件的宽度。
94
94
  * @supported alipay
95
95
  */
96
96
  width: string
97
- /** 视频文件的尺寸。
97
+ /** 视频文件的尺寸。
98
98
  * @supported alipay
99
99
  */
100
100
  size: string
101
- /** 录制的持续时间。
101
+ /** 录制的持续时间。
102
102
  * @supported alipay
103
103
  */
104
104
  duration: string
@@ -152,6 +152,8 @@ declare module '../../index' {
152
152
  normal
153
153
  /** 低质量 */
154
154
  low
155
+ /** 原图 */
156
+ original
155
157
  }
156
158
  }
157
159
 
@@ -192,6 +194,7 @@ declare module '../../index' {
192
194
 
193
195
  interface TaroStatic {
194
196
  /** 创建 camera 上下文 CameraContext 对象。
197
+ * @alipay 支付宝小程序需指定 camera 组件中的 id 属性
195
198
  * @supported weapp, rn, tt, alipay
196
199
  * @example
197
200
  * ```tsx
@@ -361,7 +361,7 @@ declare module '../../index' {
361
361
  previewImage(option: previewImage.Option): Promise<TaroGeneral.CallbackResult>
362
362
 
363
363
  /** 获取图片信息。网络图片需先配置download域名才能生效。
364
- * @supported weapp, alipay, swan, tt, h5, rn
364
+ * @supported weapp, alipay, swan, tt, h5, rn, harmony
365
365
  * @example
366
366
  * ```tsx
367
367
  * Taro.getImageInfo({
@@ -17,6 +17,8 @@ declare module '../../index' {
17
17
  verify?: keyof Verify
18
18
  /** 不 reLaunch 目标小程序,直接打开目标跳转的小程序退后台时的页面,需满足以下条件:1. 目标跳转的小程序生命周期未被销毁;2. 且目标当次启动的path、query、apiCategory与上次启动相同。默认值为 false 。 */
19
19
  noRelaunchIfPathUnchanged?: boolean
20
+ /** 打开的小程序是否支持全屏 */
21
+ allowFullScreen?: boolean
20
22
  /** 接口调用成功的回调函数 */
21
23
  success?: (res: TaroGeneral.CallbackResult) => void
22
24
  /** 接口调用失败的回调函数 */
@@ -400,7 +400,7 @@ declare module '../../index' {
400
400
  * - 对于 `GET` 方法的数据,会将数据转换成 query string(`encodeURIComponent(k)=encodeURIComponent(v)&encodeURIComponent(k)=encodeURIComponent(v)...`)
401
401
  * - 对于 `POST` 方法且 `header['content-type']` 为 `application/json` 的数据,会对数据进行 JSON 序列化
402
402
  * - 对于 `POST` 方法且 `header['content-type']` 为 `application/x-www-form-urlencoded` 的数据,会将数据转换成 query string `(encodeURIComponent(k)=encodeURIComponent(v)&encodeURIComponent(k)=encodeURIComponent(v)...)`
403
- * @supported weapp, h5, rn, alipay, swan, tt, qq
403
+ * @supported weapp, h5, rn, alipay, swan, tt, qq, harmony
404
404
  * @example
405
405
  * ```tsx
406
406
  * Taro.request({
@@ -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
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
147
147
  * @example
148
148
  * ```tsx
149
149
  * Taro.reLaunch({
@@ -155,7 +155,7 @@ 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
159
159
  * @h5 未针对 tabbar 页面做限制处理
160
160
  * @example
161
161
  * ```tsx
@@ -168,7 +168,7 @@ declare module '../../index' {
168
168
  redirectTo(option: redirectTo.Option): Promise<TaroGeneral.CallbackResult>
169
169
 
170
170
  /** 保留当前页面,跳转到应用内的某个页面。但是不能跳到 tabbar 页面。使用 Taro.navigateBack 可以返回到原页面。小程序中页面栈最多十层。
171
- * @supported weapp, h5, rn, tt
171
+ * @supported weapp, h5, rn, tt, harmony
172
172
  * @h5 未针对 tabbar 页面做限制处理
173
173
  * @example
174
174
  * ```tsx
@@ -195,7 +195,7 @@ declare module '../../index' {
195
195
  navigateTo(option: navigateTo.Option): Promise<TaroGeneral.CallbackResult>
196
196
 
197
197
  /** 关闭当前页面,返回上一页面或多级页面。可通过 getCurrentPages 获取当前的页面栈,决定需要返回几层。
198
- * @supported weapp, h5, rn, tt
198
+ * @supported weapp, h5, rn, tt, harmony
199
199
  * @h5 若入参 delta 大于现有页面数时,返回应用打开的第一个页面(如果想要返回首页请使用 reLaunch 方法)。
200
200
  * @example
201
201
  * ```tsx
@@ -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
@@ -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(表示任意类型),
@@ -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 {