@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,383 @@
1
+ import Taro from '../../index'
2
+
3
+ declare module '../../index' {
4
+ namespace sendSocketMessage {
5
+ interface Option {
6
+ /** 需要发送的内容 */
7
+ data: string | ArrayBuffer
8
+ /** 接口调用结束的回调函数(调用成功、失败都会执行) */
9
+ complete?: (res: TaroGeneral.CallbackResult) => void
10
+ /** 接口调用失败的回调函数 */
11
+ fail?: (res: TaroGeneral.CallbackResult) => void
12
+ /** 接口调用成功的回调函数 */
13
+ success?: (res: TaroGeneral.CallbackResult) => void
14
+ }
15
+ }
16
+
17
+ namespace onSocketOpen {
18
+ /** WebSocket 连接打开事件的回调函数 */
19
+ type Callback = (result: OpenCallbackResult) => void
20
+ interface OpenCallbackResult {
21
+ /** 连接成功的 HTTP 响应 Header */
22
+ header: TaroGeneral.IAnyObject
23
+ }
24
+ }
25
+
26
+ namespace onSocketMessage {
27
+ /** WebSocket 接受到服务器的消息事件的回调函数 */
28
+ type Callback<T = any> = (result: CallbackResult<T>) => void
29
+ interface CallbackResult<T extends any | string | ArrayBuffer = any> {
30
+ /** 服务器返回的消息 */
31
+ data: T
32
+ }
33
+ }
34
+
35
+ namespace onSocketError {
36
+ /** WebSocket 错误事件的回调函数 */
37
+ type Callback = (result: CallbackResult) => void
38
+ interface CallbackResult extends TaroGeneral.CallbackResult {
39
+ /** 错误信息 */
40
+ errMsg: string
41
+ }
42
+ }
43
+
44
+ namespace onSocketClose {
45
+ /** WebSocket 连接关闭事件的回调函数 */
46
+ type Callback = (result: CallbackResult) => void
47
+ interface CallbackResult {
48
+ /** 一个数字值表示关闭连接的状态号,表示连接被关闭的原因。 */
49
+ code: number
50
+ /** 一个可读的字符串,表示连接被关闭的原因。 */
51
+ reason: string
52
+ }
53
+ }
54
+
55
+ namespace connectSocket {
56
+ interface Option {
57
+ /** 开发者服务器 wss 接口地址 */
58
+ url: string
59
+ /** 接口调用结束的回调函数(调用成功、失败都会执行) */
60
+ complete?: (res: TaroGeneral.CallbackResult) => void
61
+ /** 接口调用失败的回调函数 */
62
+ fail?: (res: TaroGeneral.CallbackResult) => void
63
+ /** HTTP Header,Header 中不能设置 Referer */
64
+ header?: TaroGeneral.IAnyObject
65
+ /** 子协议数组 */
66
+ protocols?: string[]
67
+ /** 接口调用成功的回调函数 */
68
+ success?: (res: TaroGeneral.CallbackResult) => void
69
+ /** 建立 TCP 连接的时候的 TCP_NODELAY 设置 */
70
+ tcpNoDelay?: boolean
71
+ }
72
+ }
73
+
74
+ namespace closeSocket {
75
+ interface Option {
76
+ /** 一个数字值表示关闭连接的状态号,表示连接被关闭的原因。 */
77
+ code?: number
78
+ /** 接口调用结束的回调函数(调用成功、失败都会执行) */
79
+ complete?: (res: TaroGeneral.CallbackResult) => void
80
+ /** 接口调用失败的回调函数 */
81
+ fail?: (res: TaroGeneral.CallbackResult) => void
82
+ /** 一个可读的字符串,表示连接被关闭的原因。这个字符串必须是不长于 123 字节的 UTF-8 文本(不是字符)。 */
83
+ reason?: string
84
+ /** 接口调用成功的回调函数 */
85
+ success?: (res: TaroGeneral.CallbackResult) => void
86
+ }
87
+ }
88
+
89
+ namespace SocketTask {
90
+ interface CloseOption {
91
+ /** 一个数字值表示关闭连接的状态号,表示连接被关闭的原因。 */
92
+ code?: number
93
+ /** 接口调用结束的回调函数(调用成功、失败都会执行) */
94
+ complete?: (res: TaroGeneral.CallbackResult) => void
95
+ /** 接口调用失败的回调函数 */
96
+ fail?: (res: TaroGeneral.CallbackResult) => void
97
+ /** 一个可读的字符串,表示连接被关闭的原因。这个字符串必须是不长于 123 字节的 UTF-8 文本(不是字符)。 */
98
+ reason?: string
99
+ /** 接口调用成功的回调函数 */
100
+ success?: (res: TaroGeneral.CallbackResult) => void
101
+ }
102
+ /** WebSocket 连接关闭事件的回调函数 */
103
+ type OnCloseCallback = (result: OnCloseCallbackResult) => void
104
+ interface OnCloseCallbackResult {
105
+ /** 一个数字值表示关闭连接的状态号,表示连接被关闭的原因。 */
106
+ code: number
107
+ /** 一个可读的字符串,表示连接被关闭的原因。 */
108
+ reason: string
109
+ }
110
+ /** WebSocket 错误事件的回调函数 */
111
+ type OnErrorCallback = (result: OnErrorCallbackResult) => void
112
+ interface OnErrorCallbackResult extends TaroGeneral.CallbackResult {
113
+ /** 错误信息 */
114
+ errMsg: string
115
+ }
116
+ /** WebSocket 接受到服务器的消息事件的回调函数 */
117
+ type OnMessageCallback<T = any> = (result: OnMessageCallbackResult<T>) => void
118
+ interface OnMessageCallbackResult<T extends any | string | ArrayBuffer = any> {
119
+ /** 服务器返回的消息 */
120
+ data: T
121
+ }
122
+ /** WebSocket 连接打开事件的回调函数 */
123
+ type OnOpenCallback = (result: OnOpenCallbackResult) => void
124
+ interface OnOpenCallbackResult {
125
+ /** 连接成功的 HTTP 响应 Header*/
126
+ header: TaroGeneral.IAnyObject
127
+ }
128
+ interface SendOption {
129
+ /** 需要发送的内容 */
130
+ data: string | ArrayBuffer
131
+ /** 接口调用结束的回调函数(调用成功、失败都会执行) */
132
+ complete?: (res: TaroGeneral.CallbackResult) => void
133
+ /** 接口调用失败的回调函数 */
134
+ fail?: (res: TaroGeneral.CallbackResult) => void
135
+ /** 接口调用成功的回调函数 */
136
+ success?: (res: TaroGeneral.CallbackResult) => void
137
+ }
138
+ }
139
+
140
+ /** WebSocket 任务,可通过 [Taro.connectSocket()](/docs/apis/network/websocket/SocketTask) 接口创建返回。
141
+ * @supported weapp, h5, rn, alipay, swan, harmony_hybrid
142
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/websocket/SocketTask.html
143
+ */
144
+ interface SocketTask {
145
+ /** 通过 WebSocket 连接发送数据
146
+ * @supported weapp, h5, rn, alipay, swan, tt, harmony_hybrid
147
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/websocket/SocketTask.send.html
148
+ */
149
+ send(option: SocketTask.SendOption): void
150
+ /** 关闭 WebSocket 连接
151
+ * @supported weapp, h5, rn, alipay, swan, tt, harmony_hybrid
152
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/websocket/SocketTask.close.html
153
+ */
154
+ close(option: SocketTask.CloseOption): void
155
+ /** 监听 WebSocket 连接打开事件
156
+ * @supported weapp, h5, rn, alipay, swan, tt, harmony_hybrid
157
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/websocket/SocketTask.onOpen.html
158
+ */
159
+ onOpen(
160
+ /** WebSocket 连接打开事件的回调函数 */
161
+ callback: SocketTask.OnOpenCallback
162
+ ): void
163
+ /** 监听 WebSocket 连接关闭事件
164
+ * @supported weapp, h5, rn, alipay, swan, tt, harmony_hybrid
165
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/websocket/SocketTask.onClose.html
166
+ */
167
+ onClose(
168
+ /** WebSocket 连接关闭事件的回调函数 */
169
+ callback: SocketTask.OnCloseCallback
170
+ ): void
171
+ /** 监听 WebSocket 错误事件
172
+ * @supported weapp, h5, rn, alipay, swan, tt, harmony_hybrid
173
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/websocket/SocketTask.onError.html
174
+ */
175
+ onError(
176
+ /** WebSocket 错误事件的回调函数 */
177
+ callback: SocketTask.OnErrorCallback
178
+ ): void
179
+ /** 监听 WebSocket 接受到服务器的消息事件
180
+ * @supported weapp, h5, rn, alipay, swan, tt, harmony_hybrid
181
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/websocket/SocketTask.onMessage.html
182
+ */
183
+ onMessage<T = any>(
184
+ /** WebSocket 接受到服务器的消息事件的回调函数 */
185
+ callback: SocketTask.OnMessageCallback<T>
186
+ ): void
187
+
188
+ /** websocket 当前的连接 ID。 */
189
+ readonly socketTaskId: number
190
+ /** websocket 当前的连接状态。 */
191
+ readonly readyState: number
192
+ /** websocket 接口调用结果。 */
193
+ readonly errMsg: string
194
+ /** websocket 状态值:连接中。 */
195
+ readonly CONNECTING: number
196
+ /** websocket 状态值:已连接。 */
197
+ readonly OPEN: number
198
+ /** websocket 状态值:关闭中。 */
199
+ readonly CLOSING: number
200
+ /** websocket 状态值:已关闭。 */
201
+ readonly CLOSED: number
202
+ /** 浏览器 websocket 实例。(h5 端独有) */
203
+ readonly ws: WebSocket
204
+ }
205
+
206
+ interface TaroStatic {
207
+ /** 通过 WebSocket 连接发送数据。需要先 Taro.connectSocket,并在 Taro.onSocketOpen 回调之后才能发送。
208
+ * @supported weapp, alipay, swan
209
+ * @example
210
+ * ```tsx
211
+ * let socketOpen = false
212
+ * const socketMsgQueue = []
213
+ * Taro.connectSocket({
214
+ * url: 'test.php'
215
+ * })
216
+ * Taro.onSocketOpen(function(res) {
217
+ * socketOpen = true
218
+ * for (let i = 0; i < socketMsgQueue.length; i++){
219
+ * sendSocketMessage(socketMsgQueue[i])
220
+ * }
221
+ * socketMsgQueue = []
222
+ * })
223
+ * function sendSocketMessage(msg) {
224
+ * if (socketOpen) {
225
+ * Taro.sendSocketMessage({
226
+ * data:msg
227
+ * })
228
+ * } else {
229
+ * socketMsgQueue.push(msg)
230
+ * }
231
+ * }
232
+ * ```
233
+ @see https://developers.weixin.qq.com/miniprogram/dev/api/network/websocket/wx.sendSocketMessage.html
234
+ */
235
+ sendSocketMessage(option: sendSocketMessage.Option): Promise<TaroGeneral.CallbackResult>
236
+
237
+ /** 监听 WebSocket 连接打开事件
238
+ * @supported weapp, alipay, swan
239
+ * @example
240
+ * ```tsx
241
+ * Taro.connectSocket({
242
+ * url: 'test.php'
243
+ * })
244
+ * Taro.onSocketOpen(function (res) {
245
+ * console.log('WebSocket连接已打开!')
246
+ * })
247
+ * ```
248
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/websocket/wx.onSocketOpen.html
249
+ */
250
+ onSocketOpen(
251
+ /** WebSocket 连接打开事件的回调函数 */
252
+ callback: onSocketOpen.Callback
253
+ ): void
254
+
255
+ /** 监听 WebSocket 接受到服务器的消息事件
256
+ * @supported weapp, alipay, swan
257
+ * @example
258
+ * ```tsx
259
+ * Taro.connectSocket({
260
+ * url: 'test.php'
261
+ * })
262
+ * Taro.onSocketMessage(function (res) {
263
+ * console.log('收到服务器内容:' + res.data)
264
+ * })
265
+ * ```
266
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/websocket/wx.onSocketMessage.html
267
+ */
268
+ onSocketMessage<T = any>(
269
+ /** WebSocket 接受到服务器的消息事件的回调函数 */
270
+ callback: onSocketMessage.Callback<T>
271
+ ): void
272
+
273
+ /** 监听 WebSocket 错误事件
274
+ * @supported weapp, alipay, swan
275
+ * @example
276
+ * ```tsx
277
+ * Taro.connectSocket({
278
+ * url: 'test.php'
279
+ * })
280
+ * Taro.onSocketOpen(function (res){
281
+ * console.log('WebSocket连接已打开!')
282
+ * })
283
+ * Taro.onSocketError(function (res){
284
+ * console.log('WebSocket连接打开失败,请检查!')
285
+ * })
286
+ * ```
287
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/websocket/wx.onSocketError.html
288
+ */
289
+ onSocketError(
290
+ /** WebSocket 错误事件的回调函数 */
291
+ callback: onSocketError.Callback
292
+ ): void
293
+
294
+ /** 监听 WebSocket 连接关闭事件
295
+ * @supported weapp, alipay, swan
296
+ * @example
297
+ * ```tsx
298
+ * Taro.connectSocket({
299
+ * url: 'test.php'
300
+ * })
301
+ * //注意这里有时序问题,
302
+ * //如果 Taro.connectSocket 还没回调 Taro.onSocketOpen,而先调用 Taro.closeSocket,那么就做不到关闭 WebSocket 的目的。
303
+ * //必须在 WebSocket 打开期间调用 Taro.closeSocket 才能关闭。
304
+ * Taro.onSocketOpen(function () {
305
+ * Taro.closeSocket()
306
+ * })
307
+ * Taro.onSocketClose(function (res) {
308
+ * console.log('WebSocket 已关闭!')
309
+ * })
310
+ * ```
311
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/websocket/wx.onSocketClose.html
312
+ */
313
+ onSocketClose(
314
+ /** WebSocket 连接关闭事件的回调函数 */
315
+ callback: onSocketClose.Callback
316
+ ): void
317
+
318
+ /** 创建一个 WebSocket 连接。使用前请注意阅读[相关说明](https://developers.weixin.qq.com/miniprogram/dev/framework/ability/network.html)。
319
+ *
320
+ * **并发数**
321
+ * - 1.7.0 及以上版本,最多可以同时存在 5 个 WebSocket 连接。
322
+ * - 1.7.0 以下版本,一个小程序同时只能有一个 WebSocket 连接,如果当前已存在一个 WebSocket 连接,会自动关闭该连接,并重新创建一个 WebSocket 连接。
323
+ * @supported weapp, h5, rn, alipay, swan, harmony_hybrid
324
+ * @example
325
+ * ```tsx
326
+ * Taro.connectSocket({
327
+ * url: 'wss://example.qq.com',
328
+ * header:{
329
+ * 'content-type': 'application/json'
330
+ * },
331
+ * protocols: ['protocol1']
332
+ * })
333
+ * ```
334
+ * @example
335
+ * ```tsx
336
+ * Taro.connectSocket({
337
+ * url: 'ws://echo.websocket.org/echo',
338
+ * success: function () {
339
+ * console.log('connect success')
340
+ * }
341
+ * }).then(task => {
342
+ * task.onOpen(function () {
343
+ * console.log('onOpen')
344
+ * task.send({ data: 'xxx' })
345
+ * })
346
+ * task.onMessage(function (msg) {
347
+ * console.log('onMessage: ', msg)
348
+ * task.close()
349
+ * })
350
+ * task.onError(function () {
351
+ * console.log('onError')
352
+ * })
353
+ * task.onClose(function (e) {
354
+ * console.log('onClose: ', e)
355
+ * })
356
+ * })
357
+ * ```
358
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/websocket/wx.connectSocket.html
359
+ */
360
+ connectSocket(option: connectSocket.Option): Promise<SocketTask>
361
+
362
+ /** 关闭 WebSocket 连接
363
+ * @supported weapp, alipay, swan
364
+ * @example
365
+ * ```tsx
366
+ * Taro.connectSocket({
367
+ * url: 'test.php'
368
+ * })
369
+ * //注意这里有时序问题,
370
+ * //如果 Taro.connectSocket 还没回调 Taro.onSocketOpen,而先调用 Taro.closeSocket,那么就做不到关闭 WebSocket 的目的。
371
+ * //必须在 WebSocket 打开期间调用 Taro.closeSocket 才能关闭。
372
+ * Taro.onSocketOpen(function() {
373
+ * Taro.closeSocket()
374
+ * })
375
+ * Taro.onSocketClose(function(res) {
376
+ * console.log('WebSocket 已关闭!')
377
+ * })
378
+ * ```
379
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/websocket/wx.closeSocket.html
380
+ */
381
+ closeSocket(option?: closeSocket.Option): Promise<TaroGeneral.CallbackResult>
382
+ }
383
+ }
@@ -0,0 +1,51 @@
1
+ import Taro from '../../index'
2
+
3
+ declare module '../../index' {
4
+ namespace getAccountInfoSync {
5
+ /** 帐号信息 */
6
+ interface AccountInfo {
7
+ /** 小程序帐号信息 */
8
+ miniProgram: MiniProgram
9
+ /** 插件帐号信息(仅在插件中调用时包含这一项) */
10
+ plugin: Plugin
11
+ }
12
+ /** 小程序帐号信息 */
13
+ interface MiniProgram {
14
+ /** 小程序 appId */
15
+ appId: string
16
+ /**
17
+ * 小程序版本
18
+ * @since 2.10.0
19
+ */
20
+ envVersion: 'develop' | 'trial' | 'release'
21
+ /**
22
+ * 线上小程序版本号
23
+ * @since 2.10.2
24
+ */
25
+ version: string
26
+ }
27
+ /** 插件帐号信息(仅在插件中调用时包含这一项) */
28
+ interface Plugin {
29
+ /** 插件 appId */
30
+ appId: string
31
+ /** 插件版本号 */
32
+ version: string
33
+ }
34
+ }
35
+
36
+ interface TaroStatic {
37
+ /** 获取当前帐号信息
38
+ * @supported weapp, alipay, qq
39
+ * @example
40
+ * ```tsx
41
+ * const accountInfo = Taro.getAccountInfoSync();
42
+ *
43
+ * console.log(accountInfo.miniProgram.appId) // 小程序 appId
44
+ * console.log(accountInfo.plugin.appId) // 插件 appId
45
+ * console.log(accountInfo.plugin.version) // 插件版本号, 'a.b.c' 这样的形式
46
+ * ```
47
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/open-api/account-info/wx.getAccountInfoSync.html
48
+ */
49
+ getAccountInfoSync(): getAccountInfoSync.AccountInfo
50
+ }
51
+ }
@@ -0,0 +1,68 @@
1
+ import Taro from '../../index'
2
+
3
+ declare module '../../index' {
4
+ namespace chooseAddress {
5
+ interface Option {
6
+ /** 接口调用结束的回调函数(调用成功、失败都会执行) */
7
+ complete?: (res: SuccessCallbackResult) => void
8
+ /** 接口调用失败的回调函数 */
9
+ fail?: (res: TaroGeneral.CallbackResult) => void
10
+ /** 接口调用成功的回调函数 */
11
+ success?: (result: SuccessCallbackResult) => void
12
+ }
13
+
14
+ interface SuccessCallbackResult extends TaroGeneral.CallbackResult {
15
+ /** 收货人姓名 */
16
+ userName: string
17
+ /** 邮编
18
+ * @supported weapp, qq
19
+ */
20
+ postalCode: string
21
+ /** 国标收货地址第一级地址 */
22
+ provinceName: string
23
+ /** 国标收货地址第二级地址 */
24
+ cityName: string
25
+ /** 国标收货地址第三级地址 */
26
+ countyName: string
27
+ /** 国标收货地址第四级地址
28
+ * @supported weapp, qq
29
+ */
30
+ streetName: string
31
+ /** 详细收货地址信息 */
32
+ detailInfo: string
33
+ /** 新选择器详细收货地址信息
34
+ * @supported weapp, qq
35
+ */
36
+ detailInfoNew: string
37
+ /** 收货地址国家码
38
+ * @supported weapp, qq
39
+ */
40
+ nationalCode: string
41
+ /** 收货人手机号码 */
42
+ telNumber: string
43
+ }
44
+ }
45
+
46
+ interface TaroStatic {
47
+ /** 获取用户收货地址。调起用户编辑收货地址原生界面,并在编辑完成后返回用户选择的地址。
48
+ * @supported weapp, qq, tt, jd
49
+ * @example
50
+ * ```tsx
51
+ * Taro.chooseAddress({
52
+ * success: function (res) {
53
+ * console.log(res.userName)
54
+ * console.log(res.postalCode)
55
+ * console.log(res.provinceName)
56
+ * console.log(res.cityName)
57
+ * console.log(res.countyName)
58
+ * console.log(res.detailInfo)
59
+ * console.log(res.nationalCode)
60
+ * console.log(res.telNumber)
61
+ * }
62
+ * })
63
+ * ```
64
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/open-api/address/wx.chooseAddress.html
65
+ */
66
+ chooseAddress(option?: chooseAddress.Option): Promise<chooseAddress.SuccessCallbackResult>
67
+ }
68
+ }
@@ -0,0 +1,80 @@
1
+ import Taro from '../../index'
2
+
3
+ declare module '../../index' {
4
+ namespace authorizeForMiniProgram {
5
+ interface Option {
6
+ /** 需要获取权限的 scope,详见 [scope 列表](https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/authorize.html#scope-%E5%88%97%E8%A1%A8) */
7
+ scope: keyof Scope | string
8
+ /** 接口调用结束的回调函数(调用成功、失败都会执行) */
9
+ complete?: (res: TaroGeneral.CallbackResult) => void
10
+ /** 接口调用失败的回调函数 */
11
+ fail?: (res: TaroGeneral.CallbackResult) => void
12
+ /** 接口调用成功的回调函数 */
13
+ success?: (res: TaroGeneral.CallbackResult) => void
14
+ }
15
+
16
+ /** scope 合法值
17
+ * @see https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/authorize.html#scope-%E5%88%97%E8%A1%A8
18
+ */
19
+ interface Scope {
20
+ 'scope.record'
21
+ 'scope.writePhotosAlbum'
22
+ 'scope.camera'
23
+ }
24
+ }
25
+
26
+ namespace authorize {
27
+ interface Option {
28
+ /** 需要获取权限的 scope,详见 [scope 列表](https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/authorize.html#scope-%E5%88%97%E8%A1%A8) */
29
+ scope: string
30
+ /** 接口调用结束的回调函数(调用成功、失败都会执行) */
31
+ complete?: (res: TaroGeneral.CallbackResult) => void
32
+ /** 接口调用失败的回调函数 */
33
+ fail?: (res: TaroGeneral.CallbackResult) => void
34
+ /** 接口调用成功的回调函数 */
35
+ success?: (res: TaroGeneral.CallbackResult) => void
36
+ }
37
+ }
38
+
39
+ interface TaroStatic {
40
+ /** **仅小程序插件中能调用该接口**,用法同 [Taro.authorize](../authorize)。目前仅支持三种 scope
41
+ * @supported weapp
42
+ * @example
43
+ * ```tsx
44
+ * // 可以通过 Taro.getSetting 先查询一下用户是否授权了 "scope.record" 这个 scope
45
+ * Taro.authorizeForMiniProgram({
46
+ * scope: 'scope.record',
47
+ * success () {
48
+ * // 用户已经同意小程序使用录音功能,后续调用 Taro.startRecord 接口不会弹窗询问
49
+ * Taro.startRecord()
50
+ * }
51
+ * })
52
+ * ```
53
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/open-api/authorize/wx.authorizeForMiniProgram.html
54
+ */
55
+ authorizeForMiniProgram(option: authorizeForMiniProgram.Option): Promise<TaroGeneral.CallbackResult>
56
+
57
+ /** 提前向用户发起授权请求。调用后会立刻弹窗询问用户是否同意授权小程序使用某项功能或获取用户的某些数据,但不会实际调用对应接口。如果用户之前已经同意授权,则不会出现弹窗,直接返回成功。更多用法详见 [用户授权](https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/authorize.html)。
58
+ * @supported weapp, swan, qq, tt, rn
59
+ * @example
60
+ * ```tsx
61
+ * // 可以通过 Taro.getSetting 先查询一下用户是否授权了 "scope.record" 这个 scope
62
+ * Taro.getSetting({
63
+ * success: function (res) {
64
+ * if (!res.authSetting['scope.record']) {
65
+ * Taro.authorize({
66
+ * scope: 'scope.record',
67
+ * success: function () {
68
+ * // 用户已经同意小程序使用录音功能,后续调用 Taro.startRecord 接口不会弹窗询问
69
+ * Taro.startRecord()
70
+ * }
71
+ * })
72
+ * }
73
+ * }
74
+ * })
75
+ * ```
76
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/open-api/authorize/wx.authorize.html
77
+ */
78
+ authorize(option: authorize.Option): Promise<TaroGeneral.CallbackResult>
79
+ }
80
+ }
@@ -0,0 +1,110 @@
1
+ import Taro from '../../index'
2
+
3
+ declare module '../../index' {
4
+ namespace openCard {
5
+ interface Option {
6
+ /** 需要打开的卡券列表 */
7
+ cardList: RequestInfo[]
8
+ /** 接口调用结束的回调函数(调用成功、失败都会执行) */
9
+ complete?: (res: TaroGeneral.CallbackResult) => void
10
+ /** 接口调用失败的回调函数 */
11
+ fail?: (res: TaroGeneral.CallbackResult) => void
12
+ /** 接口调用成功的回调函数 */
13
+ success?: (res: TaroGeneral.CallbackResult) => void
14
+ }
15
+
16
+ /** 需要打开的卡券列表 */
17
+ interface RequestInfo {
18
+ /** 卡券 ID */
19
+ cardId: string
20
+ /** 由 Taro.addCard 的返回对象中的加密 code 通过解密后得到,解密请参照:[code 解码接口](https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1499332673_Unm7V) */
21
+ code: string
22
+ }
23
+ }
24
+
25
+ namespace addCard {
26
+ interface Option {
27
+ /** 需要添加的卡券列表 */
28
+ cardList: RequestInfo[]
29
+ /** 接口调用结束的回调函数(调用成功、失败都会执行) */
30
+ complete?: (res: TaroGeneral.CallbackResult) => void
31
+ /** 接口调用失败的回调函数 */
32
+ fail?: (res: TaroGeneral.CallbackResult) => void
33
+ /** 接口调用成功的回调函数 */
34
+ success?: (result: SuccessCallbackResult) => void
35
+ }
36
+
37
+ /** 需要添加的卡券列表 */
38
+ interface RequestInfo {
39
+ /** 卡券的扩展参数。需将 CardExt 对象 JSON 序列化为**字符串**传入 */
40
+ cardExt: string
41
+ /** 卡券 ID */
42
+ cardId: string
43
+ }
44
+
45
+ interface SuccessCallbackResult extends TaroGeneral.CallbackResult {
46
+ /** 卡券添加结果列表 */
47
+ cardList: AddCardResponseInfo[]
48
+ /** 调用结果 */
49
+ errMsg: string
50
+ }
51
+ /** 卡券添加结果列表 */
52
+ interface AddCardResponseInfo {
53
+ /** 卡券的扩展参数,结构请参考下文 */
54
+ cardExt: string
55
+ /** 用户领取到卡券的 ID */
56
+ cardId: string
57
+ /** 加密 code,为用户领取到卡券的code加密后的字符串,解密请参照:[code 解码接口](https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1499332673_Unm7V) */
58
+ code: string
59
+ /** 是否成功 */
60
+ isSuccess: boolean
61
+ }
62
+ }
63
+
64
+ interface TaroStatic {
65
+ /** 查看微信卡包中的卡券。只有通过 [认证](https://developers.weixin.qq.com/miniprogram/product/renzheng.html) 的小程序或文化互动类目的小游戏才能使用。更多文档请参考 [微信卡券接口文档](https://mp.weixin.qq.com/cgi-bin/announce?action=getannouncement&key=1490190158&version=1&lang=zh_CN&platform=2)。
66
+ * @supported weapp
67
+ * @example
68
+ * ```tsx
69
+ * Taro.openCard({
70
+ * cardList: [{
71
+ * cardId: '',
72
+ * code: ''
73
+ * }, {
74
+ * cardId: '',
75
+ * code: ''
76
+ * }],
77
+ * success: function (res) { }
78
+ * })
79
+ * ```
80
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/open-api/card/wx.openCard.html
81
+ */
82
+ openCard(option: openCard.Option): Promise<TaroGeneral.CallbackResult>
83
+
84
+ /** 批量添加卡券。只有通过 [认证](https://developers.weixin.qq.com/miniprogram/product/renzheng.html) 的小程序或文化互动类目的小游戏才能使用。更多文档请参考 [微信卡券接口文档](https://mp.weixin.qq.com/cgi-bin/announce?action=getannouncement&key=1490190158&version=1&lang=zh_CN&platform=2)。
85
+ *
86
+ * **cardExt 说明**
87
+ * cardExt 是卡券的扩展参数,其值是一个 JSON 字符串。
88
+ * @supported weapp
89
+ * @example
90
+ * ```tsx
91
+ * Taro.addCard({
92
+ * cardList: [
93
+ * {
94
+ * cardId: '',
95
+ * cardExt: '{"code": "", "openid": "", "timestamp": "", "signature":""}'
96
+ * }, {
97
+ * cardId: '',
98
+ * cardExt: '{"code": "", "openid": "", "timestamp": "", "signature":""}'
99
+ * }
100
+ * ],
101
+ * success: function (res) {
102
+ * console.log(res.cardList) // 卡券添加结果
103
+ * }
104
+ * })
105
+ * ```
106
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/open-api/card/wx.addCard.html
107
+ */
108
+ addCard(option: addCard.Option): Promise<addCard.SuccessCallbackResult>
109
+ }
110
+ }