@tarojs/taro 3.5.0-canary.1 → 3.5.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 (109) hide show
  1. package/html.css +50 -14
  2. package/html5.css +167 -64
  3. package/index.js +3 -4
  4. package/package.json +21 -11
  5. package/types/api/ad/index.d.ts +2 -2
  6. package/types/api/ai/face.d.ts +133 -0
  7. package/types/api/ai/visionkit.d.ts +303 -0
  8. package/types/api/base/crypto.d.ts +90 -0
  9. package/types/api/base/debug.d.ts +152 -13
  10. package/types/api/base/env.d.ts +2 -1
  11. package/types/api/base/index.d.ts +11 -3
  12. package/types/api/base/performance.d.ts +195 -0
  13. package/types/api/base/system.d.ts +541 -103
  14. package/types/api/base/update.d.ts +60 -8
  15. package/types/api/base/weapp/app-event.d.ts +99 -37
  16. package/types/api/base/weapp/life-cycle.d.ts +142 -2
  17. package/types/api/canvas/index.d.ts +151 -137
  18. package/types/api/cloud/index.d.ts +17 -2
  19. package/types/api/data-analysis/index.d.ts +1 -1
  20. package/types/api/device/accelerometer.d.ts +6 -6
  21. package/types/api/device/accessibility.d.ts +26 -0
  22. package/types/api/device/battery.d.ts +2 -2
  23. package/types/api/device/{ble.d.ts → bluetooth-ble.d.ts} +228 -62
  24. package/types/api/device/bluetooth-peripheral.d.ts +430 -0
  25. package/types/api/device/bluetooth.d.ts +67 -2
  26. package/types/api/device/calendar.d.ts +88 -0
  27. package/types/api/device/clipboard.d.ts +2 -2
  28. package/types/api/device/compass.d.ts +3 -3
  29. package/types/api/device/contact.d.ts +74 -50
  30. package/types/api/device/gyroscope.d.ts +6 -6
  31. package/types/api/device/iBeacon.d.ts +33 -19
  32. package/types/api/{ui → device}/keyboard.d.ts +1 -1
  33. package/types/api/device/{performance.d.ts → memory.d.ts} +5 -5
  34. package/types/api/device/motion.d.ts +3 -3
  35. package/types/api/device/network.d.ts +56 -15
  36. package/types/api/device/nfc.d.ts +1089 -13
  37. package/types/api/device/phone.d.ts +1 -1
  38. package/types/api/device/scan.d.ts +1 -1
  39. package/types/api/device/screen.d.ts +42 -14
  40. package/types/api/device/vibrate.d.ts +6 -2
  41. package/types/api/device/wifi.d.ts +44 -9
  42. package/types/api/ext/index.d.ts +2 -2
  43. package/types/api/files/index.d.ts +392 -205
  44. package/types/api/framework/index.d.ts +5 -4
  45. package/types/api/location/index.d.ts +156 -53
  46. package/types/api/media/audio.d.ts +629 -38
  47. package/types/api/media/background-audio.d.ts +9 -9
  48. package/types/api/media/camera.d.ts +41 -22
  49. package/types/api/media/editor.d.ts +22 -2
  50. package/types/api/media/image.d.ts +64 -35
  51. package/types/api/media/live.d.ts +66 -6
  52. package/types/api/media/map.d.ts +474 -54
  53. package/types/api/media/media-recorder.d.ts +92 -0
  54. package/types/api/media/recorder.d.ts +21 -21
  55. package/types/api/media/video-decoder.d.ts +117 -0
  56. package/types/api/media/video-processing.d.ts +11 -7
  57. package/types/api/media/video.d.ts +47 -18
  58. package/types/api/media/voip.d.ts +290 -0
  59. package/types/api/{open-api/navigate.d.ts → navigate/index.d.ts} +65 -27
  60. package/types/api/network/download.d.ts +61 -19
  61. package/types/api/network/request.d.ts +129 -41
  62. package/types/api/network/tcp.d.ts +181 -0
  63. package/types/api/network/udp.d.ts +154 -83
  64. package/types/api/network/upload.d.ts +55 -28
  65. package/types/api/network/websocket.d.ts +20 -19
  66. package/types/api/open-api/address.d.ts +1 -1
  67. package/types/api/open-api/authorize.d.ts +42 -3
  68. package/types/api/open-api/channels.d.ts +178 -0
  69. package/types/api/open-api/facial.d.ts +3 -0
  70. package/types/api/open-api/favorites.d.ts +100 -0
  71. package/types/api/open-api/group.d.ts +59 -0
  72. package/types/api/open-api/invoice.d.ts +2 -2
  73. package/types/api/open-api/license-plate.d.ts +27 -0
  74. package/types/api/open-api/login.d.ts +21 -0
  75. package/types/api/open-api/redpackage.d.ts +24 -0
  76. package/types/api/open-api/settings.d.ts +82 -17
  77. package/types/api/open-api/soter.d.ts +2 -2
  78. package/types/api/open-api/subscribe-message.d.ts +89 -4
  79. package/types/api/open-api/user-info.d.ts +56 -19
  80. package/types/api/open-api/werun.d.ts +33 -6
  81. package/types/api/payment/index.d.ts +119 -0
  82. package/types/api/route/index.d.ts +18 -14
  83. package/types/api/share/index.d.ts +192 -9
  84. package/types/api/storage/index.d.ts +38 -92
  85. package/types/api/swan/index.d.ts +1 -1
  86. package/types/api/ui/animation.d.ts +105 -155
  87. package/types/api/ui/background.d.ts +4 -2
  88. package/types/api/ui/custom-component.d.ts +1 -1
  89. package/types/api/ui/fonts.d.ts +27 -31
  90. package/types/api/ui/interaction.d.ts +6 -6
  91. package/types/api/ui/menu.d.ts +1 -1
  92. package/types/api/ui/navigation-bar.d.ts +6 -5
  93. package/types/api/ui/pull-down-refresh.d.ts +2 -2
  94. package/types/api/ui/scroll.d.ts +75 -7
  95. package/types/api/ui/sticky.d.ts +4 -4
  96. package/types/api/ui/tab-bar.d.ts +8 -8
  97. package/types/api/ui/window.d.ts +22 -2
  98. package/types/api/worker/index.d.ts +9 -1
  99. package/types/api/wxml/index.d.ts +116 -112
  100. package/types/compile.d.ts +57 -6
  101. package/types/global.d.ts +142 -111
  102. package/types/taro.api.d.ts +79 -62
  103. package/types/taro.component.d.ts +21 -65
  104. package/types/taro.config.d.ts +31 -0
  105. package/types/taro.extend.d.ts +31 -18
  106. package/types/taro.hooks.d.ts +55 -3
  107. package/types/taro.lifecycle.d.ts +21 -14
  108. package/LICENSE +0 -21
  109. package/types/api/open-api/payment.d.ts +0 -61
@@ -2,53 +2,84 @@ import Taro from '../../index'
2
2
 
3
3
  declare module '../../index' {
4
4
  /** 一个 UDP Socket 实例,默认使用 IPv4 协议。
5
+ * @supported weapp
5
6
  * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/udp/UDPSocket.html
6
7
  */
7
8
  interface UDPSocket {
8
- /** 关闭 UDP Socket 实例,相当于销毁。 在关闭之后,UDP Socket 实例不能再发送消息,每次调用 `UDPSocket.send` 将会触发错误事件,并且 message 事件回调函数也不会再也执行。在 `UDPSocket` 实例被创建后将被 Native 强引用,保证其不被 GC。在 `UDPSocket.close` 后将解除对其的强引用,让 UDPSocket 实例遵从 GC。
9
+ /** 绑定一个系统随机分配的可用端口,或绑定一个指定的端口号
9
10
  * @supported weapp
10
- * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/udp/UDPSocket.close.html
11
+ * @example
12
+ * ```tsx
13
+ * const udp = Taro.createUDPSocket()
14
+ * udp.close()
15
+ * ```
16
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/udp/UDPSocket.bind.html
11
17
  */
12
- close(): void
13
- /** 取消监听关闭事件
18
+ bind(
19
+ /** 指定要绑定的端口号,不传则返回系统随机分配的可用端口 */
20
+ port: number,
21
+ ): number
22
+ /** 设置 IP_TTL 套接字选项,用于设置一个 IP 数据包传输时允许的最大跳步数
14
23
  * @supported weapp
15
- * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/udp/UDPSocket.offClose.html
24
+ * @example
25
+ * ```tsx
26
+ * const udp = Taro.createUDPSocket()
27
+ * udp.onListening(function () {
28
+ * udp.setTTL(64)
29
+ * })
30
+ * udp.bind()
31
+ * ```
32
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/udp/UDPSocket.setTTL.html
16
33
  */
17
- offClose(
18
- /** 关闭事件的回调函数 */
19
- callback: UDPSocket.OffCloseCallback,
34
+ setTTL(
35
+ /** ttl 参数可以是 0 到 255 之间 */
36
+ ttl: number
20
37
  ): void
21
- /** 取消监听错误事件
38
+ /** 向指定的 IP 和 port 发送消息
22
39
  * @supported weapp
23
- * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/udp/UDPSocket.offError.html
40
+ * @example
41
+ * ```tsx
42
+ * const udp = Taro.createUDPSocket()
43
+ * udp.bind()
44
+ * udp.send({
45
+ * address: '192.168.193.2',
46
+ * port: 8848,
47
+ * message: 'hello, how are you'
48
+ * })
49
+ * ```
50
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/udp/UDPSocket.send.html
24
51
  */
25
- offError(
26
- /** 错误事件的回调函数 */
27
- callback: UDPSocket.OffErrorCallback,
28
- ): void
29
- /** 取消监听开始监听数据包消息的事件
52
+ send(option: UDPSocket.send.Option): void
53
+ /** 预先连接到指定的 IP 和 port,需要配合 write 方法一起使用
30
54
  * @supported weapp
31
- * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/udp/UDPSocket.offListening.html
55
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/udp/UDPSocket.connect.html
32
56
  */
33
- offListening(
34
- /** 开始监听数据包消息的事件的回调函数 */
35
- callback: (res: TaroGeneral.CallbackResult) => void,
36
- ): void
37
- /** 取消监听收到消息的事件
57
+ connect(option: UDPSocket.connect.Option): void
58
+ /** 用法与 send 方法相同,如果没有预先调用 connect 则与 send 无差异(注意即使调用了 connect 也需要在本接口填入地址和端口参数)
38
59
  * @supported weapp
39
- * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/udp/UDPSocket.offMessage.html
60
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/udp/UDPSocket.write.html
40
61
  */
41
- offMessage(
42
- /** 收到消息的事件的回调函数 */
43
- callback: (res: TaroGeneral.CallbackResult) => void,
44
- ): void
62
+ write(): void
63
+ /** 关闭 UDP Socket 实例,相当于销毁。 在关闭之后,UDP Socket 实例不能再发送消息,每次调用 `UDPSocket.send` 将会触发错误事件,并且 message 事件回调函数也不会再也执行。在 `UDPSocket` 实例被创建后将被 Native 强引用,保证其不被 GC。在 `UDPSocket.close` 后将解除对其的强引用,让 UDPSocket 实例遵从 GC。
64
+ * @supported weapp
65
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/udp/UDPSocket.close.html
66
+ */
67
+ close(): void
45
68
  /** 监听关闭事件
46
69
  * @supported weapp
47
70
  * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/udp/UDPSocket.onClose.html
48
71
  */
49
72
  onClose(
50
73
  /** 关闭事件的回调函数 */
51
- callback: UDPSocket.OnCloseCallback,
74
+ callback: UDPSocket.onClose.Callback,
75
+ ): void
76
+ /** 取消监听关闭事件
77
+ * @supported weapp
78
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/udp/UDPSocket.offClose.html
79
+ */
80
+ offClose(
81
+ /** 关闭事件的回调函数 */
82
+ callback: UDPSocket.onClose.Callback,
52
83
  ): void
53
84
  /** 监听错误事件
54
85
  * @supported weapp
@@ -56,15 +87,31 @@ declare module '../../index' {
56
87
  */
57
88
  onError(
58
89
  /** 错误事件的回调函数 */
59
- callback: UDPSocket.OnErrorCallback,
90
+ callback: UDPSocket.onError.Callback,
91
+ ): void
92
+ /** 取消监听错误事件
93
+ * @supported weapp
94
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/udp/UDPSocket.offError.html
95
+ */
96
+ offError(
97
+ /** 错误事件的回调函数 */
98
+ callback: UDPSocket.onError.Callback,
60
99
  ): void
61
100
  /** 监听开始监听数据包消息的事件
62
101
  * @supported weapp
63
102
  * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/udp/UDPSocket.onListening.html
64
103
  */
65
104
  onListening(
66
- /** 开始监听数据包消息的事件的回调函数 */
67
- callback: (res: TaroGeneral.CallbackResult) => void,
105
+ /** 监听开始监听数据包消息的事件 */
106
+ callback: UDPSocket.onListening.Callback,
107
+ ): void
108
+ /** 取消监听开始监听数据包消息的事件
109
+ * @supported weapp
110
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/udp/UDPSocket.offListening.html
111
+ */
112
+ offListening(
113
+ /** 监听开始监听数据包消息的事件 */
114
+ callback: UDPSocket.onListening.Callback,
68
115
  ): void
69
116
  /** 监听收到消息的事件
70
117
  * @supported weapp
@@ -72,68 +119,92 @@ declare module '../../index' {
72
119
  */
73
120
  onMessage(
74
121
  /** 收到消息的事件的回调函数 */
75
- callback: UDPSocket.OnMessageCallback,
122
+ callback: UDPSocket.onMessage.Callback,
76
123
  ): void
77
- /** 向指定的 IP 和 port 发送消息
78
- * @supported weapp
79
- * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/udp/UDPSocket.send.html
80
- */
81
- send(option: UDPSocket.SendOption): void
82
- /** 绑定一个系统随机分配的可用端口,或绑定一个指定的端口号
124
+ /** 取消监听收到消息的事件
83
125
  * @supported weapp
84
- * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/udp/UDPSocket.bind.html
126
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/udp/UDPSocket.offMessage.html
85
127
  */
86
- bind(
87
- /** 指定要绑定的端口号 */
88
- port: number,
89
- ): number
128
+ offMessage(
129
+ /** 收到消息的事件的回调函数 */
130
+ callback: UDPSocket.onMessage.Callback,
131
+ ): void
90
132
  }
91
133
 
92
134
  namespace UDPSocket {
93
- /** 关闭事件的回调函数 */
94
- type OffCloseCallback = (res: TaroGeneral.CallbackResult) => void
95
- /** 错误事件的回调函数 */
96
- type OffErrorCallback = (res: TaroGeneral.CallbackResult) => void
97
- /** 关闭事件的回调函数 */
98
- type OnCloseCallback = (res: TaroGeneral.CallbackResult) => void
99
- /** 错误事件的回调函数 */
100
- type OnErrorCallback = (
101
- result: OnErrorCallbackResult,
102
- ) => void
103
- /** 收到消息的事件的回调函数 */
104
- type OnMessageCallback = (
105
- result: OnMessageCallbackResult,
106
- ) => void
107
- interface OnErrorCallbackResult extends TaroGeneral.CallbackResult {
108
- /** 错误信息 */
109
- errMsg: string
135
+ namespace connect {
136
+ interface Option {
137
+ /** 要发消息的地址 */
138
+ address: string
139
+ /** 要发送消息的端口号 */
140
+ port: number
141
+ }
110
142
  }
111
- interface OnMessageCallbackResult {
112
- /** 收到的消息 */
113
- message: ArrayBuffer
114
- /** 消息来源的结构化信息 */
115
- remoteInfo: RemoteInfo
143
+ namespace onClose {
144
+ /** 当一个 socket 完全关闭就发出该事件的回调函数 */
145
+ type Callback = (...args: unknown[]) => void
116
146
  }
117
- /** 消息来源的结构化信息 */
118
- interface RemoteInfo {
119
- /** 发送消息的 socket 的地址 */
120
- address: string
121
- /** 使用的协议族,为 IPv4 或者 IPv6 */
122
- family: string
123
- /** 端口号 */
124
- port: number
125
- /** message 的大小,单位:字节 */
126
- size: number
147
+ namespace onError {
148
+ /** 错误事件的回调函数 */
149
+ type Callback = (result: CallbackResult) => void
150
+ interface CallbackResult extends TaroGeneral.CallbackResult {
151
+ /** 错误信息 */
152
+ errMsg: string
153
+ }
154
+ }
155
+ namespace onListening {
156
+ /** 监听开始监听数据包消息的事件 */
157
+ type Callback = (...args: unknown[]) => void
158
+ }
159
+ namespace onMessage {
160
+ /** 收到消息的事件的回调函数 */
161
+ type Callback = (result: CallbackResult) => void
162
+ interface CallbackResult extends TaroGeneral.CallbackResult {
163
+ /** 收到的消息 */
164
+ message: ArrayBuffer
165
+ /** 发送端地址信息 */
166
+ remoteInfo: RemoteInfo
167
+ /** 接收端地址信息 */
168
+ localInfo: LocalInfo
169
+ }
170
+ /** 发送端地址信息 */
171
+ interface RemoteInfo {
172
+ /** 发送消息的 socket 的地址 */
173
+ address: string
174
+ /** 使用的协议族,为 IPv4 或者 IPv6 */
175
+ family: string
176
+ /** 端口号 */
177
+ port: number
178
+ }
179
+ /** 接收端地址信息 */
180
+ interface LocalInfo {
181
+ /** 接收消息的 socket 的地址 */
182
+ address: string
183
+ /** 使用的协议族,为 IPv4 或者 IPv6 */
184
+ family: string
185
+ /** 端口号 */
186
+ port: number
187
+ /** message 的大小,单位:字节 */
188
+ size: number
189
+ }
127
190
  }
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
191
+ namespace send {
192
+ interface Option {
193
+ /** 要发消息的地址。在基础库 <= 2.9.3 版本必须是和本机同网段的 IP 地址,或安全域名列表内的域名地址;之后版本可以是任意 IP 和域名 */
194
+ address: string
195
+ /** 要发送消息的端口号 */
196
+ port: number
197
+ /** 要发送的数据 */
198
+ message: string | ArrayBuffer
199
+ /** 发送数据的偏移量,仅当 message ArrayBuffer 类型时有效
200
+ * @default 0
201
+ */
202
+ offset?: number
203
+ /** 发送数据的长度,仅当 message 为 ArrayBuffer 类型时有效
204
+ * @default message.byteLength
205
+ */
206
+ length?: number
207
+ }
137
208
  }
138
209
  }
139
210
 
@@ -35,6 +35,18 @@ declare module '../../index' {
35
35
  statusCode: number
36
36
  /** 调用结果 */
37
37
  errMsg: string
38
+ /**
39
+ * 开发者服务器返回的 HTTP Response Header
40
+ * @supported weapp
41
+ * @weapp 非官方文档标注属性
42
+ */
43
+ header?: TaroGeneral.IAnyObject
44
+ /**
45
+ * cookies
46
+ * @supported weapp
47
+ * @weapp 非官方文档标注属性
48
+ */
49
+ cookies?: string[]
38
50
  }
39
51
  }
40
52
 
@@ -68,32 +80,55 @@ declare module '../../index' {
68
80
  totalBytesSent: number
69
81
  }
70
82
 
71
- type UploadTaskPromise = Promise<UploadTask> & {
83
+ type UploadTaskPromise = Promise<uploadFile.SuccessCallbackResult> & UploadTask & {
72
84
  headersReceive: UploadTask['onHeadersReceived'],
73
- progress: UploadTask['onProgressUpdate'],
74
- abort: UploadTask['abort']
85
+ progress: UploadTask['onProgressUpdate']
75
86
  }
76
87
  }
77
88
 
78
89
  /** 一个可以监听上传进度变化事件,以及取消上传任务的对象
90
+ * @supported weapp, swan, alipay, h5, rn, tt
91
+ * @example
92
+ * ```tsx
93
+ * const uploadTask = Taro.uploadFile({
94
+ * url: 'http://example.weixin.qq.com/upload', //仅为示例,非真实的接口地址
95
+ * filePath: tempFilePaths[0],
96
+ * name: 'file',
97
+ * formData:{
98
+ * 'user': 'test'
99
+ * },
100
+ * success (res){
101
+ * const data = res.data
102
+ * //do something
103
+ * }
104
+ * })
105
+ *
106
+ * uploadTask.onProgressUpdate((res) => {
107
+ * console.log('上传进度', res.progress)
108
+ * console.log('已经上传的数据长度', res.totalBytesSent)
109
+ * console.log('预期需要上传的数据总长度', res.totalBytesExpectedToSend)
110
+ * })
111
+ *
112
+ * uploadTask.abort() // 取消上传任务
113
+ * ```
79
114
  * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/upload/UploadTask.html
80
115
  */
81
116
  interface UploadTask {
82
117
  /** 中断上传任务
83
- * @supported weapp
118
+ * @supported weapp, h5, tt
84
119
  * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/upload/UploadTask.abort.html
85
120
  */
86
121
  abort(): void
87
- /** 取消监听 HTTP Response Header 事件
88
- * @supported weapp
89
- * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/upload/UploadTask.offHeadersReceived.html
122
+ /** 监听上传进度变化事件
123
+ * @supported weapp, h5, tt
124
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/upload/UploadTask.onProgressUpdate.html
90
125
  */
91
- offHeadersReceived(
92
- /** HTTP Response Header 事件的回调函数 */
93
- callback: UploadTask.OffHeadersReceivedCallback,
126
+ onProgressUpdate(
127
+ /** 上传进度变化事件的回调函数 */
128
+ callback: UploadTask.OnProgressUpdateCallback,
94
129
  ): void
95
130
  /** 取消监听上传进度变化事件
96
- * @supported weapp
131
+ * @supported weapp, h5, tt
97
132
  * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/upload/UploadTask.offProgressUpdate.html
98
133
  */
99
134
  offProgressUpdate(
@@ -101,34 +136,26 @@ declare module '../../index' {
101
136
  callback: UploadTask.OffProgressUpdateCallback,
102
137
  ): void
103
138
  /** 监听 HTTP Response Header 事件。会比请求完成事件更早
104
- * @supported weapp
139
+ * @supported weapp, h5
105
140
  * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/upload/UploadTask.onHeadersReceived.html
106
141
  */
107
142
  onHeadersReceived(
108
143
  /** HTTP Response Header 事件的回调函数 */
109
144
  callback: UploadTask.OnHeadersReceivedCallback,
110
145
  ): void
111
- headersReceived(
112
- /** HTTP Response Header 事件的回调函数 */
113
- callback: UploadTask.OnHeadersReceivedCallback,
114
- ): void
115
- /** 监听上传进度变化事件
116
- * @supported weapp
117
- * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/upload/UploadTask.onProgressUpdate.html
146
+ /** 取消监听 HTTP Response Header 事件
147
+ * @supported weapp, h5
148
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/upload/UploadTask.offHeadersReceived.html
118
149
  */
119
- onProgressUpdate(
120
- /** 上传进度变化事件的回调函数 */
121
- callback: UploadTask.OnProgressUpdateCallback,
122
- ): void
123
- progress(
124
- /** 上传进度变化事件的回调函数 */
125
- callback: UploadTask.OnProgressUpdateCallback,
150
+ offHeadersReceived(
151
+ /** HTTP Response Header 事件的回调函数 */
152
+ callback: UploadTask.OffHeadersReceivedCallback,
126
153
  ): void
127
154
  }
128
155
 
129
156
  interface TaroStatic {
130
157
  /** 将本地资源上传到服务器。客户端发起一个 HTTPS POST 请求,其中 `content-type` 为 `multipart/form-data`。使用前请注意阅读[相关说明](https://developers.weixin.qq.com/miniprogram/dev/framework/ability/network.html)。
131
- * @supported weapp, swan, alipay, h5
158
+ * @supported weapp, swan, alipay, h5, rn, tt
132
159
  * @example
133
160
  * ```tsx
134
161
  * Taro.chooseImage({
@@ -152,7 +179,7 @@ declare module '../../index' {
152
179
  * @example
153
180
  * ```tsx
154
181
  * const uploadTask = Taro.uploadFile({
155
- * url: 'http://example.weixin.qq.com/upload', //仅为示例,非真实的接口地址
182
+ * url: 'https://example.weixin.qq.com/upload', //仅为示例,非真实的接口地址
156
183
  * filePath: tempFilePaths[0],
157
184
  * name: 'file',
158
185
  * formData:{
@@ -137,17 +137,31 @@ declare module '../../index' {
137
137
  }
138
138
  }
139
139
 
140
- /** WebSocket 任务,可通过 [Taro.connectSocket()](https://developers.weixin.qq.com/miniprogram/dev/api/network/websocket/SocketTask.html) 接口创建返回。
140
+ /** WebSocket 任务,可通过 [Taro.connectSocket()](/docs/apis/network/websocket/SocketTask) 接口创建返回。
141
+ * @supported weapp, h5, rn, alipay, swan
141
142
  * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/websocket/SocketTask.html
142
143
  */
143
144
  interface SocketTask {
145
+ /** 通过 WebSocket 连接发送数据
146
+ * @supported weapp, h5, rn, alipay, swan, tt
147
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/websocket/SocketTask.send.html
148
+ */
149
+ send(option: SocketTask.SendOption): void
144
150
  /** 关闭 WebSocket 连接
145
- * @supported weapp, h5, rn, alipay, swan
151
+ * @supported weapp, h5, rn, alipay, swan, tt
146
152
  * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/websocket/SocketTask.close.html
147
153
  */
148
154
  close(option: SocketTask.CloseOption): void
155
+ /** 监听 WebSocket 连接打开事件
156
+ * @supported weapp, h5, rn, alipay, swan, tt
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
149
163
  /** 监听 WebSocket 连接关闭事件
150
- * @supported weapp, h5, rn, alipay, swan
164
+ * @supported weapp, h5, rn, alipay, swan, tt
151
165
  * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/websocket/SocketTask.onClose.html
152
166
  */
153
167
  onClose(
@@ -155,7 +169,7 @@ declare module '../../index' {
155
169
  callback: SocketTask.OnCloseCallback
156
170
  ): void
157
171
  /** 监听 WebSocket 错误事件
158
- * @supported weapp, h5, rn, alipay, swan
172
+ * @supported weapp, h5, rn, alipay, swan, tt
159
173
  * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/websocket/SocketTask.onError.html
160
174
  */
161
175
  onError(
@@ -163,26 +177,13 @@ declare module '../../index' {
163
177
  callback: SocketTask.OnErrorCallback
164
178
  ): void
165
179
  /** 监听 WebSocket 接受到服务器的消息事件
166
- * @supported weapp, h5, rn, alipay, swan
180
+ * @supported weapp, h5, rn, alipay, swan, tt
167
181
  * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/websocket/SocketTask.onMessage.html
168
182
  */
169
183
  onMessage<T = any>(
170
184
  /** WebSocket 接受到服务器的消息事件的回调函数 */
171
185
  callback: SocketTask.OnMessageCallback<T>
172
186
  ): void
173
- /** 监听 WebSocket 连接打开事件
174
- * @supported weapp, h5, rn, alipay, swan
175
- * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/websocket/SocketTask.onOpen.html
176
- */
177
- onOpen(
178
- /** WebSocket 连接打开事件的回调函数 */
179
- callback: SocketTask.OnOpenCallback
180
- ): void
181
- /** 通过 WebSocket 连接发送数据
182
- * @supported weapp, h5, rn, alipay, swan
183
- * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/websocket/SocketTask.send.html
184
- */
185
- send(option: SocketTask.SendOption): void
186
187
 
187
188
  /** websocket 当前的连接 ID。 */
188
189
  readonly socketTaskId: number
@@ -287,7 +288,7 @@ declare module '../../index' {
287
288
  */
288
289
  onSocketError(
289
290
  /** WebSocket 错误事件的回调函数 */
290
- callback: (result: onSocketError.Callback) => void
291
+ callback: onSocketError.Callback
291
292
  ): void
292
293
 
293
294
  /** 监听 WebSocket 连接关闭事件
@@ -35,7 +35,7 @@ declare module '../../index' {
35
35
 
36
36
  interface TaroStatic {
37
37
  /** 获取用户收货地址。调起用户编辑收货地址原生界面,并在编辑完成后返回用户选择的地址。
38
- * @supported weapp
38
+ * @supported weapp, tt
39
39
  * @example
40
40
  * ```tsx
41
41
  * Taro.chooseAddress({
@@ -1,9 +1,31 @@
1
1
  import Taro from '../../index'
2
2
 
3
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
+
4
26
  namespace authorize {
5
27
  interface Option {
6
- /** 需要获取权限的 scope,详见 [scope 列表]((authorize#scope-列表)) */
28
+ /** 需要获取权限的 scope,详见 [scope 列表](https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/authorize.html#scope-%E5%88%97%E8%A1%A8) */
7
29
  scope: string
8
30
  /** 接口调用结束的回调函数(调用成功、失败都会执行) */
9
31
  complete?: (res: TaroGeneral.CallbackResult) => void
@@ -15,11 +37,28 @@ declare module '../../index' {
15
37
  }
16
38
 
17
39
  interface TaroStatic {
18
- /** 提前向用户发起授权请求。调用后会立刻弹窗询问用户是否同意授权小程序使用某项功能或获取用户的某些数据,但不会实际调用对应接口。如果用户之前已经同意授权,则不会出现弹窗,直接返回成功。更多用法详见 [用户授权](https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/authorize.html)
40
+ /** **仅小程序插件中能调用该接口**,用法同 [Taro.authorize](../authorize)。目前仅支持三种 scope
19
41
  * @supported weapp
20
42
  * @example
21
43
  * ```tsx
22
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, rn, tt
59
+ * @example
60
+ * ```tsx
61
+ * // 可以通过 Taro.getSetting 先查询一下用户是否授权了 "scope.record" 这个 scope
23
62
  * Taro.getSetting({
24
63
  * success: function (res) {
25
64
  * if (!res.authSetting['scope.record']) {
@@ -36,6 +75,6 @@ declare module '../../index' {
36
75
  * ```
37
76
  * @see https://developers.weixin.qq.com/miniprogram/dev/api/open-api/authorize/wx.authorize.html
38
77
  */
39
- authorize(option: authorize.Option): Promise<TaroGeneral.CallbackResult>
78
+ authorize(option: authorize.Option): Promise<TaroGeneral.CallbackResult>
40
79
  }
41
80
  }