@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,196 @@
|
|
|
1
|
+
import Taro from '../../index'
|
|
2
|
+
|
|
3
|
+
declare module '../../index' {
|
|
4
|
+
namespace showTabBarRedDot {
|
|
5
|
+
interface Option {
|
|
6
|
+
/** tabBar 的哪一项,从左边算起 */
|
|
7
|
+
index: number
|
|
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 showTabBar {
|
|
18
|
+
interface Option {
|
|
19
|
+
/** 是否需要动画效果 */
|
|
20
|
+
animation?: boolean
|
|
21
|
+
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
|
|
22
|
+
complete?: (res: TaroGeneral.CallbackResult) => void
|
|
23
|
+
/** 接口调用失败的回调函数 */
|
|
24
|
+
fail?: (res: TaroGeneral.CallbackResult) => void
|
|
25
|
+
/** 接口调用成功的回调函数 */
|
|
26
|
+
success?: (res: TaroGeneral.CallbackResult) => void
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
namespace setTabBarStyle {
|
|
31
|
+
interface Option {
|
|
32
|
+
/** tab 的背景色,HexColor */
|
|
33
|
+
backgroundColor?: string
|
|
34
|
+
/** tabBar上边框的颜色, 仅支持 black/white */
|
|
35
|
+
borderStyle?: string
|
|
36
|
+
/** tab 上的文字默认颜色,HexColor */
|
|
37
|
+
color?: string
|
|
38
|
+
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
|
|
39
|
+
complete?: (res: TaroGeneral.CallbackResult) => void
|
|
40
|
+
/** 接口调用失败的回调函数 */
|
|
41
|
+
fail?: (res: TaroGeneral.CallbackResult) => void
|
|
42
|
+
/** tab 上的文字选中时的颜色,HexColor */
|
|
43
|
+
selectedColor?: string
|
|
44
|
+
/** 接口调用成功的回调函数 */
|
|
45
|
+
success?: (res: TaroGeneral.CallbackResult) => void
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
namespace setTabBarItem {
|
|
50
|
+
interface Option {
|
|
51
|
+
/** tabBar 的哪一项,从左边算起 */
|
|
52
|
+
index: number
|
|
53
|
+
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
|
|
54
|
+
complete?: (res: TaroGeneral.CallbackResult) => void
|
|
55
|
+
/** 接口调用失败的回调函数 */
|
|
56
|
+
fail?: (res: TaroGeneral.CallbackResult) => void
|
|
57
|
+
/** 图片路径,icon 大小限制为 40kb,建议尺寸为 81px * 81px,当 postion 为 top 时,此参数无效 */
|
|
58
|
+
iconPath?: string
|
|
59
|
+
/** 选中时的图片路径,icon 大小限制为 40kb,建议尺寸为 81px * 81px ,当 postion 为 top 时,此参数无效 */
|
|
60
|
+
selectedIconPath?: string
|
|
61
|
+
/** 接口调用成功的回调函数 */
|
|
62
|
+
success?: (res: TaroGeneral.CallbackResult) => void
|
|
63
|
+
/** tab 上的按钮文字 */
|
|
64
|
+
text?: string
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
namespace setTabBarBadge {
|
|
69
|
+
interface Option {
|
|
70
|
+
/** tabBar 的哪一项,从左边算起 */
|
|
71
|
+
index: number
|
|
72
|
+
/** 显示的文本,超过 4 个字符则显示成 ... */
|
|
73
|
+
text: string
|
|
74
|
+
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
|
|
75
|
+
complete?: (res: TaroGeneral.CallbackResult) => void
|
|
76
|
+
/** 接口调用失败的回调函数 */
|
|
77
|
+
fail?: (res: TaroGeneral.CallbackResult) => void
|
|
78
|
+
/** 接口调用成功的回调函数 */
|
|
79
|
+
success?: (res: TaroGeneral.CallbackResult) => void
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
namespace removeTabBarBadge {
|
|
84
|
+
interface Option {
|
|
85
|
+
/** tabBar 的哪一项,从左边算起 */
|
|
86
|
+
index: number
|
|
87
|
+
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
|
|
88
|
+
complete?: (res: TaroGeneral.CallbackResult) => void
|
|
89
|
+
/** 接口调用失败的回调函数 */
|
|
90
|
+
fail?: (res: TaroGeneral.CallbackResult) => void
|
|
91
|
+
/** 接口调用成功的回调函数 */
|
|
92
|
+
success?: (res: TaroGeneral.CallbackResult) => void
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
namespace hideTabBarRedDot {
|
|
97
|
+
interface Option {
|
|
98
|
+
/** tabBar 的哪一项,从左边算起 */
|
|
99
|
+
index: number
|
|
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 hideTabBar {
|
|
110
|
+
interface Option {
|
|
111
|
+
/** 是否需要动画效果 */
|
|
112
|
+
animation?: boolean
|
|
113
|
+
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
|
|
114
|
+
complete?: (res: TaroGeneral.CallbackResult) => void
|
|
115
|
+
/** 接口调用失败的回调函数 */
|
|
116
|
+
fail?: (res: TaroGeneral.CallbackResult) => void
|
|
117
|
+
/** 接口调用成功的回调函数 */
|
|
118
|
+
success?: (res: TaroGeneral.CallbackResult) => void
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
interface TaroStatic {
|
|
123
|
+
/** 显示 tabBar 某一项的右上角的红点
|
|
124
|
+
* @supported weapp, h5, rn, tt, harmony_hybrid
|
|
125
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/ui/tab-bar/wx.showTabBarRedDot.html
|
|
126
|
+
*/
|
|
127
|
+
showTabBarRedDot(option: showTabBarRedDot.Option): Promise<TaroGeneral.CallbackResult>
|
|
128
|
+
|
|
129
|
+
/** 显示 tabBar
|
|
130
|
+
* @supported weapp, h5, rn, tt, harmony_hybrid
|
|
131
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/ui/tab-bar/wx.showTabBar.html
|
|
132
|
+
*/
|
|
133
|
+
showTabBar(option?: showTabBar.Option): Promise<TaroGeneral.CallbackResult>
|
|
134
|
+
|
|
135
|
+
/** 动态设置 tabBar 的整体样式
|
|
136
|
+
* @supported weapp, h5, rn, tt, harmony_hybrid
|
|
137
|
+
* @example
|
|
138
|
+
* ```tsx
|
|
139
|
+
* Taro.setTabBarStyle({
|
|
140
|
+
* color: '#FF0000',
|
|
141
|
+
* selectedColor: '#00FF00',
|
|
142
|
+
* backgroundColor: '#0000FF',
|
|
143
|
+
* borderStyle: 'white'
|
|
144
|
+
* })
|
|
145
|
+
* ```
|
|
146
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/ui/tab-bar/wx.setTabBarStyle.html
|
|
147
|
+
*/
|
|
148
|
+
setTabBarStyle(option?: setTabBarStyle.Option): Promise<TaroGeneral.CallbackResult>
|
|
149
|
+
|
|
150
|
+
/** 动态设置 tabBar 某一项的内容,`2.7.0` 起图片支持临时文件和网络文件。
|
|
151
|
+
* @supported weapp, h5, rn, tt, harmony_hybrid
|
|
152
|
+
* @example
|
|
153
|
+
* ```tsx
|
|
154
|
+
* Taro.setTabBarItem({
|
|
155
|
+
* index: 0,
|
|
156
|
+
* text: 'text',
|
|
157
|
+
* iconPath: '/path/to/iconPath',
|
|
158
|
+
* selectedIconPath: '/path/to/selectedIconPath'
|
|
159
|
+
* })
|
|
160
|
+
* ```
|
|
161
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/ui/tab-bar/wx.setTabBarItem.html
|
|
162
|
+
*/
|
|
163
|
+
setTabBarItem(option: setTabBarItem.Option): Promise<TaroGeneral.CallbackResult>
|
|
164
|
+
|
|
165
|
+
/** 为 tabBar 某一项的右上角添加文本
|
|
166
|
+
* @supported weapp, h5, rn, tt, harmony_hybrid
|
|
167
|
+
* @example
|
|
168
|
+
* ```tsx
|
|
169
|
+
* Taro.setTabBarBadge({
|
|
170
|
+
* index: 0,
|
|
171
|
+
* text: '1'
|
|
172
|
+
* })
|
|
173
|
+
* ```
|
|
174
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/ui/tab-bar/wx.setTabBarBadge.html
|
|
175
|
+
*/
|
|
176
|
+
setTabBarBadge(option: setTabBarBadge.Option): Promise<TaroGeneral.CallbackResult>
|
|
177
|
+
|
|
178
|
+
/** 移除 tabBar 某一项右上角的文本
|
|
179
|
+
* @supported weapp, h5, rn, tt, harmony_hybrid
|
|
180
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/ui/tab-bar/wx.removeTabBarBadge.html
|
|
181
|
+
*/
|
|
182
|
+
removeTabBarBadge(option: removeTabBarBadge.Option): Promise<TaroGeneral.CallbackResult>
|
|
183
|
+
|
|
184
|
+
/** 隐藏 tabBar 某一项的右上角的红点
|
|
185
|
+
* @supported weapp, h5, rn, tt, harmony_hybrid
|
|
186
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/ui/tab-bar/wx.hideTabBarRedDot.html
|
|
187
|
+
*/
|
|
188
|
+
hideTabBarRedDot(option: hideTabBarRedDot.Option): Promise<TaroGeneral.CallbackResult>
|
|
189
|
+
|
|
190
|
+
/** 隐藏 tabBar
|
|
191
|
+
* @supported weapp, h5, rn, tt, harmony_hybrid
|
|
192
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/ui/tab-bar/wx.hideTabBar.html
|
|
193
|
+
*/
|
|
194
|
+
hideTabBar(option?: hideTabBar.Option): Promise<TaroGeneral.CallbackResult>
|
|
195
|
+
}
|
|
196
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import Taro from '../../index'
|
|
2
|
+
|
|
3
|
+
declare module '../../index' {
|
|
4
|
+
namespace setWindowSize {
|
|
5
|
+
interface Option {
|
|
6
|
+
/** 窗口宽度,以像素为单位 */
|
|
7
|
+
width: string
|
|
8
|
+
/** 窗口高度,以像素为单位 */
|
|
9
|
+
height: string
|
|
10
|
+
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
|
|
11
|
+
complete?: (res: TaroGeneral.CallbackResult) => void
|
|
12
|
+
/** 接口调用失败的回调函数 */
|
|
13
|
+
fail?: (res: TaroGeneral.CallbackResult) => void
|
|
14
|
+
/** 接口调用成功的回调函数 */
|
|
15
|
+
success?: (res: TaroGeneral.CallbackResult) => void
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
namespace onWindowResize {
|
|
19
|
+
/** 窗口尺寸变化事件的回调函数 */
|
|
20
|
+
type Callback = (result: CallbackResult) => void
|
|
21
|
+
|
|
22
|
+
interface CallbackResult {
|
|
23
|
+
size: Size
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
interface Size {
|
|
27
|
+
/** 变化后的窗口高度,单位 px */
|
|
28
|
+
windowHeight: number
|
|
29
|
+
/** 变化后的窗口宽度,单位 px */
|
|
30
|
+
windowWidth: number
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
namespace offWindowResize {
|
|
35
|
+
/** 窗口尺寸变化事件的回调函数 */
|
|
36
|
+
type Callback = (res: TaroGeneral.CallbackResult) => void
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
interface TaroStatic {
|
|
40
|
+
/** 设置窗口大小,该接口仅适用于 PC 平台,使用细则请参见指南
|
|
41
|
+
* @supported weapp
|
|
42
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/ui/window/wx.setWindowSize.html
|
|
43
|
+
*/
|
|
44
|
+
setWindowSize(option: setWindowSize.Option): Promise<TaroGeneral.CallbackResult>
|
|
45
|
+
|
|
46
|
+
/** 监听窗口尺寸变化事件
|
|
47
|
+
* @supported weapp, h5, rn, harmony_hybrid
|
|
48
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/ui/window/wx.onWindowResize.html
|
|
49
|
+
*/
|
|
50
|
+
onWindowResize(
|
|
51
|
+
/** 窗口尺寸变化事件的回调函数 */
|
|
52
|
+
callback: onWindowResize.Callback,
|
|
53
|
+
): void
|
|
54
|
+
|
|
55
|
+
/** 取消监听窗口尺寸变化事件
|
|
56
|
+
* @supported weapp, h5, rn, harmony_hybrid
|
|
57
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/ui/window/wx.offWindowResize.html
|
|
58
|
+
*/
|
|
59
|
+
offWindowResize(
|
|
60
|
+
/** 窗口尺寸变化事件的回调函数 */
|
|
61
|
+
callback: offWindowResize.Callback,
|
|
62
|
+
): void
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* 返回当前是否存在小窗播放(小窗在 video/live-player/live-pusher 下可用)
|
|
66
|
+
* @supported weapp
|
|
67
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/ui/window/wx.checkIsPictureInPictureActive.html
|
|
68
|
+
*/
|
|
69
|
+
checkIsPictureInPictureActive(): boolean
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import Taro from '../../index'
|
|
2
|
+
|
|
3
|
+
declare module '../../index' {
|
|
4
|
+
namespace Worker {
|
|
5
|
+
type OnMessageCallback = (
|
|
6
|
+
result: OnMessageCallbackResult,
|
|
7
|
+
) => void
|
|
8
|
+
interface OnMessageCallbackResult {
|
|
9
|
+
/** 主线程/Worker 线程向当前线程发送的消息 */
|
|
10
|
+
message: TaroGeneral.IAnyObject
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
interface Worker {
|
|
14
|
+
/** 监听主线程/Worker 线程向当前线程发送的消息的事件。
|
|
15
|
+
* @supported weapp
|
|
16
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/worker/Worker.onMessage.html
|
|
17
|
+
*/
|
|
18
|
+
onMessage(
|
|
19
|
+
/** 主线程/Worker 线程向当前线程发送的消息的事件的回调函数 */
|
|
20
|
+
callback: Worker.OnMessageCallback,
|
|
21
|
+
): void
|
|
22
|
+
/** 监听 worker 线程被系统回收事件(当 iOS 系统资源紧张时,worker 线程存在被系统回收的可能,开发者可监听此事件并重新创建一个 worker)
|
|
23
|
+
* @supported weapp
|
|
24
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/worker/Worker.onProcessKilled.html
|
|
25
|
+
*/
|
|
26
|
+
onProcessKilled(
|
|
27
|
+
/** worker 线程被系统回收事件的回调函数 */
|
|
28
|
+
callback: Worker.OnMessageCallback,
|
|
29
|
+
): void
|
|
30
|
+
/** 向主线程/Worker 线程发送的消息。
|
|
31
|
+
* @supported weapp
|
|
32
|
+
* @example
|
|
33
|
+
* worker 线程中
|
|
34
|
+
*
|
|
35
|
+
* ```tsx
|
|
36
|
+
* worker.postMessage({
|
|
37
|
+
* msg: 'hello from worker'
|
|
38
|
+
* })
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
* 主线程中
|
|
42
|
+
*
|
|
43
|
+
* ```tsx
|
|
44
|
+
* const worker = Taro.createWorker('workers/request/index.js')
|
|
45
|
+
* worker.postMessage({
|
|
46
|
+
* msg: 'hello from main'
|
|
47
|
+
* })
|
|
48
|
+
* ```
|
|
49
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/worker/Worker.postMessage.html
|
|
50
|
+
*/
|
|
51
|
+
postMessage(
|
|
52
|
+
/** 需要发送的消息,必须是一个可序列化的 JavaScript key-value 形式的对象。 */
|
|
53
|
+
message: TaroGeneral.IAnyObject,
|
|
54
|
+
): void
|
|
55
|
+
/** 结束当前 Worker 线程。仅限在主线程 worker 对象上调用。
|
|
56
|
+
* @supported weapp
|
|
57
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/worker/Worker.terminate.html
|
|
58
|
+
*/
|
|
59
|
+
terminate(): void
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
interface TaroStatic {
|
|
63
|
+
/** 创建一个 Worker 线程。目前限制最多只能创建一个 Worker,创建下一个 Worker 前请先调用 [Worker.terminate](/docs/apis/worker/#terminate)
|
|
64
|
+
* @supported weapp
|
|
65
|
+
* @example
|
|
66
|
+
* ```tsx
|
|
67
|
+
* const worker = Taro.createWorker('workers/request/index.js') // 文件名指定 worker 的入口文件路径,绝对路径
|
|
68
|
+
* worker.onMessage(function (res) {
|
|
69
|
+
* console.log(res)
|
|
70
|
+
* })
|
|
71
|
+
* worker.postMessage({
|
|
72
|
+
* msg: 'hello worker'
|
|
73
|
+
* })
|
|
74
|
+
* worker.terminate()
|
|
75
|
+
* ```
|
|
76
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api/worker/wx.createWorker.html
|
|
77
|
+
*/
|
|
78
|
+
createWorker(
|
|
79
|
+
/** worker 入口文件的**绝对路径** */
|
|
80
|
+
scriptPath: string,
|
|
81
|
+
): Worker
|
|
82
|
+
}
|
|
83
|
+
}
|