@tarojs/taro 3.8.0-canary.0 → 4.0.0-beta.0

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 (73) hide show
  1. package/html.css +9 -0
  2. package/package.json +11 -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/performance.d.ts +5 -5
  7. package/types/api/base/system.d.ts +2 -2
  8. package/types/api/base/weapp/app-event.d.ts +4 -4
  9. package/types/api/canvas/index.d.ts +67 -54
  10. package/types/api/data-analysis/index.d.ts +51 -1
  11. package/types/api/device/accelerometer.d.ts +8 -6
  12. package/types/api/device/accessibility.d.ts +1 -1
  13. package/types/api/device/battery.d.ts +3 -3
  14. package/types/api/device/bluetooth-ble.d.ts +40 -17
  15. package/types/api/device/bluetooth-peripheral.d.ts +26 -26
  16. package/types/api/device/bluetooth.d.ts +37 -13
  17. package/types/api/device/calendar.d.ts +11 -1
  18. package/types/api/device/clipboard.d.ts +17 -17
  19. package/types/api/device/compass.d.ts +5 -5
  20. package/types/api/device/gyroscope.d.ts +4 -4
  21. package/types/api/device/iBeacon.d.ts +10 -8
  22. package/types/api/device/keyboard.d.ts +7 -5
  23. package/types/api/device/memory.d.ts +3 -4
  24. package/types/api/device/motion.d.ts +8 -6
  25. package/types/api/device/network.d.ts +12 -6
  26. package/types/api/device/nfc.d.ts +13 -13
  27. package/types/api/device/phone.d.ts +1 -1
  28. package/types/api/device/scan.d.ts +5 -3
  29. package/types/api/device/screen.d.ts +28 -12
  30. package/types/api/device/sms.d.ts +1 -1
  31. package/types/api/device/vibrate.d.ts +5 -5
  32. package/types/api/device/wifi.d.ts +25 -13
  33. package/types/api/files/index.d.ts +71 -41
  34. package/types/api/location/index.d.ts +166 -18
  35. package/types/api/media/audio.d.ts +50 -30
  36. package/types/api/media/camera.d.ts +6 -3
  37. package/types/api/media/image.d.ts +1 -1
  38. package/types/api/navigate/index.d.ts +2 -0
  39. package/types/api/network/download.d.ts +2 -10
  40. package/types/api/network/request.d.ts +1 -1
  41. package/types/api/network/upload.d.ts +2 -10
  42. package/types/api/open-api/device-voip.d.ts +2 -2
  43. package/types/api/open-api/login.d.ts +1 -1
  44. package/types/api/open-api/my-miniprogram.d.ts +2 -2
  45. package/types/api/open-api/privacy.d.ts +99 -0
  46. package/types/api/route/index.d.ts +8 -5
  47. package/types/api/skyline/index.d.ts +59 -0
  48. package/types/api/storage/background-fetch.d.ts +63 -11
  49. package/types/api/storage/cache-manager.d.ts +61 -10
  50. package/types/api/storage/index.d.ts +125 -10
  51. package/types/api/taro.extend.d.ts +9 -3
  52. package/types/api/ui/animation.d.ts +1 -1
  53. package/types/api/ui/fonts.d.ts +4 -3
  54. package/types/api/ui/interaction.d.ts +4 -4
  55. package/types/api/ui/navigation-bar.d.ts +5 -5
  56. package/types/api/ui/pull-down-refresh.d.ts +2 -2
  57. package/types/api/ui/scroll.d.ts +1 -1
  58. package/types/api/ui/tab-bar.d.ts +7 -7
  59. package/types/api/wxml/index.d.ts +4 -4
  60. package/types/compile/compiler.d.ts +7 -4
  61. package/types/compile/config/h5.d.ts +23 -10
  62. package/types/compile/config/harmony.d.ts +77 -0
  63. package/types/compile/config/index.d.ts +1 -0
  64. package/types/compile/config/mini.d.ts +58 -30
  65. package/types/compile/config/plugin.d.ts +34 -0
  66. package/types/compile/config/project.d.ts +26 -13
  67. package/types/compile/config/util.d.ts +22 -8
  68. package/types/compile/viteCompilerContext.d.ts +149 -0
  69. package/types/global.d.ts +1 -0
  70. package/types/index.d.ts +2 -0
  71. package/types/taro.api.d.ts +3 -0
  72. package/types/taro.component.d.ts +2 -1
  73. package/types/taro.config.d.ts +41 -4
@@ -0,0 +1,99 @@
1
+ import Taro from '../../index'
2
+
3
+ declare module '../../index' {
4
+ namespace getPrivacySetting {
5
+ interface Option {
6
+ /** 接口调用结束的回调函数(调用成功、失败都会执行) */
7
+ complete?: (res: TaroGeneral.CallbackResult) => void
8
+ /** 接口调用失败的回调函数 */
9
+ fail?: (res: TaroGeneral.CallbackResult) => void
10
+ /** 接口调用成功的回调函数 */
11
+ success?: (result: SuccessCallbackResult) => void
12
+ }
13
+ interface SuccessCallbackResult extends TaroGeneral.CallbackResult {
14
+ /** 是否需要用户授权隐私协议(如果开发者没有在[mp后台-设置-服务内容声明-用户隐私保护指引]中声明隐私收集类型则会返回false;如果开发者声明了隐私收集,且用户之前同意过隐私协议则会返回false;如果开发者声明了隐私收集,且用户还没同意过则返回true;如果用户之前同意过、但后来小程序又新增了隐私收集类型也会返回true) */
15
+ needAuthorization: boolean
16
+ /** 隐私授权协议的名称 */
17
+ privacyContractName: string
18
+ }
19
+ }
20
+
21
+ namespace requirePrivacyAuthorize {
22
+ interface Option {
23
+ /** 接口调用结束的回调函数(调用成功、失败都会执行) */
24
+ complete?: (res: TaroGeneral.CallbackResult) => void
25
+ /** 接口调用失败的回调函数 */
26
+ fail?: (res: TaroGeneral.CallbackResult) => void
27
+ /** 接口调用成功的回调函数 */
28
+ success?: (result: TaroGeneral.CallbackResult) => void
29
+ }
30
+ }
31
+
32
+ namespace openPrivacyContract {
33
+ interface Option {
34
+ /** 接口调用结束的回调函数(调用成功、失败都会执行) */
35
+ complete?: (res: TaroGeneral.CallbackResult) => void
36
+ /** 接口调用失败的回调函数 */
37
+ fail?: (res: TaroGeneral.CallbackResult) => void
38
+ /** 接口调用成功的回调函数 */
39
+ success?: (result: TaroGeneral.CallbackResult) => void
40
+ }
41
+ }
42
+
43
+ namespace onNeedPrivacyAuthorization {
44
+ /**
45
+ * resolve 是 onNeedPrivacyAuthorization 的回调参数,是一个接口函数。
46
+ * 当触发 needPrivacyAuthorization 事件时,触发该事件的隐私接口或组件会处于 pending 状态。
47
+ * 如果调用 resolve({ buttonId: 'disagree-btn', event:'agree' }),则触发当前 needPrivacyAuthorization 事件的原隐私接口或组件会继续执行。其中 buttonId 为隐私同意授权按钮的id,为确保用户有同意的操作,基础库会检查对应的同意按钮是否被点击过。
48
+ * 如果调用 resolve({ event: 'disagree' }),则触发当前 needPrivacyAuthorization 事件的原隐私接口或组件会失败并返回 API:fail privacy permission is not authorized 的错误信息。
49
+ * 在调用 resolve({ event: 'agree'/'disagree' }) 之前,开发者可以调用 resolve({ event: 'exposureAuthorization' }) 把隐私弹窗曝光告知平台。
50
+ */
51
+ interface ResolveOption {
52
+ /** 用户操作类型 */
53
+ event: 'exposureAuthorization' | 'agree' | 'disagree'
54
+ /** 同意授权按钮的id (仅event=agree时必填) */
55
+ buttonId?: string
56
+ }
57
+ /**
58
+ * 触发本次 onNeedPrivacyAuthorization 事件的关联信息
59
+ */
60
+ interface EventInfo {
61
+ referrer: string
62
+ }
63
+
64
+ /** 隐私授权监听函数 */
65
+ type Listener = (
66
+ /** 事件回调函数 */
67
+ resolve: (option: ResolveOption) => void,
68
+ /** 关联事件信息 */
69
+ eventInfo: EventInfo
70
+ ) => void
71
+ }
72
+
73
+ interface TaroStatic {
74
+ /**
75
+ * 查询隐私授权情况。隐私合规开发指南详情可见《小程序隐私协议开发指南》
76
+ * @supported weapp
77
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/open-api/privacy/wx.getPrivacySetting.html
78
+ */
79
+ getPrivacySetting(option?: getPrivacySetting.Option): void
80
+ /**
81
+ * 跳转至隐私协议页面。隐私合规开发指南详情可见《小程序隐私协议开发指南》
82
+ * @supported weapp
83
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/open-api/privacy/wx.openPrivacyContract.html
84
+ */
85
+ openPrivacyContract(option?: openPrivacyContract.Option): void
86
+ /**
87
+ * 模拟隐私接口调用,并触发隐私弹窗逻辑。隐私合规开发指南详情可见《小程序隐私协议开发指南》
88
+ * @supported weapp
89
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/open-api/privacy/wx.requirePrivacyAuthorize.html
90
+ */
91
+ requirePrivacyAuthorize(option?: requirePrivacyAuthorize.Option): void
92
+ /**
93
+ * 监听隐私接口需要用户授权事件。当需要用户进行隐私授权时会触发。触发该事件时,开发者需要弹出隐私协议说明,并在用户同意或拒绝授权后调用回调接口 resolve 触发原隐私接口或组件继续执行。隐私合规开发指南详情可见《小程序隐私协议开发指南》
94
+ * @supported weapp
95
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/open-api/privacy/wx.onNeedPrivacyAuthorization.html
96
+ */
97
+ onNeedPrivacyAuthorization(listener: onNeedPrivacyAuthorization.Listener): void
98
+ }
99
+ }
@@ -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,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
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
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
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
+ }
@@ -49,6 +49,10 @@ declare module '../../index' {
49
49
  keys: string[]
50
50
  /** 限制的空间大小,单位 KB */
51
51
  limitSize: number
52
+ /** 是否执行成功
53
+ * @supported alipay
54
+ */
55
+ success?: boolean
52
56
  }
53
57
  }
54
58
 
@@ -102,9 +106,54 @@ declare module '../../index' {
102
106
  }
103
107
  }
104
108
 
109
+ namespace batchSetStorageSync {
110
+ interface Option {
111
+ /** [{ key, value }] */
112
+ kvList: kv[]
113
+ }
114
+ interface kv {
115
+ /** key 本地缓存中指定的 key */
116
+ key: string
117
+ /** data 需要存储的内容。只支持原生类型、Date、及能够通过JSON.stringify序列化的对象。*/
118
+ value: any
119
+ }
120
+ }
121
+
122
+ namespace batchSetStorage {
123
+ interface Option {
124
+ /** [{ key, value }] */
125
+ kvList: kv[]
126
+ /** 接口调用结束的回调函数(调用成功、失败都会执行) */
127
+ complete?: (res: TaroGeneral.CallbackResult) => void
128
+ /** 接口调用失败的回调函数 */
129
+ fail?: (res: TaroGeneral.CallbackResult) => void
130
+ /** 接口调用成功的回调函数 */
131
+ success?: (res: TaroGeneral.CallbackResult) => void
132
+ }
133
+ interface kv {
134
+ /** key 本地缓存中指定的 key */
135
+ key: string
136
+ /** data 需要存储的内容。只支持原生类型、Date、及能够通过JSON.stringify序列化的对象。*/
137
+ value: any
138
+ }
139
+ }
140
+
141
+ namespace batchGetStorage {
142
+ interface Option {
143
+ /** 本地缓存中指定的 keyList */
144
+ keyList: string[]
145
+ /** 接口调用结束的回调函数(调用成功、失败都会执行) */
146
+ complete?: (res: TaroGeneral.CallbackResult) => void
147
+ /** 接口调用失败的回调函数 */
148
+ fail?: (res: TaroGeneral.CallbackResult) => void
149
+ /** 接口调用成功的回调函数 */
150
+ success?: (res: TaroGeneral.CallbackResult) => void
151
+ }
152
+ }
153
+
105
154
  interface TaroStatic {
106
155
  /** Taro.setStorage 的同步版本
107
- * @supported weapp, h5, tt
156
+ * @supported weapp, alipay, swan, jd, qq, tt, h5
108
157
  * @example
109
158
  * ```tsx
110
159
  * Taro.setStorage({
@@ -128,7 +177,7 @@ declare module '../../index' {
128
177
  ): void
129
178
 
130
179
  /** 将数据存储在本地缓存中指定的 key 中。会覆盖掉原来该 key 对应的内容。除非用户主动删除或因存储空间原因被系统清理,否则数据都一直可用。单个 key 允许存储的最大数据长度为 1MB,所有数据存储上限为 10MB。
131
- * @supported weapp, h5, rn, tt
180
+ * @supported weapp, alipay, swan, jd, qq, tt, h5, rn, harmony
132
181
  * @example
133
182
  * ```tsx
134
183
  * Taro.setStorage({
@@ -155,7 +204,7 @@ declare module '../../index' {
155
204
  ): void
156
205
 
157
206
  /** Taro.removeStorage 的同步版本
158
- * @supported weapp, h5, tt
207
+ * @supported weapp, alipay, swan, jd, qq, tt, h5
159
208
  * @example
160
209
  * ```tsx
161
210
  * try {
@@ -172,7 +221,7 @@ declare module '../../index' {
172
221
  ): void
173
222
 
174
223
  /** 从本地缓存中移除指定 key
175
- * @supported weapp, h5, rn, tt
224
+ * @supported weapp, alipay, swan, jd, qq, tt, h5, rn, harmony
176
225
  * @example
177
226
  * ```tsx
178
227
  * Taro.removeStorage({
@@ -187,7 +236,7 @@ declare module '../../index' {
187
236
  removeStorage(option: removeStorage.Option): Promise<TaroGeneral.CallbackResult>
188
237
 
189
238
  /** Taro.getStorage 的同步版本
190
- * @supported weapp, h5, tt
239
+ * @supported weapp, alipay, swan, jd, qq, tt, h5
191
240
  * @example
192
241
  * ```tsx
193
242
  * try {
@@ -207,7 +256,7 @@ declare module '../../index' {
207
256
  ): T
208
257
 
209
258
  /** Taro.getStorageInfo 的同步版本
210
- * @supported weapp, h5, rn, tt
259
+ * @supported weapp, alipay, swan, jd, qq, tt, h5, rn
211
260
  * @example
212
261
  * ```tsx
213
262
  * try {
@@ -224,7 +273,7 @@ declare module '../../index' {
224
273
  getStorageInfoSync(): getStorageInfoSync.Option
225
274
 
226
275
  /** 异步获取当前storage的相关信息
227
- * @supported weapp, h5, rn, tt
276
+ * @supported weapp, alipay, swan, jd, qq, tt, h5, rn
228
277
  * @example
229
278
  * ```tsx
230
279
  * Taro.getStorageInfo({
@@ -240,7 +289,7 @@ declare module '../../index' {
240
289
  getStorageInfo(option?: getStorageInfo.Option): Promise<TaroGeneral.CallbackResult>
241
290
 
242
291
  /** 从本地缓存中异步获取指定 key 的内容
243
- * @supported weapp, h5, rn, tt
292
+ * @supported weapp, alipay, swan, jd, qq, tt, h5, rn, harmony
244
293
  * @example
245
294
  * ```tsx
246
295
  * Taro.getStorage({
@@ -264,7 +313,7 @@ declare module '../../index' {
264
313
  ): void
265
314
 
266
315
  /** Taro.clearStorage 的同步版本
267
- * @supported weapp, h5, tt
316
+ * @supported weapp, alipay, swan, jd, qq, tt, h5
268
317
  * @example
269
318
  * ```tsx
270
319
  * try {
@@ -278,7 +327,7 @@ declare module '../../index' {
278
327
  clearStorageSync(): void
279
328
 
280
329
  /** 清理本地数据缓存
281
- * @supported weapp, h5, rn, tt
330
+ * @supported weapp, alipay, swan, jd, qq, tt, h5, rn, harmony
282
331
  * @example
283
332
  * ```tsx
284
333
  * Taro.clearStorage()
@@ -286,5 +335,71 @@ declare module '../../index' {
286
335
  * @see https://developers.weixin.qq.com/miniprogram/dev/api/storage/wx.clearStorage.html
287
336
  */
288
337
  clearStorage(option?: clearStorage.Option): Promise<TaroGeneral.CallbackResult>
338
+
339
+ /** 将数据批量存储在本地缓存中指定的 key 中。
340
+ * 会覆盖掉原来该 key 对应的内容。除非用户主动删除或因存储空间原因被系统清理,否则数据都一直可用。
341
+ * 单个 key 允许存储的最大数据长度为 1MB,所有数据存储上限为 10MB。
342
+ * @supported weapp
343
+ * @example
344
+ * ```tsx
345
+ * try {
346
+ * Taro.batchSetStorageSync([{key: 'key', value: 'value'}])
347
+ * } catch (e) { }
348
+ * ```
349
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/storage/wx.batchGetStorageSync.html
350
+ */
351
+ batchSetStorageSync(option: batchSetStorageSync.Option): void
352
+
353
+ /** 将数据批量存储在本地缓存中指定的 key 中。会覆盖掉原来该 key 对应的内容。
354
+ * 除非用户主动删除或因存储空间原因被系统清理,否则数据都一直可用。
355
+ * 单个 key 允许存储的最大数据长度为 1MB,所有数据存储上限为 10MB。
356
+ * @supported weapp
357
+ * @example
358
+ * ```tsx
359
+ * Taro.batchGetStorage({
360
+ * keyList: ['key']
361
+ * success(res) {
362
+ * console.log(res)
363
+ * }
364
+ * })
365
+ * ```
366
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/storage/wx.batchGetStorage.html
367
+ */
368
+ batchSetStorage(option: batchSetStorage.Option): Promise<TaroGeneral.CallbackResult>
369
+
370
+ /** 从本地缓存中同步批量获取指定 key 的内容。
371
+ * @supported weapp
372
+ * @example
373
+ * ```tsx
374
+ * try {
375
+ * var valueList = Taro.batchGetStorageSync(['key'])
376
+ * if (valueList) {
377
+ * // Do something with return value
378
+ * }
379
+ * } catch (e) {
380
+ * // Do something when catch error
381
+ * }
382
+ * ```
383
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/storage/wx.batchGetStorageSync.html
384
+ */
385
+ batchGetStorageSync<T = any>(
386
+ /** 本地缓存中指定的 key 数组 */
387
+ keyList: string[]
388
+ ): T[]
389
+
390
+ /** 从本地缓存中异步批量获取指定 key 的内容。
391
+ * @supported weapp
392
+ * @example
393
+ * ```tsx
394
+ * Taro.batchGetStorage({
395
+ * keyList: ['key'],
396
+ * success(res) {
397
+ * console.log(res)
398
+ * }
399
+ * })
400
+ * ```
401
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/storage/wx.batchGetStorage.html
402
+ */
403
+ batchGetStorage(option: batchGetStorage.Option): Promise<TaroGeneral.CallbackResult>
289
404
  }
290
405
  }