@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.
Files changed (140) hide show
  1. package/README.md +12 -0
  2. package/dist/index.js +147 -0
  3. package/dist/index.js.map +1 -0
  4. package/index.js +9 -0
  5. package/package.json +86 -0
  6. package/types/api/ad/index.d.ts +197 -0
  7. package/types/api/ai/face.d.ts +133 -0
  8. package/types/api/ai/inference.d.ts +129 -0
  9. package/types/api/ai/visionkit.d.ts +874 -0
  10. package/types/api/alipay/index.d.ts +69 -0
  11. package/types/api/base/crypto.d.ts +104 -0
  12. package/types/api/base/debug.d.ts +329 -0
  13. package/types/api/base/env.d.ts +19 -0
  14. package/types/api/base/index.d.ts +102 -0
  15. package/types/api/base/performance.d.ts +258 -0
  16. package/types/api/base/system.d.ts +742 -0
  17. package/types/api/base/update.d.ts +130 -0
  18. package/types/api/base/weapp/app-event.d.ts +265 -0
  19. package/types/api/base/weapp/life-cycle.d.ts +155 -0
  20. package/types/api/canvas/index.d.ts +2162 -0
  21. package/types/api/cloud/index.d.ts +2622 -0
  22. package/types/api/data-analysis/index.d.ts +122 -0
  23. package/types/api/device/accelerometer.d.ts +102 -0
  24. package/types/api/device/accessibility.d.ts +26 -0
  25. package/types/api/device/battery.d.ts +46 -0
  26. package/types/api/device/bluetooth-ble.d.ts +601 -0
  27. package/types/api/device/bluetooth-peripheral.d.ts +430 -0
  28. package/types/api/device/bluetooth.d.ts +463 -0
  29. package/types/api/device/calendar.d.ts +98 -0
  30. package/types/api/device/clipboard.d.ts +81 -0
  31. package/types/api/device/compass.d.ts +105 -0
  32. package/types/api/device/contact.d.ts +110 -0
  33. package/types/api/device/gyroscope.d.ts +85 -0
  34. package/types/api/device/iBeacon.d.ts +168 -0
  35. package/types/api/device/keyboard.d.ts +97 -0
  36. package/types/api/device/memory.d.ts +52 -0
  37. package/types/api/device/motion.d.ts +88 -0
  38. package/types/api/device/network.d.ts +172 -0
  39. package/types/api/device/nfc.d.ts +1238 -0
  40. package/types/api/device/phone.d.ts +30 -0
  41. package/types/api/device/scan.d.ts +111 -0
  42. package/types/api/device/screen.d.ts +217 -0
  43. package/types/api/device/sms.d.ts +26 -0
  44. package/types/api/device/vibrate.d.ts +51 -0
  45. package/types/api/device/wifi.d.ts +301 -0
  46. package/types/api/ext/index.d.ts +64 -0
  47. package/types/api/files/index.d.ts +1472 -0
  48. package/types/api/framework/index.d.ts +51 -0
  49. package/types/api/location/index.d.ts +517 -0
  50. package/types/api/media/audio.d.ts +1013 -0
  51. package/types/api/media/background-audio.d.ts +291 -0
  52. package/types/api/media/camera.d.ts +207 -0
  53. package/types/api/media/editor.d.ts +239 -0
  54. package/types/api/media/image.d.ts +469 -0
  55. package/types/api/media/live.d.ts +461 -0
  56. package/types/api/media/map.d.ts +638 -0
  57. package/types/api/media/media-recorder.d.ts +117 -0
  58. package/types/api/media/recorder.d.ts +317 -0
  59. package/types/api/media/video-decoder.d.ts +117 -0
  60. package/types/api/media/video-processing.d.ts +84 -0
  61. package/types/api/media/video.d.ts +527 -0
  62. package/types/api/media/voip.d.ts +393 -0
  63. package/types/api/navigate/index.d.ts +327 -0
  64. package/types/api/network/download.d.ts +173 -0
  65. package/types/api/network/mdns.d.ts +191 -0
  66. package/types/api/network/request.d.ts +480 -0
  67. package/types/api/network/tcp.d.ts +181 -0
  68. package/types/api/network/udp.d.ts +218 -0
  69. package/types/api/network/upload.d.ts +201 -0
  70. package/types/api/network/websocket.d.ts +383 -0
  71. package/types/api/open-api/account.d.ts +51 -0
  72. package/types/api/open-api/address.d.ts +68 -0
  73. package/types/api/open-api/authorize.d.ts +80 -0
  74. package/types/api/open-api/card.d.ts +110 -0
  75. package/types/api/open-api/channels.d.ts +225 -0
  76. package/types/api/open-api/customer-service.d.ts +45 -0
  77. package/types/api/open-api/device-voip.d.ts +103 -0
  78. package/types/api/open-api/facial.d.ts +98 -0
  79. package/types/api/open-api/favorites.d.ts +101 -0
  80. package/types/api/open-api/group.d.ts +59 -0
  81. package/types/api/open-api/invoice.d.ts +87 -0
  82. package/types/api/open-api/license-plate.d.ts +27 -0
  83. package/types/api/open-api/login.d.ts +115 -0
  84. package/types/api/open-api/my-miniprogram.d.ts +28 -0
  85. package/types/api/open-api/privacy.d.ts +107 -0
  86. package/types/api/open-api/redpackage.d.ts +24 -0
  87. package/types/api/open-api/settings.d.ts +174 -0
  88. package/types/api/open-api/soter.d.ts +184 -0
  89. package/types/api/open-api/sticker.d.ts +83 -0
  90. package/types/api/open-api/subscribe-message.d.ts +305 -0
  91. package/types/api/open-api/user-info.d.ts +182 -0
  92. package/types/api/open-api/werun.d.ts +101 -0
  93. package/types/api/payment/index.d.ts +119 -0
  94. package/types/api/qq/index.d.ts +354 -0
  95. package/types/api/route/index.d.ts +324 -0
  96. package/types/api/share/index.d.ts +354 -0
  97. package/types/api/skyline/index.d.ts +345 -0
  98. package/types/api/storage/background-fetch.d.ts +131 -0
  99. package/types/api/storage/cache-manager.d.ts +249 -0
  100. package/types/api/storage/index.d.ts +405 -0
  101. package/types/api/swan/bookshelf.d.ts +307 -0
  102. package/types/api/swan/download-package.d.ts +80 -0
  103. package/types/api/swan/index.d.ts +251 -0
  104. package/types/api/swan/pay.d.ts +139 -0
  105. package/types/api/taro.extend.d.ts +233 -0
  106. package/types/api/taro.hooks.d.ts +148 -0
  107. package/types/api/ui/animation.d.ts +427 -0
  108. package/types/api/ui/background.d.ts +69 -0
  109. package/types/api/ui/custom-component.d.ts +23 -0
  110. package/types/api/ui/fonts.d.ts +77 -0
  111. package/types/api/ui/interaction.d.ts +281 -0
  112. package/types/api/ui/menu.d.ts +29 -0
  113. package/types/api/ui/navigation-bar.d.ts +130 -0
  114. package/types/api/ui/pull-down-refresh.d.ts +50 -0
  115. package/types/api/ui/scroll.d.ts +114 -0
  116. package/types/api/ui/sticky.d.ts +32 -0
  117. package/types/api/ui/tab-bar.d.ts +196 -0
  118. package/types/api/ui/window.d.ts +71 -0
  119. package/types/api/worker/index.d.ts +83 -0
  120. package/types/api/wxml/index.d.ts +540 -0
  121. package/types/compile/compiler.d.ts +32 -0
  122. package/types/compile/config/h5.d.ts +134 -0
  123. package/types/compile/config/harmony.d.ts +118 -0
  124. package/types/compile/config/index.d.ts +8 -0
  125. package/types/compile/config/manifest.d.ts +155 -0
  126. package/types/compile/config/mini.d.ts +118 -0
  127. package/types/compile/config/plugin.d.ts +34 -0
  128. package/types/compile/config/project.d.ts +338 -0
  129. package/types/compile/config/rn.d.ts +85 -0
  130. package/types/compile/config/util.d.ts +179 -0
  131. package/types/compile/hooks.d.ts +13 -0
  132. package/types/compile/index.d.ts +11 -0
  133. package/types/compile/viteCompilerContext.d.ts +167 -0
  134. package/types/global.d.ts +428 -0
  135. package/types/index.d.ts +190 -0
  136. package/types/taro.api.d.ts +130 -0
  137. package/types/taro.component.d.ts +168 -0
  138. package/types/taro.config.d.ts +712 -0
  139. package/types/taro.lifecycle.d.ts +220 -0
  140. package/types/taro.runtime.d.ts +9 -0
@@ -0,0 +1,480 @@
1
+ import Taro from '../../index'
2
+
3
+ declare module '../../index' {
4
+ namespace request {
5
+ interface Option<T = any, U extends string | TaroGeneral.IAnyObject | ArrayBuffer = any | any> {
6
+ /** 开发者服务器接口地址 */
7
+ url: string
8
+ /** 请求的参数 */
9
+ data?: U
10
+ /** 设置请求的 header,header 中不能设置 Referer。
11
+ *
12
+ * `content-type` 默认为 `application/json`
13
+ */
14
+ header?: TaroGeneral.IAnyObject
15
+ /** 超时时间,单位为毫秒
16
+ * @default 60000
17
+ * @supported weapp, h5, tt, alipay, rn
18
+ */
19
+ timeout?: number
20
+ /** HTTP 请求方法
21
+ * @default "GET"
22
+ */
23
+ method?: keyof Method
24
+ /** 返回的数据格式 */
25
+ dataType?: keyof DataType | string
26
+ /** 响应的数据类型 */
27
+ responseType?: keyof ResponseType
28
+ /**
29
+ * 使用高性能模式。从基础库 v3.5.0 开始在 Android 端默认开启,其他端暂不生效。该模式下有更优的网络性能表现。
30
+ * @default true
31
+ * */
32
+ useHighPerformanceMode?: boolean
33
+ /** 开启 http2
34
+ * @default false
35
+ * @supported weapp
36
+ */
37
+ enableHttp2?: boolean
38
+ /** 开启 quic
39
+ * @default false
40
+ * @supported weapp
41
+ */
42
+ enableQuic?: boolean
43
+ /** 开启 cache
44
+ * @default false
45
+ * @supported weapp, tt
46
+ */
47
+ enableCache?: boolean
48
+ /** 是否开启 HttpDNS 服务。如开启,需要同时填入 httpDNSServiceId 。 HttpDNS 用法详见 移动解析HttpDNS
49
+ * @default false
50
+ * @supported weapp
51
+ */
52
+ enableHttpDNS?: boolean
53
+ /** HttpDNS 服务商 Id。 HttpDNS 用法详见 移动解析HttpDNS
54
+ * @supported weapp
55
+ */
56
+ httpDNSServiceId?: string
57
+ /** 开启 transfer-encoding chunked。
58
+ * @default false
59
+ * @supported weapp
60
+ */
61
+ enableChunked?: boolean
62
+ /**
63
+ * wifi下使用移动网络发送请求
64
+ * @default false
65
+ * @supported weapp
66
+ */
67
+ forceCellularNetwork?: boolean
68
+ /**
69
+ * headers 中设置 cookie 字段是否生效。如果为 false,则 headers 中的 cookie 字段将被忽略,请求头中将包含服务端上一次返回的 cookie(如果有)。
70
+ * @default false
71
+ * @supported alipay 支付宝: 10.2.33+
72
+ */
73
+ enableCookie?: boolean
74
+ /**
75
+ * referer 策略,用于控制当前请求 header 对象中 referer 字段格式。该参数默认值可通过 app.json 中的配置进行修改。
76
+ * @default "querystring"
77
+ * @supported alipay 支付宝: 10.3.50+ APPX: 2.8.7 开发者工具: 3.5.1
78
+ * @see https://opendocs.alipay.com/mini/api/owycmh#referrerStrategy%20%E5%8F%82%E6%95%B0%E8%AF%B4%E6%98%8E
79
+ */
80
+ referrerStrategy?: keyof ReferrerStrategy
81
+ /** 接口调用成功的回调函数 */
82
+ success?: (result: SuccessCallbackResult<T>) => void
83
+ /** 接口调用失败的回调函数 */
84
+ fail?: (res: TaroGeneral.CallbackResult) => void
85
+ /** 接口调用结束的回调函数(调用成功、失败都会执行) */
86
+ complete?: (res: Partial<SuccessCallbackResult> & TaroGeneral.CallbackResult) => void
87
+ /** 设置是否使用 jsonp 方式获取数据
88
+ * @default false
89
+ * @supported h5
90
+ */
91
+ jsonp?: boolean | string
92
+ /** 设置 jsonp 请求 url 是否需要被缓存
93
+ * @supported h5
94
+ */
95
+ jsonpCache?: RequestCache
96
+ /** 设置是否允许跨域请求
97
+ * @default "same-origin"
98
+ * @supported h5
99
+ */
100
+ mode?: keyof CorsMode
101
+ /** 设置是否携带 Cookie
102
+ * @default "omit"
103
+ * @supported h5
104
+ */
105
+ credentials?: keyof Credentials
106
+ /** 设置缓存模式
107
+ * @default "default"
108
+ * @supported h5
109
+ */
110
+ cache?: keyof Cache
111
+ /** 设置请求重试次数
112
+ * @default 2
113
+ * @supported h5
114
+ * @h5 仅在 jsonp 模式下生效
115
+ */
116
+ retryTimes?: number
117
+ /** 设置请求的兜底接口
118
+ * @supported h5
119
+ * @h5 仅在 jsonp 模式下生效
120
+ */
121
+ backup?: string | string[]
122
+ /** 设置请求中止信号
123
+ * @supported h5
124
+ */
125
+ signal?: AbortSignal
126
+ /** 设置请求响应的数据校验函数,若返回 false,则请求兜底接口,若无兜底接口,则报请求失败
127
+ * @supported h5
128
+ * @h5 仅在 jsonp 模式下生效
129
+ */
130
+ dataCheck?(): boolean
131
+ /** 设置请求是否使用缓存
132
+ * @default false
133
+ * @supported h5
134
+ * @h5 仅在 jsonp 模式下生效
135
+ */
136
+ useStore?: boolean
137
+ /** 设置请求缓存校验的 key
138
+ * @supported h5
139
+ * @h5 仅在 jsonp 模式下生效
140
+ */
141
+ storeCheckKey?: string
142
+ /** 设置请求缓存签名
143
+ * @supported h5
144
+ * @h5 仅在 jsonp 模式下生效
145
+ */
146
+ storeSign?: string
147
+ /** 设置请求校验函数,一般不需要设置
148
+ * @supported h5
149
+ */
150
+ storeCheck?(): boolean
151
+ }
152
+
153
+ interface SuccessCallbackResult<T extends string | TaroGeneral.IAnyObject | ArrayBuffer = any | any>
154
+ extends TaroGeneral.CallbackResult {
155
+ /** 开发者服务器返回的数据 */
156
+ data: T
157
+ /** 开发者服务器返回的 HTTP Response Header */
158
+ header: TaroGeneral.IAnyObject
159
+ /** 开发者服务器返回的 HTTP 状态码 */
160
+ statusCode: number
161
+ /** 调用结果 */
162
+ errMsg: string
163
+ /** cookies */
164
+ cookies?: string[]
165
+ }
166
+
167
+ /** 返回的数据格式 */
168
+ interface DataType {
169
+ /**
170
+ * 返回的数据为 JSON,返回后会对返回的数据进行一次 JSON.parse
171
+ * 其他: 不对返回的内容进行 JSON.parse
172
+ */
173
+ json
174
+ /**
175
+ * 返回的数据为文本字符串
176
+ * @supported alipay
177
+ */
178
+ text
179
+ /**
180
+ * 返回的数据将转换为 base64 格式字符串
181
+ * @supported alipay
182
+ */
183
+ base64
184
+ /**
185
+ * 返回的数据将保持 ArrayBuffer 数据
186
+ * @supported alipay 支付宝: 10.1.70+
187
+ */
188
+ arraybuffer
189
+ }
190
+
191
+ /** HTTP 请求方法 */
192
+ interface Method {
193
+ /** HTTP 请求 OPTIONS */
194
+ OPTIONS
195
+ /** HTTP 请求 GET */
196
+ GET
197
+ /** HTTP 请求 HEAD */
198
+ HEAD
199
+ /** HTTP 请求 POST */
200
+ POST
201
+ /** HTTP 请求 PUT */
202
+ PUT
203
+ /** HTTP 请求 PATCH */
204
+ PATCH
205
+ /** HTTP 请求 DELETE */
206
+ DELETE
207
+ /** HTTP 请求 TRACE */
208
+ TRACE
209
+ /** HTTP 请求 CONNECT */
210
+ CONNECT
211
+ }
212
+
213
+ /** 响应的数据类型 */
214
+ interface ResponseType {
215
+ /** 响应的数据为文本 */
216
+ text
217
+ /** 响应的数据为 ArrayBuffer */
218
+ arraybuffer
219
+ }
220
+
221
+ /** 跨域策略 */
222
+ interface CorsMode {
223
+ /** 跨域请求将获取不透明的响应 */
224
+ 'no-cors'
225
+ /** 允许跨域请求 */
226
+ cors
227
+ /** 请求总是向当前的源发起的 */
228
+ 'same-origin'
229
+ }
230
+ /** 证书 */
231
+ interface Credentials {
232
+ /** 不论是不是跨域的请求,总是发送请求资源域在本地的 cookies、 HTTP Basic authentication 等验证信息 */
233
+ include
234
+ /** 只有当URL与响应脚本同源才发送 cookies、 HTTP Basic authentication 等验证信息 */
235
+ 'same-origin'
236
+ /** 从不发送cookies */
237
+ omit
238
+ }
239
+ /** 缓存策略 */
240
+ interface Cache {
241
+ /** 浏览器从HTTP缓存中寻找匹配的请求 */
242
+ default
243
+ /** 浏览器在其HTTP缓存中寻找匹配的请求 */
244
+ 'no-cache'
245
+ /** 浏览器直接从远程服务器获取资源,不查看缓存,然后使用下载的资源更新缓存 */
246
+ reload
247
+ /** 浏览器在其HTTP缓存中寻找匹配的请求 */
248
+ 'force-cache'
249
+ /** 浏览器在其HTTP缓存中寻找匹配的请求 */
250
+ 'only-if-cached'
251
+ }
252
+ /** referer 策略 */
253
+ interface ReferrerStrategy {
254
+ /**
255
+ * referer 值为 https://{appid}.hybrid.alipay-eco.com/{appid}/{version}/index.html
256
+ */
257
+ index
258
+ /**
259
+ * 保留 page(pages/xxx/yyy),referer 值为 https://{appid}.hybrid.alipay-eco.com/{appid}/{version}/index.html#{page}
260
+ */
261
+ page
262
+ /**
263
+ * 默认值。会将发起请求时所在页面的 URL 作为 referer 值,会保留 page(pages/xxx/yyy)和 querystring(x=1&y=2)并可能有框架添加的其他参数,referer 值为 https://{appid}.hybrid.alipay-eco.com/{appid}/{version}/index.html#{page}?{querysrtring}{框架其他参数}
264
+ */
265
+ querystring
266
+ }
267
+ }
268
+
269
+ /** 网络请求任务对象
270
+ * @supported weapp, h5, rn, alipay, swan, tt, qq, harmony_hybrid
271
+ * @example
272
+ * 回调函数(Callback)用法:
273
+ *
274
+ * ```tsx
275
+ * const requestTask = Taro.request({
276
+ * url: 'test.php', //仅为示例,并非真实的接口地址
277
+ * data: {
278
+ * x: '' ,
279
+ * y: ''
280
+ * },
281
+ * header: {
282
+ * 'content-type': 'application/json' // 默认值
283
+ * },
284
+ * success: function (res) {
285
+ * console.log(res.data)
286
+ * }
287
+ * })
288
+ * requestTask.abort()
289
+ * ```
290
+ * @example
291
+ * Promise 用法:
292
+ *
293
+ * ```tsx
294
+ * const requestTask = Taro.request({
295
+ * url: 'test.php', //仅为示例,并非真实的接口地址
296
+ * data: {
297
+ * x: '' ,
298
+ * y: ''
299
+ * },
300
+ * header: {
301
+ * 'content-type': 'application/json' // 默认值
302
+ * },
303
+ * success: function (res) {
304
+ * console.log(res.data)
305
+ * }
306
+ * })
307
+ * requestTask.then(res => {
308
+ * console.log(res.data)
309
+ * })
310
+ * requestTask.abort()
311
+ * ```
312
+ * @example
313
+ * async/await 用法:
314
+ *
315
+ * ```tsx
316
+ * const requestTask = Taro.request(params)
317
+ * const res = await requestTask
318
+ * requestTask.abort()
319
+ * ```
320
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/request/RequestTask.html
321
+ */
322
+ interface RequestTask<T> extends Promise<request.SuccessCallbackResult<T>> {
323
+ /** 中断请求任务
324
+ * @supported weapp, tt, harmony_hybrid
325
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/request/RequestTask.abort.html
326
+ */
327
+ abort(): void
328
+ /** 监听 HTTP Response Header 事件。会比请求完成事件更早
329
+ * @supported weapp, harmony_hybrid
330
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/request/RequestTask.onHeadersReceived.html
331
+ */
332
+ onHeadersReceived(
333
+ /** HTTP Response Header 事件的回调函数 */
334
+ callback: RequestTask.onHeadersReceived.Callback
335
+ ): void
336
+ /** 取消监听 HTTP Response Header 事件
337
+ * @supported weapp, harmony_hybrid
338
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/request/RequestTask.offHeadersReceived.html
339
+ */
340
+ offHeadersReceived(
341
+ /** HTTP Response Header 事件的回调函数 */
342
+ callback: RequestTask.onHeadersReceived.Callback
343
+ ): void
344
+ /** 监听 Transfer-Encoding Chunk Received 事件。当接收到新的chunk时触发。
345
+ * @supported weapp
346
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/request/RequestTask.onChunkReceived.html
347
+ */
348
+ onChunkReceived(
349
+ /** Transfer-Encoding Chunk Received 事件的回调函数 */
350
+ callback: RequestTask.onChunkReceived.Callback
351
+ ): void
352
+ /** 移除 Transfer-Encoding Chunk Received 事件的监听函数
353
+ * @supported weapp
354
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/request/RequestTask.offChunkReceived.html
355
+ */
356
+ offChunkReceived(
357
+ /** Transfer-Encoding Chunk Received 事件的回调函数 */
358
+ callback: RequestTask.onChunkReceived.Callback
359
+ ): void
360
+ }
361
+
362
+ namespace RequestTask {
363
+ namespace onHeadersReceived {
364
+ /** HTTP Response Header 事件的回调函数 */
365
+ type Callback = (result: CallbackResult) => void
366
+ interface CallbackResult {
367
+ /** 开发者服务器返回的 HTTP Response Header */
368
+ header: TaroGeneral.IAnyObject
369
+ }
370
+ }
371
+ namespace onChunkReceived {
372
+ /** Transfer-Encoding Chunk Received 事件的回调函数 */
373
+ type Callback = (result: CallbackResult) => void
374
+ /** 开发者服务器每次返回新 chunk 时的 Response */
375
+ interface CallbackResult {
376
+ /** 返回的chunk buffer */
377
+ data: ArrayBuffer
378
+ }
379
+ }
380
+ }
381
+
382
+ /** @ignore */
383
+ type interceptor = (chain: Chain) => any
384
+
385
+ /** @ignore */
386
+ interface Chain {
387
+ index: number
388
+ requestParams: RequestParams
389
+ interceptors: interceptor[]
390
+ proceed(requestParams: RequestParams): any
391
+ }
392
+
393
+ /** @ignore */
394
+ interface interceptors {
395
+ logInterceptor(chain: Chain): Promise<any>
396
+
397
+ timeoutInterceptor(chain: Chain): Promise<any>
398
+ }
399
+
400
+ interface TaroStatic {
401
+ /** 发起 HTTPS 网络请求。使用前请注意阅读[相关说明](https://developers.weixin.qq.com/miniprogram/dev/framework/ability/network.html)。
402
+ *
403
+ * **data 参数说明**
404
+ * 最终发送给服务器的数据是 String 类型,如果传入的 data 不是 String 类型,会被转换成 String 。转换规则如下:
405
+ * - 对于 `GET` 方法的数据,会将数据转换成 query string(`encodeURIComponent(k)=encodeURIComponent(v)&encodeURIComponent(k)=encodeURIComponent(v)...`)
406
+ * - 对于 `POST` 方法且 `header['content-type']` 为 `application/json` 的数据,会对数据进行 JSON 序列化
407
+ * - 对于 `POST` 方法且 `header['content-type']` 为 `application/x-www-form-urlencoded` 的数据,会将数据转换成 query string `(encodeURIComponent(k)=encodeURIComponent(v)&encodeURIComponent(k)=encodeURIComponent(v)...)`
408
+ * @supported weapp, h5, rn, alipay, swan, tt, qq, harmony, harmony_hybrid
409
+ * @example
410
+ * ```tsx
411
+ * Taro.request({
412
+ * url: 'test.php', //仅为示例,并非真实的接口地址
413
+ * data: {
414
+ * x: '',
415
+ * y: ''
416
+ * },
417
+ * header: {
418
+ * 'content-type': 'application/json' // 默认值
419
+ * },
420
+ * success: function (res) {
421
+ * console.log(res.data)
422
+ * }
423
+ * })
424
+ * ```
425
+ * @example
426
+ * async/await 用法:
427
+ *
428
+ * ```tsx
429
+ * const res = await Taro.request(params)
430
+ * ```
431
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/request/wx.request.html
432
+ */
433
+ request<T = any, U = any>(option: request.Option<T, U>): RequestTask<T>
434
+
435
+ /** 可以使用拦截器在请求发出前或发出后做一些额外操作。
436
+ *
437
+ * 在调用 `Taro.request` 发起请求之前,调用 `Taro.addInterceptor` 方法为请求添加拦截器,拦截器的调用顺序遵循洋葱模型。
438
+ * 拦截器是一个函数,接受 chain 对象作为参数。chain 对象中含有 **requestParmas** 属性,代表请求参数。拦截器内最后需要调用 `chain.proceed(requestParams)` 以调用下一个拦截器或发起请求。
439
+ *
440
+ * Taro 提供了两个内置拦截器 `logInterceptor` 与 `timeoutInterceptor`,分别用于打印请求的相关信息和在请求超时时抛出错误。
441
+ * @supported weapp, h5, alipay, swan, tt, qq
442
+ * @example
443
+ * ```tsx
444
+ * const interceptor = function (chain) {
445
+ * const requestParams = chain.requestParams
446
+ * const { method, data, url } = requestParams
447
+ *
448
+ * console.log(`http ${method || 'GET'} --> ${url} data: `, data)
449
+ *
450
+ * return chain.proceed(requestParams)
451
+ * .then(res => {
452
+ * console.log(`http <-- ${url} result:`, res)
453
+ * return res
454
+ * })
455
+ * }
456
+ * Taro.addInterceptor(interceptor)
457
+ * Taro.request({ url })
458
+ * ```
459
+ * @example
460
+ * ```tsx
461
+ * Taro.addInterceptor(Taro.interceptors.logInterceptor)
462
+ * Taro.addInterceptor(Taro.interceptors.timeoutInterceptor)
463
+ * Taro.request({ url })
464
+ * ```
465
+ * @since 1.2.16
466
+ */
467
+ addInterceptor(interceptor: interceptor): any
468
+
469
+ /** 清除所有拦截器
470
+ * @example
471
+ * ```tsx
472
+ * Taro.cleanInterceptors()
473
+ * ```
474
+ * @supported weapp, h5, alipay, swan, tt, qq
475
+ */
476
+ cleanInterceptors(): void
477
+
478
+ interceptors: interceptors
479
+ }
480
+ }
@@ -0,0 +1,181 @@
1
+ import Taro from '../../index'
2
+
3
+ declare module '../../index' {
4
+ /** 一个 TCP Socket 实例,默认使用 IPv4 协议
5
+ * @supported weapp
6
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/tcp/TCPSocket.html
7
+ */
8
+ interface TCPSocket {
9
+ /** 在给定的套接字上启动连接
10
+ * @supported weapp
11
+ * @example
12
+ * ```tsx
13
+ * const tcp = Taro.createTCPSocket()
14
+ * tcp.connect({ address: '192.168.193.2', port: 8848 })
15
+ * ```
16
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/tcp/TCPSocket.connect.html
17
+ */
18
+ connect(option: TCPSocket.connect.Option): void
19
+ /** 在 socket 上发送数据
20
+ * @supported weapp
21
+ * @example
22
+ * ```tsx
23
+ * const tcp = Taro.createTCPSocket()
24
+ * tcp.write('hello, how are you')
25
+ * ```
26
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/tcp/TCPSocket.write.html
27
+ */
28
+ write(
29
+ /** 要发送的数据 */
30
+ data: string | ArrayBuffer
31
+ ): void
32
+ /** 关闭连接
33
+ * @supported weapp
34
+ * @example
35
+ * ```tsx
36
+ * const tcp = Taro.createTCPSocket()
37
+ * tcp.close()
38
+ * ```
39
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/tcp/TCPSocket.close.html
40
+ */
41
+ close(): void
42
+ /** 监听关闭事件
43
+ * @supported weapp
44
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/tcp/TCPSocket.onClose.html
45
+ */
46
+ onClose(
47
+ /** 当一个 socket 完全关闭就发出该事件的回调函数 */
48
+ callback: TCPSocket.onClose.Callback,
49
+ ): void
50
+ /** 取消监听当一个 socket 完全关闭就发出该事件
51
+ * @supported weapp
52
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/tcp/TCPSocket.offClose.html
53
+ */
54
+ offClose(
55
+ /** 当一个 socket 完全关闭就发出该事件的回调函数 */
56
+ callback: TCPSocket.onClose.Callback,
57
+ ): void
58
+ /** 监听当一个 socket 连接成功建立的时候触发该事件
59
+ * @supported weapp
60
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/tcp/TCPSocket.onConnect.html
61
+ */
62
+ onConnect(
63
+ /** 当一个 socket 连接成功建立的时候触发该事件的回调函数 */
64
+ callback: TCPSocket.onConnect.Callback,
65
+ ): void
66
+ /** 取消监听当一个 socket 连接成功建立的时候触发该事件
67
+ * @supported weapp
68
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/tcp/TCPSocket.offConnect.html
69
+ */
70
+ offConnect(
71
+ /** 当一个 socket 连接成功建立的时候触发该事件的回调函数 */
72
+ callback: TCPSocket.onConnect.Callback,
73
+ ): void
74
+ /** 监听当错误发生时触发
75
+ * @supported weapp
76
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/tcp/TCPSocket.onError.html
77
+ */
78
+ onError(
79
+ /** 监听当错误发生时触发的回调函数 */
80
+ callback: TCPSocket.onError.Callback,
81
+ ): void
82
+ /** 取消监听当错误发生时触发
83
+ * @supported weapp
84
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/tcp/TCPSocket.offError.html
85
+ */
86
+ offError(
87
+ /** 监听当错误发生时触发的回调函数 */
88
+ callback: TCPSocket.onError.Callback,
89
+ ): void
90
+ /** 监听当接收到数据的时触发该事件
91
+ * @supported weapp
92
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/tcp/TCPSocket.onMessage.html
93
+ */
94
+ onMessage(
95
+ /** 当接收到数据的时触发该事件的回调函数 */
96
+ callback: TCPSocket.onMessage.Callback,
97
+ ): void
98
+ /** 取消监听当接收到数据的时触发该事件
99
+ * @supported weapp
100
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/tcp/TCPSocket.offMessage.html
101
+ */
102
+ offMessage(
103
+ /** 当接收到数据的时触发该事件的回调函数 */
104
+ callback: TCPSocket.onMessage.Callback,
105
+ ): void
106
+ }
107
+
108
+ namespace TCPSocket {
109
+ namespace connect {
110
+ interface Option {
111
+ /** 套接字要连接的地址 */
112
+ address: string
113
+ /** 套接字要连接的端口 */
114
+ port: number
115
+ }
116
+ }
117
+ namespace onClose {
118
+ /** 当一个 socket 完全关闭就发出该事件的回调函数 */
119
+ type Callback = (...args: unknown[]) => void
120
+ }
121
+ namespace onConnect {
122
+ /** 当一个 socket 连接成功建立的时候触发该事件的回调函数 */
123
+ type Callback = (...args: unknown[]) => void
124
+ }
125
+ namespace onError {
126
+ /** 监听当错误发生时触发的回调函数 */
127
+ type Callback = (result: CallbackResult) => void
128
+ interface CallbackResult extends TaroGeneral.CallbackResult {
129
+ /** 错误信息 */
130
+ errMsg: string
131
+ }
132
+ }
133
+ namespace onMessage {
134
+ /** 当接收到数据的时触发该事件的回调函数 */
135
+ type Callback = (result: CallbackResult) => void
136
+ interface CallbackResult extends TaroGeneral.CallbackResult {
137
+ /** 收到的消息 */
138
+ message: ArrayBuffer
139
+ /** 发送端地址信息 */
140
+ remoteInfo: RemoteInfo
141
+ /** 接收端地址信息 */
142
+ localInfo: LocalInfo
143
+ }
144
+ /** 发送端地址信息 */
145
+ interface RemoteInfo {
146
+ /** 发送消息的 socket 的地址 */
147
+ address: string
148
+ /** 使用的协议族,为 IPv4 或者 IPv6 */
149
+ family: string
150
+ /** 端口号 */
151
+ port: number
152
+ /** message 的大小,单位:字节 */
153
+ size: number
154
+ }
155
+ /** 接收端地址信息 */
156
+ interface LocalInfo {
157
+ /** 接收消息的 socket 的地址 */
158
+ address: string
159
+ /** 使用的协议族,为 IPv4 或者 IPv6 */
160
+ family: string
161
+ /** 端口号 */
162
+ port: number
163
+ }
164
+ }
165
+ }
166
+
167
+ interface TaroStatic {
168
+ /** 创建一个 TCP Socket 实例。使用前请注意阅读[相关说明](https://developers.weixin.qq.com/miniprogram/dev/framework/ability/network.html)。
169
+ *
170
+ * **连接限制**
171
+ *
172
+ * - 允许与局域网内的非本机 IP 通信
173
+ * - 允许与配置过的服务器域名通信,详见[相关说明](https://developers.weixin.qq.com/miniprogram/dev/framework/ability/network.html)
174
+ * - 禁止与以下端口号连接:1024 以下 1099 1433 1521 1719 1720 1723 2049 2375 3128 3306 3389 3659 4045 5060 5061 5432 5984 6379 6000 6566 7001 7002 8000-8100 8443 8888 9200 9300 10051 10080 11211 27017 27018 27019
175
+ * - 每 5 分钟内最多创建 20 个 TCPSocket
176
+ * @supported weapp
177
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/tcp/wx.createTCPSocket.html
178
+ */
179
+ createTCPSocket(): TCPSocket
180
+ }
181
+ }