@spcsn/taro 0.1.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.
- package/README.md +12 -0
- package/dist/index.js +147 -0
- package/dist/index.js.map +1 -0
- package/index.js +9 -0
- package/package.json +86 -0
- package/types/api/ad/index.d.ts +197 -0
- package/types/api/ai/face.d.ts +133 -0
- package/types/api/ai/inference.d.ts +129 -0
- package/types/api/ai/visionkit.d.ts +874 -0
- package/types/api/alipay/index.d.ts +69 -0
- package/types/api/base/crypto.d.ts +104 -0
- package/types/api/base/debug.d.ts +329 -0
- package/types/api/base/env.d.ts +19 -0
- package/types/api/base/index.d.ts +102 -0
- package/types/api/base/performance.d.ts +258 -0
- package/types/api/base/system.d.ts +742 -0
- package/types/api/base/update.d.ts +130 -0
- package/types/api/base/weapp/app-event.d.ts +265 -0
- package/types/api/base/weapp/life-cycle.d.ts +155 -0
- package/types/api/canvas/index.d.ts +2162 -0
- package/types/api/cloud/index.d.ts +2622 -0
- package/types/api/data-analysis/index.d.ts +122 -0
- package/types/api/device/accelerometer.d.ts +102 -0
- package/types/api/device/accessibility.d.ts +26 -0
- package/types/api/device/battery.d.ts +46 -0
- package/types/api/device/bluetooth-ble.d.ts +601 -0
- package/types/api/device/bluetooth-peripheral.d.ts +430 -0
- package/types/api/device/bluetooth.d.ts +463 -0
- package/types/api/device/calendar.d.ts +98 -0
- package/types/api/device/clipboard.d.ts +81 -0
- package/types/api/device/compass.d.ts +105 -0
- package/types/api/device/contact.d.ts +110 -0
- package/types/api/device/gyroscope.d.ts +85 -0
- package/types/api/device/iBeacon.d.ts +168 -0
- package/types/api/device/keyboard.d.ts +97 -0
- package/types/api/device/memory.d.ts +52 -0
- package/types/api/device/motion.d.ts +88 -0
- package/types/api/device/network.d.ts +172 -0
- package/types/api/device/nfc.d.ts +1238 -0
- package/types/api/device/phone.d.ts +30 -0
- package/types/api/device/scan.d.ts +111 -0
- package/types/api/device/screen.d.ts +217 -0
- package/types/api/device/sms.d.ts +26 -0
- package/types/api/device/vibrate.d.ts +51 -0
- package/types/api/device/wifi.d.ts +301 -0
- package/types/api/ext/index.d.ts +64 -0
- package/types/api/files/index.d.ts +1472 -0
- package/types/api/framework/index.d.ts +51 -0
- package/types/api/location/index.d.ts +517 -0
- package/types/api/media/audio.d.ts +1013 -0
- package/types/api/media/background-audio.d.ts +291 -0
- package/types/api/media/camera.d.ts +207 -0
- package/types/api/media/editor.d.ts +239 -0
- package/types/api/media/image.d.ts +469 -0
- package/types/api/media/live.d.ts +461 -0
- package/types/api/media/map.d.ts +638 -0
- package/types/api/media/media-recorder.d.ts +117 -0
- package/types/api/media/recorder.d.ts +317 -0
- package/types/api/media/video-decoder.d.ts +117 -0
- package/types/api/media/video-processing.d.ts +84 -0
- package/types/api/media/video.d.ts +527 -0
- package/types/api/media/voip.d.ts +393 -0
- package/types/api/navigate/index.d.ts +327 -0
- package/types/api/network/download.d.ts +173 -0
- package/types/api/network/mdns.d.ts +191 -0
- package/types/api/network/request.d.ts +480 -0
- package/types/api/network/tcp.d.ts +181 -0
- package/types/api/network/udp.d.ts +218 -0
- package/types/api/network/upload.d.ts +201 -0
- package/types/api/network/websocket.d.ts +383 -0
- package/types/api/open-api/account.d.ts +51 -0
- package/types/api/open-api/address.d.ts +68 -0
- package/types/api/open-api/authorize.d.ts +80 -0
- package/types/api/open-api/card.d.ts +110 -0
- package/types/api/open-api/channels.d.ts +225 -0
- package/types/api/open-api/customer-service.d.ts +45 -0
- package/types/api/open-api/device-voip.d.ts +103 -0
- package/types/api/open-api/facial.d.ts +98 -0
- package/types/api/open-api/favorites.d.ts +101 -0
- package/types/api/open-api/group.d.ts +59 -0
- package/types/api/open-api/invoice.d.ts +87 -0
- package/types/api/open-api/license-plate.d.ts +27 -0
- package/types/api/open-api/login.d.ts +115 -0
- package/types/api/open-api/my-miniprogram.d.ts +28 -0
- package/types/api/open-api/privacy.d.ts +107 -0
- package/types/api/open-api/redpackage.d.ts +24 -0
- package/types/api/open-api/settings.d.ts +174 -0
- package/types/api/open-api/soter.d.ts +184 -0
- package/types/api/open-api/sticker.d.ts +83 -0
- package/types/api/open-api/subscribe-message.d.ts +305 -0
- package/types/api/open-api/user-info.d.ts +182 -0
- package/types/api/open-api/werun.d.ts +101 -0
- package/types/api/payment/index.d.ts +119 -0
- package/types/api/qq/index.d.ts +354 -0
- package/types/api/route/index.d.ts +324 -0
- package/types/api/share/index.d.ts +354 -0
- package/types/api/skyline/index.d.ts +345 -0
- package/types/api/storage/background-fetch.d.ts +131 -0
- package/types/api/storage/cache-manager.d.ts +249 -0
- package/types/api/storage/index.d.ts +405 -0
- package/types/api/swan/bookshelf.d.ts +307 -0
- package/types/api/swan/download-package.d.ts +80 -0
- package/types/api/swan/index.d.ts +251 -0
- package/types/api/swan/pay.d.ts +139 -0
- package/types/api/taro.extend.d.ts +233 -0
- package/types/api/taro.hooks.d.ts +148 -0
- package/types/api/ui/animation.d.ts +427 -0
- package/types/api/ui/background.d.ts +69 -0
- package/types/api/ui/custom-component.d.ts +23 -0
- package/types/api/ui/fonts.d.ts +77 -0
- package/types/api/ui/interaction.d.ts +281 -0
- package/types/api/ui/menu.d.ts +29 -0
- package/types/api/ui/navigation-bar.d.ts +130 -0
- package/types/api/ui/pull-down-refresh.d.ts +50 -0
- package/types/api/ui/scroll.d.ts +114 -0
- package/types/api/ui/sticky.d.ts +32 -0
- package/types/api/ui/tab-bar.d.ts +196 -0
- package/types/api/ui/window.d.ts +71 -0
- package/types/api/worker/index.d.ts +83 -0
- package/types/api/wxml/index.d.ts +540 -0
- package/types/compile/compiler.d.ts +32 -0
- package/types/compile/config/h5.d.ts +134 -0
- package/types/compile/config/harmony.d.ts +118 -0
- package/types/compile/config/index.d.ts +8 -0
- package/types/compile/config/manifest.d.ts +155 -0
- package/types/compile/config/mini.d.ts +118 -0
- package/types/compile/config/plugin.d.ts +34 -0
- package/types/compile/config/project.d.ts +338 -0
- package/types/compile/config/rn.d.ts +85 -0
- package/types/compile/config/util.d.ts +179 -0
- package/types/compile/hooks.d.ts +13 -0
- package/types/compile/index.d.ts +11 -0
- package/types/compile/viteCompilerContext.d.ts +167 -0
- package/types/global.d.ts +428 -0
- package/types/index.d.ts +190 -0
- package/types/taro.api.d.ts +130 -0
- package/types/taro.component.d.ts +168 -0
- package/types/taro.config.d.ts +712 -0
- package/types/taro.lifecycle.d.ts +220 -0
- package/types/taro.runtime.d.ts +9 -0
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
import Taro from '../../index'
|
|
2
|
+
|
|
3
|
+
declare module '../../index' {
|
|
4
|
+
interface CacheManager {
|
|
5
|
+
/** 当前缓存模式 */
|
|
6
|
+
mode: keyof CacheManager.Mode
|
|
7
|
+
/** 全局 origin */
|
|
8
|
+
origin: string
|
|
9
|
+
/** 全局缓存有效时间 */
|
|
10
|
+
maxAge: number
|
|
11
|
+
/** 当前缓存管理器状态 */
|
|
12
|
+
state: keyof CacheManager.State
|
|
13
|
+
/** 添加规则
|
|
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
|
+
* ```
|
|
41
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/storage/cachemanager/CacheManager.addRule.html
|
|
42
|
+
*/
|
|
43
|
+
addRule(option: CacheManager.AddRuleOption): string
|
|
44
|
+
/** 批量添加规则
|
|
45
|
+
* @supported weapp
|
|
46
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/storage/cachemanager/CacheManager.addRules.html
|
|
47
|
+
*/
|
|
48
|
+
addRules(option: CacheManager.AddRulesOption): string[]
|
|
49
|
+
/** 清空所有缓存
|
|
50
|
+
* @supported weapp
|
|
51
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/storage/cachemanager/CacheManager.clearCaches.html
|
|
52
|
+
*/
|
|
53
|
+
clearCaches(): void
|
|
54
|
+
/** 清空所有规则,同时会删除对应规则下所有缓存
|
|
55
|
+
* @supported weapp
|
|
56
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/storage/cachemanager/CacheManager.clearRules.html
|
|
57
|
+
*/
|
|
58
|
+
clearRules(): void
|
|
59
|
+
/** 删除缓存
|
|
60
|
+
* @supported weapp
|
|
61
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/storage/cachemanager/CacheManager.deleteCache.html
|
|
62
|
+
*/
|
|
63
|
+
deleteCache(
|
|
64
|
+
/** 缓存 id */
|
|
65
|
+
id: string
|
|
66
|
+
): void
|
|
67
|
+
/** 批量删除缓存
|
|
68
|
+
* @supported weapp
|
|
69
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/storage/cachemanager/CacheManager.deleteCaches.html
|
|
70
|
+
*/
|
|
71
|
+
deleteCaches(
|
|
72
|
+
/** 缓存 id 列表 */
|
|
73
|
+
ids: string[]
|
|
74
|
+
): void
|
|
75
|
+
/** 删除规则,同时会删除对应规则下所有缓存
|
|
76
|
+
* @supported weapp
|
|
77
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/storage/cachemanager/CacheManager.deleteRule.html
|
|
78
|
+
*/
|
|
79
|
+
deleteRule(
|
|
80
|
+
/** 规则 id */
|
|
81
|
+
id: string
|
|
82
|
+
): void
|
|
83
|
+
/** 批量删除规则,同时会删除对应规则下所有缓存
|
|
84
|
+
* @supported weapp
|
|
85
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/storage/cachemanager/CacheManager.deleteRules.html
|
|
86
|
+
*/
|
|
87
|
+
deleteRules(
|
|
88
|
+
/** 规则 id 列表 */
|
|
89
|
+
ids: string[]
|
|
90
|
+
): void
|
|
91
|
+
/** 匹配命中的缓存规则,一般需要和 request 事件搭配使用
|
|
92
|
+
* @supported weapp
|
|
93
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/storage/cachemanager/CacheManager.match.html
|
|
94
|
+
*/
|
|
95
|
+
match(option: CacheManager.MatchOption): CacheManager.MatchResult
|
|
96
|
+
/** 取消事件监听
|
|
97
|
+
* @supported weapp
|
|
98
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/storage/cachemanager/CacheManager.off.html
|
|
99
|
+
*/
|
|
100
|
+
off(
|
|
101
|
+
/** 事件名称 */
|
|
102
|
+
eventName: string,
|
|
103
|
+
/** 事件监听函数 */
|
|
104
|
+
handler: TaroGeneral.EventCallback
|
|
105
|
+
): void
|
|
106
|
+
/** 监听事件
|
|
107
|
+
* @supported weapp
|
|
108
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/storage/cachemanager/CacheManager.on.html
|
|
109
|
+
*/
|
|
110
|
+
on(
|
|
111
|
+
/** 事件名称 */
|
|
112
|
+
eventName: keyof CacheManager.OnEventName,
|
|
113
|
+
/** 事件监听函数 */
|
|
114
|
+
handler: TaroGeneral.EventCallback
|
|
115
|
+
): void
|
|
116
|
+
/** 开启缓存,仅在 mode 为 none 时生效,调用后缓存管理器的 state 会置为 1
|
|
117
|
+
* @supported weapp
|
|
118
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/storage/cachemanager/CacheManager.start.html
|
|
119
|
+
*/
|
|
120
|
+
start(): void
|
|
121
|
+
/** 关闭缓存,仅在 mode 为 none 时生效,调用后缓存管理器的 state 会置为 0
|
|
122
|
+
* @supported weapp
|
|
123
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/storage/cachemanager/CacheManager.stop.html
|
|
124
|
+
*/
|
|
125
|
+
stop(): void
|
|
126
|
+
}
|
|
127
|
+
|
|
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
|
+
}
|
|
145
|
+
interface DataSchema {
|
|
146
|
+
/** 需要匹配的 data 对象的参数类型
|
|
147
|
+
* string、number、boolean、null、object、any(表示任意类型),
|
|
148
|
+
* 同时支持数组模式(数组模式则在类型后面加 [],如 string[] 表示字符串数组)
|
|
149
|
+
*/
|
|
150
|
+
type: string
|
|
151
|
+
/** 需要匹配的 data 对象的参数值
|
|
152
|
+
* 当 type 为基本类型时,可以用 string/regexp 来匹配固定的值,
|
|
153
|
+
* 也可以通过 function 来确定值是否匹配,
|
|
154
|
+
* 如果传入的 type 是 object,那么表示需要嵌套匹配值是否正确,可以传入 Array
|
|
155
|
+
*/
|
|
156
|
+
value?: string | RegExp | Function | DataRule[]
|
|
157
|
+
}
|
|
158
|
+
interface DataRule {
|
|
159
|
+
/** 需要匹配的参数名 */
|
|
160
|
+
name: string
|
|
161
|
+
schema: DataSchema | DataSchema[]
|
|
162
|
+
}
|
|
163
|
+
interface RuleObject {
|
|
164
|
+
/** 规则 id,如果不填则会由基础库生成 */
|
|
165
|
+
id: string
|
|
166
|
+
/** 请求方法,可选值 GET/POST/PATCH/PUT/DELETE,如果为空则表示前面提到的所有方法都能被匹配到 */
|
|
167
|
+
method: string
|
|
168
|
+
/** uri 匹配规则,可参考规则字符串写法和正则写法 */
|
|
169
|
+
url: any
|
|
170
|
+
/**
|
|
171
|
+
* 缓存有效时间,单位为 ms,不填则默认取缓存管理器全局的缓存有效时间
|
|
172
|
+
* @default 7 * 24 * 60 * 60 * 1000
|
|
173
|
+
*/
|
|
174
|
+
maxAge: number
|
|
175
|
+
/**
|
|
176
|
+
* 匹配请求参数
|
|
177
|
+
*/
|
|
178
|
+
dataSchema: DataRule[]
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
type Rule = string | RegExp | RuleObject
|
|
182
|
+
|
|
183
|
+
interface AddRuleOption {
|
|
184
|
+
/** 规则 */
|
|
185
|
+
rule: Rule
|
|
186
|
+
}
|
|
187
|
+
interface AddRulesOption {
|
|
188
|
+
/** 规则列表 */
|
|
189
|
+
rules: Rule[]
|
|
190
|
+
}
|
|
191
|
+
interface MatchOption {
|
|
192
|
+
/** request 事件对象 */
|
|
193
|
+
evt: any
|
|
194
|
+
}
|
|
195
|
+
interface MatchResult {
|
|
196
|
+
/** 命中的规则id */
|
|
197
|
+
ruleId: string
|
|
198
|
+
/** 缓存id */
|
|
199
|
+
cacheId: string
|
|
200
|
+
/** 缓存内容,会带有 fromCache 标记,方便开发者区分内容是否来自缓存 */
|
|
201
|
+
data: any
|
|
202
|
+
/** 缓存创建时间 */
|
|
203
|
+
createTime: number
|
|
204
|
+
/** 缓存有效时间 */
|
|
205
|
+
maxAge: number
|
|
206
|
+
}
|
|
207
|
+
interface OnEventName {
|
|
208
|
+
/** 发生 wx.request 请求,只在缓存管理器开启阶段会触发 */
|
|
209
|
+
request
|
|
210
|
+
/** 进入弱网/离线状态 */
|
|
211
|
+
enterWeakNetwork
|
|
212
|
+
/** 离开弱网/离线状态 */
|
|
213
|
+
exitWeakNetwork
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
namespace createCacheManager {
|
|
218
|
+
interface Mode {
|
|
219
|
+
/** 弱网/离线使用缓存返回 */
|
|
220
|
+
weakNetwork
|
|
221
|
+
/** 总是使用缓存返回 */
|
|
222
|
+
always
|
|
223
|
+
/** 不开启,后续可手动开启/停止使用缓存返回 */
|
|
224
|
+
none
|
|
225
|
+
}
|
|
226
|
+
interface Extra {
|
|
227
|
+
/** 需要缓存的 wx api 接口,不传则表示支持缓存的接口全都做缓存处理。返回的如果是缓存数据,开发者可通过 fromCache 标记区分 */
|
|
228
|
+
apiList?: string[]
|
|
229
|
+
}
|
|
230
|
+
interface Option {
|
|
231
|
+
/** 全局 origin */
|
|
232
|
+
origin?: string
|
|
233
|
+
/** 缓存模式 */
|
|
234
|
+
mode?: keyof Mode
|
|
235
|
+
/** 全局缓存有效时间,单位为毫秒,默认为 7 天,最长不超过 30 天 */
|
|
236
|
+
maxAge?: number
|
|
237
|
+
/** 额外的缓存处理 */
|
|
238
|
+
extra?: Extra
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
interface TaroStatic {
|
|
243
|
+
/** 创建缓存管理器
|
|
244
|
+
* @supported weapp
|
|
245
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/storage/cachemanager/wx.createCacheManager.html
|
|
246
|
+
*/
|
|
247
|
+
createCacheManager(option: createCacheManager.Option): CacheManager
|
|
248
|
+
}
|
|
249
|
+
}
|
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
import Taro from '../../index'
|
|
2
|
+
|
|
3
|
+
declare module '../../index' {
|
|
4
|
+
/** @ignore */
|
|
5
|
+
type TypedArray =
|
|
6
|
+
| Int8Array
|
|
7
|
+
| Uint8Array
|
|
8
|
+
| Uint8ClampedArray
|
|
9
|
+
| Int16Array
|
|
10
|
+
| Uint16Array
|
|
11
|
+
| Int32Array
|
|
12
|
+
| Uint32Array
|
|
13
|
+
| Float32Array
|
|
14
|
+
| Float64Array
|
|
15
|
+
|
|
16
|
+
namespace setStorage {
|
|
17
|
+
interface Option {
|
|
18
|
+
/** 需要存储的内容。只支持原生类型、Date、及能够通过`JSON.stringify`序列化的对象。 */
|
|
19
|
+
data: any
|
|
20
|
+
/** 本地缓存中指定的 key */
|
|
21
|
+
key: string
|
|
22
|
+
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
|
|
23
|
+
complete?: (res: TaroGeneral.CallbackResult) => void
|
|
24
|
+
/** 接口调用失败的回调函数 */
|
|
25
|
+
fail?: (res: TaroGeneral.CallbackResult) => void
|
|
26
|
+
/** 接口调用成功的回调函数 */
|
|
27
|
+
success?: (res: TaroGeneral.CallbackResult) => void
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
namespace removeStorage {
|
|
32
|
+
interface Option {
|
|
33
|
+
/** 本地缓存中指定的 key */
|
|
34
|
+
key: string
|
|
35
|
+
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
|
|
36
|
+
complete?: (res: TaroGeneral.CallbackResult) => void
|
|
37
|
+
/** 接口调用失败的回调函数 */
|
|
38
|
+
fail?: (res: TaroGeneral.CallbackResult) => void
|
|
39
|
+
/** 接口调用成功的回调函数 */
|
|
40
|
+
success?: (res: TaroGeneral.CallbackResult) => void
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
namespace getStorageInfoSync {
|
|
45
|
+
interface Option {
|
|
46
|
+
/** 当前占用的空间大小, 单位 KB */
|
|
47
|
+
currentSize: number
|
|
48
|
+
/** 当前 storage 中所有的 key */
|
|
49
|
+
keys: string[]
|
|
50
|
+
/** 限制的空间大小,单位 KB */
|
|
51
|
+
limitSize: number
|
|
52
|
+
/** 是否执行成功
|
|
53
|
+
* @supported alipay
|
|
54
|
+
*/
|
|
55
|
+
success?: boolean
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
namespace getStorageInfo {
|
|
60
|
+
interface Option {
|
|
61
|
+
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
|
|
62
|
+
complete?: (res: TaroGeneral.CallbackResult) => void
|
|
63
|
+
/** 接口调用失败的回调函数 */
|
|
64
|
+
fail?: (res: TaroGeneral.CallbackResult) => void
|
|
65
|
+
/** 接口调用成功的回调函数 */
|
|
66
|
+
success?: (option: SuccessCallbackOption) => void
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
interface SuccessCallbackOption {
|
|
70
|
+
/** 当前占用的空间大小, 单位 KB */
|
|
71
|
+
currentSize: number
|
|
72
|
+
/** 当前 storage 中所有的 key */
|
|
73
|
+
keys: string[]
|
|
74
|
+
/** 限制的空间大小,单位 KB */
|
|
75
|
+
limitSize: number
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
namespace getStorage {
|
|
80
|
+
interface Option<T> {
|
|
81
|
+
/** 本地缓存中指定的 key */
|
|
82
|
+
key: string
|
|
83
|
+
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
|
|
84
|
+
complete?: (res: TaroGeneral.CallbackResult) => void
|
|
85
|
+
/** 接口调用失败的回调函数 */
|
|
86
|
+
fail?: (res: TaroGeneral.CallbackResult) => void
|
|
87
|
+
/** 接口调用成功的回调函数 */
|
|
88
|
+
success?: (result: SuccessCallbackResult<T>) => void
|
|
89
|
+
}
|
|
90
|
+
interface SuccessCallbackResult<T> extends TaroGeneral.CallbackResult {
|
|
91
|
+
/** key对应的内容 */
|
|
92
|
+
data: T
|
|
93
|
+
/** 调用结果 */
|
|
94
|
+
errMsg: string
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
namespace clearStorage {
|
|
99
|
+
interface Option {
|
|
100
|
+
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
|
|
101
|
+
complete?: (res: TaroGeneral.CallbackResult) => void
|
|
102
|
+
/** 接口调用失败的回调函数 */
|
|
103
|
+
fail?: (res: TaroGeneral.CallbackResult) => void
|
|
104
|
+
/** 接口调用成功的回调函数 */
|
|
105
|
+
success?: (res: TaroGeneral.CallbackResult) => void
|
|
106
|
+
}
|
|
107
|
+
}
|
|
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
|
+
|
|
154
|
+
interface TaroStatic {
|
|
155
|
+
/** Taro.setStorage 的同步版本
|
|
156
|
+
* @supported weapp, alipay, swan, jd, qq, tt, h5, harmony_hybrid
|
|
157
|
+
* @example
|
|
158
|
+
* ```tsx
|
|
159
|
+
* Taro.setStorage({
|
|
160
|
+
* key:"key",
|
|
161
|
+
* data:"value"
|
|
162
|
+
* })
|
|
163
|
+
* ```
|
|
164
|
+
* @example
|
|
165
|
+
* ```tsx
|
|
166
|
+
* try {
|
|
167
|
+
* Taro.setStorageSync('key', 'value')
|
|
168
|
+
* } catch (e) { }
|
|
169
|
+
* ```
|
|
170
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/storage/wx.setStorageSync.html
|
|
171
|
+
*/
|
|
172
|
+
setStorageSync(
|
|
173
|
+
/** 本地缓存中指定的 key */
|
|
174
|
+
key: string,
|
|
175
|
+
/** 需要存储的内容。只支持原生类型、Date、及能够通过`JSON.stringify`序列化的对象。 */
|
|
176
|
+
data: any,
|
|
177
|
+
): void
|
|
178
|
+
|
|
179
|
+
/** 将数据存储在本地缓存中指定的 key 中。会覆盖掉原来该 key 对应的内容。除非用户主动删除或因存储空间原因被系统清理,否则数据都一直可用。单个 key 允许存储的最大数据长度为 1MB,所有数据存储上限为 10MB。
|
|
180
|
+
* @supported weapp, alipay, swan, jd, qq, tt, h5, rn, harmony, harmony_hybrid
|
|
181
|
+
* @example
|
|
182
|
+
* ```tsx
|
|
183
|
+
* Taro.setStorage({
|
|
184
|
+
* key:"key",
|
|
185
|
+
* data:"value"
|
|
186
|
+
* })
|
|
187
|
+
* ```
|
|
188
|
+
* ```tsx
|
|
189
|
+
* try {
|
|
190
|
+
* Taro.setStorageSync('key', 'value')
|
|
191
|
+
* } catch (e) { }
|
|
192
|
+
* ```
|
|
193
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/storage/wx.setStorage.html
|
|
194
|
+
*/
|
|
195
|
+
setStorage(option: setStorage.Option): Promise<TaroGeneral.CallbackResult>
|
|
196
|
+
|
|
197
|
+
/** 根据 URL 销毁存在内存中的数据
|
|
198
|
+
* @supported weapp
|
|
199
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/storage/wx.revokeBufferURL.html
|
|
200
|
+
*/
|
|
201
|
+
revokeBufferURL(
|
|
202
|
+
/** 需要销毁的二进制数据 URL */
|
|
203
|
+
url: string
|
|
204
|
+
): void
|
|
205
|
+
|
|
206
|
+
/** Taro.removeStorage 的同步版本
|
|
207
|
+
* @supported weapp, alipay, swan, jd, qq, tt, h5, harmony_hybrid
|
|
208
|
+
* @example
|
|
209
|
+
* ```tsx
|
|
210
|
+
* try {
|
|
211
|
+
* Taro.removeStorageSync('key')
|
|
212
|
+
* } catch (e) {
|
|
213
|
+
* // Do something when catch error
|
|
214
|
+
* }
|
|
215
|
+
* ```
|
|
216
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/storage/wx.removeStorageSync.html
|
|
217
|
+
*/
|
|
218
|
+
removeStorageSync(
|
|
219
|
+
/** 本地缓存中指定的 key */
|
|
220
|
+
key: string,
|
|
221
|
+
): void
|
|
222
|
+
|
|
223
|
+
/** 从本地缓存中移除指定 key
|
|
224
|
+
* @supported weapp, alipay, swan, jd, qq, tt, h5, rn, harmony, harmony_hybrid
|
|
225
|
+
* @example
|
|
226
|
+
* ```tsx
|
|
227
|
+
* Taro.removeStorage({
|
|
228
|
+
* key: 'key',
|
|
229
|
+
* success: function (res) {
|
|
230
|
+
* console.log(res)
|
|
231
|
+
* }
|
|
232
|
+
* })
|
|
233
|
+
* ```
|
|
234
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/storage/wx.removeStorage.html
|
|
235
|
+
*/
|
|
236
|
+
removeStorage(option: removeStorage.Option): Promise<TaroGeneral.CallbackResult>
|
|
237
|
+
|
|
238
|
+
/** Taro.getStorage 的同步版本
|
|
239
|
+
* @supported weapp, alipay, swan, jd, qq, tt, h5, harmony_hybrid
|
|
240
|
+
* @example
|
|
241
|
+
* ```tsx
|
|
242
|
+
* try {
|
|
243
|
+
* var value = Taro.getStorageSync('key')
|
|
244
|
+
* if (value) {
|
|
245
|
+
* // Do something with return value
|
|
246
|
+
* }
|
|
247
|
+
* } catch (e) {
|
|
248
|
+
* // Do something when catch error
|
|
249
|
+
* }
|
|
250
|
+
* ```
|
|
251
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/storage/wx.getStorageSync.html
|
|
252
|
+
*/
|
|
253
|
+
getStorageSync<T = any>(
|
|
254
|
+
/** 本地缓存中指定的 key */
|
|
255
|
+
key: string,
|
|
256
|
+
): T
|
|
257
|
+
|
|
258
|
+
/** Taro.getStorageInfo 的同步版本
|
|
259
|
+
* @supported weapp, alipay, swan, jd, qq, tt, h5, harmony_hybrid
|
|
260
|
+
* @example
|
|
261
|
+
* ```tsx
|
|
262
|
+
* try {
|
|
263
|
+
* const res = Taro.getStorageInfoSync()
|
|
264
|
+
* console.log(res.keys)
|
|
265
|
+
* console.log(res.currentSize)
|
|
266
|
+
* console.log(res.limitSize)
|
|
267
|
+
* } catch (e) {
|
|
268
|
+
* // Do something when catch error
|
|
269
|
+
* }
|
|
270
|
+
* ```
|
|
271
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/storage/wx.getStorageInfoSync.html
|
|
272
|
+
*/
|
|
273
|
+
getStorageInfoSync(): getStorageInfoSync.Option
|
|
274
|
+
|
|
275
|
+
/** 异步获取当前storage的相关信息
|
|
276
|
+
* @supported weapp, alipay, swan, jd, qq, tt, h5, rn, harmony_hybrid
|
|
277
|
+
* @example
|
|
278
|
+
* ```tsx
|
|
279
|
+
* Taro.getStorageInfo({
|
|
280
|
+
* success: function (res) {
|
|
281
|
+
* console.log(res.keys)
|
|
282
|
+
* console.log(res.currentSize)
|
|
283
|
+
* console.log(res.limitSize)
|
|
284
|
+
* }
|
|
285
|
+
* })
|
|
286
|
+
* ```
|
|
287
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/storage/wx.getStorageInfo.html
|
|
288
|
+
*/
|
|
289
|
+
getStorageInfo(option?: getStorageInfo.Option): Promise<TaroGeneral.CallbackResult>
|
|
290
|
+
|
|
291
|
+
/** 从本地缓存中异步获取指定 key 的内容
|
|
292
|
+
* @supported weapp, alipay, swan, jd, qq, tt, h5, rn, harmony, harmony_hybrid
|
|
293
|
+
* @example
|
|
294
|
+
* ```tsx
|
|
295
|
+
* Taro.getStorage({
|
|
296
|
+
* key: 'key',
|
|
297
|
+
* success: function (res) {
|
|
298
|
+
* console.log(res.data)
|
|
299
|
+
* }
|
|
300
|
+
* })
|
|
301
|
+
* ```
|
|
302
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/storage/wx.getStorage.html
|
|
303
|
+
*/
|
|
304
|
+
getStorage<T = any>(option: getStorage.Option<T>): Promise<getStorage.SuccessCallbackResult<T>>
|
|
305
|
+
|
|
306
|
+
/** 根据传入的 buffer 创建一个唯一的 URL 存在内存中
|
|
307
|
+
* @supported weapp
|
|
308
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/storage/wx.createBufferURL.html
|
|
309
|
+
*/
|
|
310
|
+
createBufferURL(
|
|
311
|
+
/** 需要存入内存的二进制数据 */
|
|
312
|
+
buffer: ArrayBuffer | TypedArray
|
|
313
|
+
): string
|
|
314
|
+
|
|
315
|
+
/** Taro.clearStorage 的同步版本
|
|
316
|
+
* @supported weapp, alipay, swan, jd, qq, tt, h5, harmony_hybrid
|
|
317
|
+
* @example
|
|
318
|
+
* ```tsx
|
|
319
|
+
* try {
|
|
320
|
+
* Taro.clearStorageSync()
|
|
321
|
+
* } catch(e) {
|
|
322
|
+
* // Do something when catch error
|
|
323
|
+
* }
|
|
324
|
+
* ```
|
|
325
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/storage/wx.clearStorageSync.html
|
|
326
|
+
*/
|
|
327
|
+
clearStorageSync(): void
|
|
328
|
+
|
|
329
|
+
/** 清理本地数据缓存
|
|
330
|
+
* @supported weapp, alipay, swan, jd, qq, tt, h5, rn, harmony_hybrid
|
|
331
|
+
* @example
|
|
332
|
+
* ```tsx
|
|
333
|
+
* Taro.clearStorage()
|
|
334
|
+
* ```
|
|
335
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/storage/wx.clearStorage.html
|
|
336
|
+
*/
|
|
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>
|
|
404
|
+
}
|
|
405
|
+
}
|