@tarojs/taro-h5 3.3.13 → 3.3.17
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/dist/index.cjs.js +6134 -8352
- package/dist/index.js +9044 -0
- package/dist/taroApis.js +1 -1
- package/package.json +9 -9
- package/src/api/ad/index.ts +5 -0
- package/src/api/ai/facial.ts +6 -0
- package/src/api/ai/index.ts +2 -0
- package/src/api/ai/visual.ts +4 -0
- package/src/api/alipay/index.ts +4 -0
- package/src/api/base/crypto.ts +4 -0
- package/src/api/base/debug.ts +5 -0
- package/src/api/base/index.ts +23 -0
- package/src/api/base/performance.ts +5 -0
- package/src/api/base/system/index.ts +2 -0
- package/src/api/base/system/info.ts +64 -0
- package/src/api/base/system/network.ts +70 -0
- package/src/api/base/update.ts +5 -0
- package/src/api/base/weapp/app-event.ts +19 -0
- package/src/api/base/weapp/life-cycle.ts +5 -0
- package/src/api/canvas/CanvasContext.ts +230 -0
- package/src/api/canvas/canvasGetImageData.ts +29 -0
- package/src/api/canvas/canvasPutImageData.ts +26 -0
- package/src/api/canvas/canvasToTempFilePath.ts +26 -0
- package/src/api/canvas/createCanvasContext.ts +20 -0
- package/src/api/canvas/{index.js → index.ts} +9 -3
- package/src/api/cloud/index.ts +27 -0
- package/src/api/data-analysis/index.ts +6 -0
- package/src/api/device/accelerometer.ts +89 -0
- package/src/api/device/accessibility.ts +4 -0
- package/src/api/device/battery.ts +5 -0
- package/src/api/device/bluetooth-ble.ts +19 -0
- package/src/api/device/bluetooth-peripheral.ts +6 -0
- package/src/api/device/bluetooth.ts +16 -0
- package/src/api/device/calendar.ts +5 -0
- package/src/api/device/clipboard.ts +67 -0
- package/src/api/device/compass.ts +74 -0
- package/src/api/device/contact.ts +5 -0
- package/src/api/device/crypto.ts +4 -0
- package/src/api/device/gyroscope.ts +7 -0
- package/src/api/device/iBeacon.ts +10 -0
- package/src/api/device/index.ts +22 -0
- package/src/api/device/keyboard.ts +7 -0
- package/src/api/device/memory.ts +5 -0
- package/src/api/device/motion.ts +92 -0
- package/src/api/device/nfc.ts +10 -0
- package/src/api/device/phone.ts +30 -0
- package/src/api/device/scan.ts +7 -0
- package/src/api/device/screen.ts +9 -0
- package/src/api/device/vibrate.ts +36 -0
- package/src/api/device/wifi.ts +13 -0
- package/src/api/ext/index.ts +5 -0
- package/src/api/files/index.ts +11 -0
- package/src/api/framework/index.ts +10 -0
- package/src/api/index.ts +25 -0
- package/src/api/location/chooseLocation.ts +106 -0
- package/src/api/location/index.ts +19 -0
- package/src/api/location/style.css +8 -8
- package/src/api/media/audio/index.ts +99 -0
- package/src/api/media/background-audio.ts +12 -0
- package/src/api/media/camera.ts +4 -0
- package/src/api/media/editor.ts +29 -0
- package/src/api/media/image/chooseImage.ts +80 -0
- package/src/api/{image → media/image}/getImageInfo.js +0 -0
- package/src/api/media/image/index.ts +13 -0
- package/src/api/{image → media/image}/previewImage.js +4 -0
- package/src/api/media/index.ts +13 -0
- package/src/api/media/live.ts +5 -0
- package/src/api/media/map.ts +4 -0
- package/src/api/media/media-recorder.ts +4 -0
- package/src/api/media/recorder.ts +6 -0
- package/src/api/media/video/index.ts +82 -0
- package/src/api/media/video-decoder.ts +4 -0
- package/src/api/media/video-processing.ts +4 -0
- package/src/api/media/voip.ts +17 -0
- package/src/api/navigate/index.ts +7 -0
- package/src/api/{fileTransfer/downloadFile.js → network/download.ts} +16 -25
- package/src/api/network/index.ts +7 -0
- package/src/api/network/mdns.ts +13 -0
- package/src/api/{request/index.js → network/request/index.ts} +9 -6
- package/src/api/network/tcp.ts +4 -0
- package/src/api/network/udp.ts +4 -0
- package/src/api/{fileTransfer/uploadFile.js → network/upload.ts} +28 -30
- package/src/api/{fileTransfer/utils.js → network/utils.ts} +0 -0
- package/src/api/{webSocket/index.js → network/websocket/index.ts} +50 -57
- package/src/api/{webSocket/socketTask.js → network/websocket/socketTask.ts} +16 -6
- package/src/api/open-api/account.ts +4 -0
- package/src/api/open-api/address.ts +4 -0
- package/src/api/open-api/authorize.ts +5 -0
- package/src/api/open-api/card.ts +5 -0
- package/src/api/open-api/channels-live.ts +9 -0
- package/src/api/open-api/customer-service.ts +4 -0
- package/src/api/open-api/facial.ts +7 -0
- package/src/api/open-api/favorites.ts +5 -0
- package/src/api/open-api/group.ts +4 -0
- package/src/api/open-api/index.ts +18 -0
- package/src/api/open-api/invoice.ts +5 -0
- package/src/api/open-api/license-plate.ts +4 -0
- package/src/api/open-api/login.ts +6 -0
- package/src/api/open-api/red-package.ts +4 -0
- package/src/api/open-api/settings.ts +5 -0
- package/src/api/open-api/soter.ts +6 -0
- package/src/api/open-api/subscribe-message.ts +4 -0
- package/src/api/open-api/user-info.ts +5 -0
- package/src/api/open-api/werun.ts +5 -0
- package/src/api/payment/index.ts +5 -0
- package/src/api/route/index.ts +10 -0
- package/src/api/share/index.ts +13 -0
- package/src/api/storage/background-fetch.ts +7 -0
- package/src/api/storage/index.ts +193 -0
- package/src/api/swan/index.ts +31 -0
- package/src/{taro/index.js → api/taro.ts} +133 -149
- package/src/api/{createAnimation/index.js → ui/animation/index.ts} +26 -14
- package/src/api/ui/background.ts +5 -0
- package/src/api/ui/custom-component.ts +4 -0
- package/src/api/ui/fonts.ts +4 -0
- package/src/api/ui/index.ts +12 -0
- package/src/api/ui/interaction/actionSheet.ts +212 -0
- package/src/api/{interactive/index.js → ui/interaction/index.ts} +102 -90
- package/src/api/ui/interaction/modal.ts +237 -0
- package/src/api/{interactive/toast.js → ui/interaction/toast.ts} +35 -33
- package/src/api/ui/menu.ts +4 -0
- package/src/api/ui/navigation-bar/index.ts +52 -0
- package/src/api/ui/pull-down-refresh.ts +32 -0
- package/src/api/{scroll/index.js → ui/scroll/index.ts} +16 -28
- package/src/api/ui/sticky.ts +4 -0
- package/src/api/ui/tab-bar.ts +326 -0
- package/src/api/ui/window.ts +37 -0
- package/src/api/utils/handler.ts +105 -0
- package/src/api/utils/{index.js → index.ts} +24 -87
- package/src/api/worker/index.ts +4 -0
- package/src/api/wxml/index.ts +9 -0
- package/src/api/{createSelectorQuery/index.js → wxml/selectorQuery.ts} +86 -59
- package/src/index.ts +6 -0
- package/src/types/api.d.ts +4 -0
- package/src/types/define.d.ts +2 -0
- package/{types → src/types}/index.d.ts +0 -0
- package/{types → src/types}/type.ts +1 -1
- package/src/api/accelerometer/index.js +0 -105
- package/src/api/audio/index.js +0 -137
- package/src/api/canvas/canvasGetImageData.js +0 -44
- package/src/api/canvas/canvasPutImageData.js +0 -45
- package/src/api/canvas/canvasToTempFilePath.js +0 -49
- package/src/api/canvas/createCanvasContext.js +0 -340
- package/src/api/clipboard/index.js +0 -113
- package/src/api/compass/index.js +0 -99
- package/src/api/deviceMotion/index.js +0 -105
- package/src/api/fileTransfer/index.js +0 -2
- package/src/api/image/chooseImage.js +0 -87
- package/src/api/image/index.js +0 -7
- package/src/api/index.js +0 -29
- package/src/api/interactive/actionSheet.js +0 -214
- package/src/api/interactive/modal.js +0 -256
- package/src/api/location/chooseLocation.js +0 -143
- package/src/api/location/index.js +0 -5
- package/src/api/navigationBar/index.js +0 -57
- package/src/api/open/index.js +0 -5
- package/src/api/others/index.js +0 -43
- package/src/api/pullDownRefresh/index.js +0 -51
- package/src/api/storage/index.js +0 -211
- package/src/api/system/index.js +0 -9
- package/src/api/system/info.js +0 -36
- package/src/api/system/network.js +0 -68
- package/src/api/tabBar/index.js +0 -424
- package/src/api/unsupportedApi/index.js +0 -278
- package/src/api/vibrate/index.js +0 -49
- package/src/api/video/index.js +0 -87
- package/src/api/window/index.js +0 -38
- package/src/index.cjs.js +0 -11
- package/src/index.js +0 -6
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
import Taro, { AppConfig } from '@tarojs/api'
|
|
2
|
+
import { shouldBeObject, getParameterError, isValidColor } from '../utils'
|
|
3
|
+
import { MethodHandler } from '../utils/handler'
|
|
4
|
+
|
|
5
|
+
let tabConf
|
|
6
|
+
|
|
7
|
+
export function initTabBarApis (config: AppConfig = {}) {
|
|
8
|
+
tabConf = config.tabBar
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* 显示 tabBar 某一项的右上角的红点
|
|
13
|
+
*/
|
|
14
|
+
export const showTabBarRedDot: typeof Taro.showTabBarRedDot = (options) => {
|
|
15
|
+
// options must be an Object
|
|
16
|
+
const isObject = shouldBeObject(options)
|
|
17
|
+
if (!isObject.flag) {
|
|
18
|
+
const res = { errMsg: `showTabBarRedDot:fail ${isObject.msg}` }
|
|
19
|
+
console.error(res.errMsg)
|
|
20
|
+
return Promise.reject(res)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const {
|
|
24
|
+
index,
|
|
25
|
+
success,
|
|
26
|
+
fail,
|
|
27
|
+
complete
|
|
28
|
+
} = options
|
|
29
|
+
const handle = new MethodHandler({ name: 'showTabBarRedDot', success, fail, complete })
|
|
30
|
+
|
|
31
|
+
if (typeof index !== 'number') {
|
|
32
|
+
return handle.fail({
|
|
33
|
+
errMsg: getParameterError({
|
|
34
|
+
para: 'index',
|
|
35
|
+
correct: 'Number',
|
|
36
|
+
wrong: index
|
|
37
|
+
})
|
|
38
|
+
})
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return new Promise((resolve, reject) => {
|
|
42
|
+
Taro.eventCenter.trigger('__taroShowTabBarRedDotHandler', {
|
|
43
|
+
index,
|
|
44
|
+
successHandler: (res = {}) => handle.success(res, resolve as any),
|
|
45
|
+
errorHandler: (res = {}) => handle.fail(res, reject as any)
|
|
46
|
+
})
|
|
47
|
+
})
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* 显示 tabBar
|
|
52
|
+
*/
|
|
53
|
+
export const showTabBar: typeof Taro.showTabBar = (options = {}) => {
|
|
54
|
+
// options must be an Object
|
|
55
|
+
const isObject = shouldBeObject(options)
|
|
56
|
+
if (!isObject.flag) {
|
|
57
|
+
const res = { errMsg: `showTabBar:fail ${isObject.msg}` }
|
|
58
|
+
console.error(res.errMsg)
|
|
59
|
+
return Promise.reject(res)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const { animation, success, fail, complete } = options
|
|
63
|
+
const handle = new MethodHandler({ name: 'showTabBar', success, fail, complete })
|
|
64
|
+
|
|
65
|
+
if (options.hasOwnProperty('animation') && typeof animation !== 'boolean') {
|
|
66
|
+
return handle.fail({
|
|
67
|
+
errMsg: getParameterError({
|
|
68
|
+
para: 'animation',
|
|
69
|
+
correct: 'Boolean',
|
|
70
|
+
wrong: animation
|
|
71
|
+
})
|
|
72
|
+
})
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return new Promise((resolve, reject) => {
|
|
76
|
+
Taro.eventCenter.trigger('__taroShowTabBar', {
|
|
77
|
+
animation,
|
|
78
|
+
successHandler: (res = {}) => handle.success(res, resolve as any),
|
|
79
|
+
errorHandler: (res = {}) => handle.fail(res, reject as any)
|
|
80
|
+
})
|
|
81
|
+
})
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* 动态设置 tabBar 的整体样式
|
|
86
|
+
*/
|
|
87
|
+
export const setTabBarStyle: typeof Taro.setTabBarStyle = (options = {}) => {
|
|
88
|
+
// options must be an Object
|
|
89
|
+
const isObject = shouldBeObject(options)
|
|
90
|
+
if (!isObject.flag) {
|
|
91
|
+
const res = { errMsg: `setTabBarStyle:fail ${isObject.msg}` }
|
|
92
|
+
console.error(res.errMsg)
|
|
93
|
+
return Promise.reject(res)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const { color, selectedColor, backgroundColor, borderStyle, success, fail, complete } = options
|
|
97
|
+
const handle = new MethodHandler({ name: 'setTabBarStyle', success, fail, complete })
|
|
98
|
+
|
|
99
|
+
let errMsg
|
|
100
|
+
if (color && !isValidColor(color)) {
|
|
101
|
+
errMsg = 'color'
|
|
102
|
+
} else if (selectedColor && !isValidColor(selectedColor)) {
|
|
103
|
+
errMsg = 'selectedColor'
|
|
104
|
+
} else if (backgroundColor && !isValidColor(backgroundColor)) {
|
|
105
|
+
errMsg = 'backgroundColor'
|
|
106
|
+
} else if (borderStyle && !/^(black|white)$/.test(borderStyle)) {
|
|
107
|
+
errMsg = 'borderStyle'
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (errMsg) {
|
|
111
|
+
return handle.fail({ errMsg: `invalid ${errMsg}` })
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (!tabConf) {
|
|
115
|
+
return handle.fail()
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const obj: Taro.setTabBarStyle.Option = {}
|
|
119
|
+
if (color) obj.color = color
|
|
120
|
+
if (selectedColor) obj.selectedColor = selectedColor
|
|
121
|
+
if (backgroundColor) obj.backgroundColor = backgroundColor
|
|
122
|
+
if (borderStyle) obj.borderStyle = borderStyle
|
|
123
|
+
|
|
124
|
+
return new Promise((resolve, reject) => {
|
|
125
|
+
Taro.eventCenter.trigger('__taroSetTabBarStyle', {
|
|
126
|
+
color,
|
|
127
|
+
selectedColor,
|
|
128
|
+
backgroundColor,
|
|
129
|
+
borderStyle,
|
|
130
|
+
successHandler: (res = {}) => handle.success(res, resolve as any),
|
|
131
|
+
errorHandler: (res = {}) => handle.fail(res, reject as any)
|
|
132
|
+
})
|
|
133
|
+
})
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* 动态设置 tabBar 某一项的内容
|
|
138
|
+
*/
|
|
139
|
+
export const setTabBarItem: typeof Taro.setTabBarItem = (options) => {
|
|
140
|
+
// options must be an Object
|
|
141
|
+
const isObject = shouldBeObject(options)
|
|
142
|
+
if (!isObject.flag) {
|
|
143
|
+
const res = { errMsg: `setTabBarItem:fail ${isObject.msg}` }
|
|
144
|
+
console.error(res.errMsg)
|
|
145
|
+
return Promise.reject(res)
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const {
|
|
149
|
+
index,
|
|
150
|
+
text,
|
|
151
|
+
iconPath,
|
|
152
|
+
selectedIconPath,
|
|
153
|
+
success,
|
|
154
|
+
fail,
|
|
155
|
+
complete
|
|
156
|
+
} = options
|
|
157
|
+
const handle = new MethodHandler({ name: 'setTabBarItem', success, fail, complete })
|
|
158
|
+
|
|
159
|
+
if (typeof index !== 'number') {
|
|
160
|
+
return handle.fail({
|
|
161
|
+
errMsg: getParameterError({
|
|
162
|
+
para: 'index',
|
|
163
|
+
correct: 'Number',
|
|
164
|
+
wrong: index
|
|
165
|
+
})
|
|
166
|
+
})
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
return new Promise((resolve, reject) => {
|
|
170
|
+
Taro.eventCenter.trigger('__taroSetTabBarItem', {
|
|
171
|
+
index,
|
|
172
|
+
text,
|
|
173
|
+
iconPath,
|
|
174
|
+
selectedIconPath,
|
|
175
|
+
successHandler: (res = {}) => handle.success(res, resolve as any),
|
|
176
|
+
errorHandler: (res = {}) => handle.fail(res, reject as any)
|
|
177
|
+
})
|
|
178
|
+
})
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* 为 tabBar 某一项的右上角添加文本
|
|
183
|
+
*/
|
|
184
|
+
export const setTabBarBadge: typeof Taro.setTabBarBadge = (options) => {
|
|
185
|
+
// options must be an Object
|
|
186
|
+
const isObject = shouldBeObject(options)
|
|
187
|
+
if (!isObject.flag) {
|
|
188
|
+
const res = { errMsg: `setTabBarBadge:fail ${isObject.msg}` }
|
|
189
|
+
console.error(res.errMsg)
|
|
190
|
+
return Promise.reject(res)
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const { index, text, success, fail, complete } = options
|
|
194
|
+
const handle = new MethodHandler({ name: 'setTabBarBadge', success, fail, complete })
|
|
195
|
+
|
|
196
|
+
if (typeof index !== 'number') {
|
|
197
|
+
return handle.fail({
|
|
198
|
+
errMsg: getParameterError({
|
|
199
|
+
para: 'index',
|
|
200
|
+
correct: 'Number',
|
|
201
|
+
wrong: index
|
|
202
|
+
})
|
|
203
|
+
})
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
if (typeof text !== 'string') {
|
|
207
|
+
return handle.fail({
|
|
208
|
+
errMsg: getParameterError({
|
|
209
|
+
para: 'text',
|
|
210
|
+
correct: 'String',
|
|
211
|
+
wrong: text
|
|
212
|
+
})
|
|
213
|
+
})
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
return new Promise((resolve, reject) => {
|
|
217
|
+
Taro.eventCenter.trigger('__taroSetTabBarBadge', {
|
|
218
|
+
index,
|
|
219
|
+
text,
|
|
220
|
+
successHandler: (res = {}) => handle.success(res, resolve as any),
|
|
221
|
+
errorHandler: (res = {}) => handle.fail(res, reject as any)
|
|
222
|
+
})
|
|
223
|
+
})
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* 移除 tabBar 某一项右上角的文本
|
|
228
|
+
*/
|
|
229
|
+
export const removeTabBarBadge: typeof Taro.removeTabBarBadge = (options) => {
|
|
230
|
+
// options must be an Object
|
|
231
|
+
const isObject = shouldBeObject(options)
|
|
232
|
+
if (!isObject.flag) {
|
|
233
|
+
const res = { errMsg: `removeTabBarBadge:fail ${isObject.msg}` }
|
|
234
|
+
console.error(res.errMsg)
|
|
235
|
+
return Promise.reject(res)
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
const { index, success, fail, complete } = options
|
|
239
|
+
const handle = new MethodHandler({ name: 'removeTabBarBadge', success, fail, complete })
|
|
240
|
+
|
|
241
|
+
if (typeof index !== 'number') {
|
|
242
|
+
return handle.fail({
|
|
243
|
+
errMsg: getParameterError({
|
|
244
|
+
para: 'index',
|
|
245
|
+
correct: 'Number',
|
|
246
|
+
wrong: index
|
|
247
|
+
})
|
|
248
|
+
})
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
return new Promise((resolve, reject) => {
|
|
252
|
+
Taro.eventCenter.trigger('__taroRemoveTabBarBadge', {
|
|
253
|
+
index,
|
|
254
|
+
successHandler: (res = {}) => handle.success(res, resolve as any),
|
|
255
|
+
errorHandler: (res = {}) => handle.fail(res, reject as any)
|
|
256
|
+
})
|
|
257
|
+
})
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* 隐藏 tabBar 某一项的右上角的红点
|
|
262
|
+
*/
|
|
263
|
+
export const hideTabBarRedDot: typeof Taro.hideTabBarRedDot = (options) => {
|
|
264
|
+
// options must be an Object
|
|
265
|
+
const isObject = shouldBeObject(options)
|
|
266
|
+
if (!isObject.flag) {
|
|
267
|
+
const res = { errMsg: `hideTabBarRedDot:fail ${isObject.msg}` }
|
|
268
|
+
console.error(res.errMsg)
|
|
269
|
+
return Promise.reject(res)
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
const { index, success, fail, complete } = options
|
|
273
|
+
const handle = new MethodHandler({ name: 'hideTabBarRedDot', success, fail, complete })
|
|
274
|
+
|
|
275
|
+
if (typeof index !== 'number') {
|
|
276
|
+
return handle.fail({
|
|
277
|
+
errMsg: getParameterError({
|
|
278
|
+
para: 'index',
|
|
279
|
+
correct: 'Number',
|
|
280
|
+
wrong: index
|
|
281
|
+
})
|
|
282
|
+
})
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
return new Promise((resolve, reject) => {
|
|
286
|
+
Taro.eventCenter.trigger('__taroHideTabBarRedDotHandler', {
|
|
287
|
+
index,
|
|
288
|
+
successHandler: (res = {}) => handle.success(res, resolve as any),
|
|
289
|
+
errorHandler: (res = {}) => handle.fail(res, reject as any)
|
|
290
|
+
})
|
|
291
|
+
})
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* 隐藏 tabBar
|
|
296
|
+
*/
|
|
297
|
+
export const hideTabBar: typeof Taro.hideTabBar = (options = {}) => {
|
|
298
|
+
// options must be an Object
|
|
299
|
+
const isObject = shouldBeObject(options)
|
|
300
|
+
if (!isObject.flag) {
|
|
301
|
+
const res = { errMsg: `hideTabBar:fail ${isObject.msg}` }
|
|
302
|
+
console.error(res.errMsg)
|
|
303
|
+
return Promise.reject(res)
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
const { animation, success, fail, complete } = options
|
|
307
|
+
const handle = new MethodHandler({ name: 'hideTabBar', success, fail, complete })
|
|
308
|
+
|
|
309
|
+
if (options.hasOwnProperty('animation') && typeof animation !== 'boolean') {
|
|
310
|
+
return handle.fail({
|
|
311
|
+
errMsg: getParameterError({
|
|
312
|
+
para: 'animation',
|
|
313
|
+
correct: 'Boolean',
|
|
314
|
+
wrong: animation
|
|
315
|
+
})
|
|
316
|
+
})
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
return new Promise((resolve, reject) => {
|
|
320
|
+
Taro.eventCenter.trigger('__taroHideTabBar', {
|
|
321
|
+
animation,
|
|
322
|
+
successHandler: (res = {}) => handle.success(res, resolve as any),
|
|
323
|
+
errorHandler: (res = {}) => handle.fail(res, reject as any)
|
|
324
|
+
})
|
|
325
|
+
})
|
|
326
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import Taro from '@tarojs/api'
|
|
2
|
+
import { temporarilyNotSupport } from '../utils'
|
|
3
|
+
import { CallbackManager } from '../utils/handler'
|
|
4
|
+
|
|
5
|
+
const callbackManager = new CallbackManager()
|
|
6
|
+
|
|
7
|
+
const resizeListener = () => {
|
|
8
|
+
callbackManager.trigger({
|
|
9
|
+
windowWidth: window.screen.width,
|
|
10
|
+
windowHeight: window.screen.height
|
|
11
|
+
})
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* 设置窗口大小,该接口仅适用于 PC 平台,使用细则请参见指南
|
|
16
|
+
*/
|
|
17
|
+
export const setWindowSize = temporarilyNotSupport('setWindowSize')
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* 监听窗口尺寸变化事件
|
|
21
|
+
*/
|
|
22
|
+
export const onWindowResize: typeof Taro.onWindowResize = callback => {
|
|
23
|
+
callbackManager.add(callback)
|
|
24
|
+
if (callbackManager.count() === 1) {
|
|
25
|
+
window.addEventListener('resize', resizeListener)
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* 取消监听窗口尺寸变化事件
|
|
31
|
+
*/
|
|
32
|
+
export const offWindowResize: typeof Taro.offWindowResize = callback => {
|
|
33
|
+
callbackManager.remove(callback)
|
|
34
|
+
if (callbackManager.count() === 0) {
|
|
35
|
+
window.removeEventListener('resize', resizeListener)
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
type TCallback<T = Partial<TaroGeneral.CallbackResult>> = (res: T) => Promise<void> | void
|
|
2
|
+
interface IMethodParam<T = Partial<TaroGeneral.CallbackResult>> {
|
|
3
|
+
name: string
|
|
4
|
+
success?: TCallback<T>
|
|
5
|
+
fail?: TCallback
|
|
6
|
+
complete?: TCallback
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export class MethodHandler<T = Partial<TaroGeneral.CallbackResult>> {
|
|
10
|
+
methodName: string
|
|
11
|
+
|
|
12
|
+
protected __success?: TCallback<T>
|
|
13
|
+
protected __fail?: TCallback
|
|
14
|
+
protected __complete?: TCallback
|
|
15
|
+
|
|
16
|
+
constructor ({ name, success, fail, complete }: IMethodParam<T>) {
|
|
17
|
+
this.methodName = name
|
|
18
|
+
this.__success = success
|
|
19
|
+
this.__fail = fail
|
|
20
|
+
this.__complete = complete
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
success<U = Record<string, unknown>> (res: Partial<T> & Partial<TaroGeneral.CallbackResult> = {}, resolve = Promise.resolve.bind(Promise)): Promise<T & U & TaroGeneral.CallbackResult> {
|
|
24
|
+
if (!res.errMsg) {
|
|
25
|
+
res.errMsg = `${this.methodName}:ok`
|
|
26
|
+
}
|
|
27
|
+
typeof this.__success === 'function' && this.__success(res as T)
|
|
28
|
+
typeof this.__complete === 'function' && this.__complete(res)
|
|
29
|
+
return resolve(res as Required<T & U & TaroGeneral.CallbackResult>)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
fail<U = Record<string, unknown>> (res: Partial<T> & Partial<TaroGeneral.CallbackResult> = {}, reject = Promise.reject.bind(Promise)): Promise<T & U & TaroGeneral.CallbackResult> {
|
|
33
|
+
if (!res.errMsg) {
|
|
34
|
+
res.errMsg = `${this.methodName}:fail`
|
|
35
|
+
} else {
|
|
36
|
+
res.errMsg = `${this.methodName}:fail ${res.errMsg}`
|
|
37
|
+
}
|
|
38
|
+
console.error(res.errMsg)
|
|
39
|
+
typeof this.__fail === 'function' && this.__fail(res)
|
|
40
|
+
typeof this.__complete === 'function' && this.__complete(res)
|
|
41
|
+
return reject(res)
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
type TCallbackManagerParam = (...arr: unknown[]) => void
|
|
46
|
+
interface ICallbackManagerOption {
|
|
47
|
+
callback?: TCallbackManagerParam
|
|
48
|
+
ctx?: any
|
|
49
|
+
[key: string]: unknown
|
|
50
|
+
}
|
|
51
|
+
type TCallbackManagerListItem = (TCallbackManagerParam | ICallbackManagerOption)
|
|
52
|
+
type TCallbackManagerList = TCallbackManagerListItem[]
|
|
53
|
+
|
|
54
|
+
export class CallbackManager {
|
|
55
|
+
callbacks: TCallbackManagerList = []
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* 添加回调
|
|
59
|
+
* @param {{ callback: function, ctx: any } | function} opt
|
|
60
|
+
*/
|
|
61
|
+
add (opt?: TCallbackManagerListItem) {
|
|
62
|
+
if (opt) this.callbacks.push(opt)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* 移除回调
|
|
67
|
+
* @param {{ callback: function, ctx: any } | function} opt
|
|
68
|
+
*/
|
|
69
|
+
remove (opt?: TCallbackManagerListItem) {
|
|
70
|
+
if (opt) {
|
|
71
|
+
let pos = -1
|
|
72
|
+
this.callbacks.forEach((callback, k) => {
|
|
73
|
+
if (callback === opt) {
|
|
74
|
+
pos = k
|
|
75
|
+
}
|
|
76
|
+
})
|
|
77
|
+
if (pos > -1) {
|
|
78
|
+
this.callbacks.splice(pos, 1)
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* 获取回调函数数量
|
|
85
|
+
* @return {number}
|
|
86
|
+
*/
|
|
87
|
+
count () {
|
|
88
|
+
return this.callbacks.length
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* 触发回调
|
|
93
|
+
* @param {...any} args 回调的调用参数
|
|
94
|
+
*/
|
|
95
|
+
trigger (...args: TCallbackManagerList) {
|
|
96
|
+
this.callbacks.forEach(opt => {
|
|
97
|
+
if (typeof opt === 'function') {
|
|
98
|
+
opt(...args)
|
|
99
|
+
} else {
|
|
100
|
+
const { callback, ctx } = opt
|
|
101
|
+
typeof callback === 'function' && callback.call(ctx, ...args)
|
|
102
|
+
}
|
|
103
|
+
})
|
|
104
|
+
}
|
|
105
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/* eslint-disable prefer-promise-reject-errors */
|
|
2
|
-
import { Current, container, SERVICE_IDENTIFIER } from '@tarojs/runtime'
|
|
2
|
+
import { Current, container, SERVICE_IDENTIFIER, IHooks, TaroElement } from '@tarojs/runtime'
|
|
3
3
|
|
|
4
|
-
function
|
|
5
|
-
if (target && typeof target === 'object') return {
|
|
4
|
+
function shouldBeObject (target: unknown) {
|
|
5
|
+
if (target && typeof target === 'object') return { flag: true }
|
|
6
6
|
return {
|
|
7
|
-
|
|
7
|
+
flag: false,
|
|
8
8
|
msg: getParameterError({
|
|
9
9
|
correct: 'Object',
|
|
10
10
|
wrong: target
|
|
@@ -12,8 +12,8 @@ function shouleBeObject (target) {
|
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
export function findDOM (inst) {
|
|
16
|
-
const runtimeHooks = container.get(SERVICE_IDENTIFIER.Hooks)
|
|
15
|
+
export function findDOM (inst): TaroElement | HTMLElement | undefined {
|
|
16
|
+
const runtimeHooks = container.get<IHooks>(SERVICE_IDENTIFIER.Hooks)
|
|
17
17
|
|
|
18
18
|
if (inst) {
|
|
19
19
|
const find = runtimeHooks.getDOMNode
|
|
@@ -23,7 +23,7 @@ export function findDOM (inst) {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
const page = Current.page
|
|
26
|
-
const path = page
|
|
26
|
+
const path = page?.path
|
|
27
27
|
const msg = '没有找到已经加载了的页面,请在页面加载完成后时候此 API。'
|
|
28
28
|
if (path == null) {
|
|
29
29
|
throw new Error(msg)
|
|
@@ -37,10 +37,20 @@ export function findDOM (inst) {
|
|
|
37
37
|
return el
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
|
|
40
|
+
interface IParameterErrorParam {
|
|
41
|
+
name?: string
|
|
42
|
+
para?: string
|
|
43
|
+
correct?: string
|
|
44
|
+
wrong?: unknown
|
|
45
|
+
}
|
|
46
|
+
function getParameterError ({ name = '', para, correct, wrong }: IParameterErrorParam) {
|
|
41
47
|
const parameter = para ? `parameter.${para}` : 'parameter'
|
|
42
48
|
const errorType = upperCaseFirstLetter(wrong === null ? 'Null' : typeof wrong)
|
|
43
|
-
|
|
49
|
+
if (name) {
|
|
50
|
+
return `${name}:fail parameter error: ${parameter} should be ${correct} instead of ${errorType}`
|
|
51
|
+
} else {
|
|
52
|
+
return `parameter error: ${parameter} should be ${correct} instead of ${errorType}`
|
|
53
|
+
}
|
|
44
54
|
}
|
|
45
55
|
|
|
46
56
|
function upperCaseFirstLetter (string) {
|
|
@@ -67,22 +77,6 @@ function isFunction (obj) {
|
|
|
67
77
|
return typeof obj === 'function'
|
|
68
78
|
}
|
|
69
79
|
|
|
70
|
-
function successHandler (success, complete) {
|
|
71
|
-
return function (res) {
|
|
72
|
-
isFunction(success) && success(res)
|
|
73
|
-
isFunction(complete) && complete(res)
|
|
74
|
-
return Promise.resolve(res)
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
function errorHandler (fail, complete) {
|
|
79
|
-
return function (res) {
|
|
80
|
-
isFunction(fail) && fail(res)
|
|
81
|
-
isFunction(complete) && complete(res)
|
|
82
|
-
return Promise.reject(res)
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
80
|
function serializeParams (params) {
|
|
87
81
|
if (!params) {
|
|
88
82
|
return ''
|
|
@@ -131,63 +125,8 @@ const isValidColor = (color) => {
|
|
|
131
125
|
return VALID_COLOR_REG.test(color)
|
|
132
126
|
}
|
|
133
127
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* 添加回调
|
|
139
|
-
* @param {{ callback: function, ctx: any } | function} opt
|
|
140
|
-
*/
|
|
141
|
-
const add = (opt) => {
|
|
142
|
-
callbacks.push(opt)
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* 移除回调
|
|
147
|
-
* @param {{ callback: function, ctx: any } | function} opt
|
|
148
|
-
*/
|
|
149
|
-
const remove = (opt) => {
|
|
150
|
-
let pos = -1
|
|
151
|
-
callbacks.forEach((callback, k) => {
|
|
152
|
-
if (callback === opt) {
|
|
153
|
-
pos = k
|
|
154
|
-
}
|
|
155
|
-
})
|
|
156
|
-
if (pos > -1) {
|
|
157
|
-
callbacks.splice(pos, 1)
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* 获取回调函数数量
|
|
163
|
-
* @return {number}
|
|
164
|
-
*/
|
|
165
|
-
const count = () => callbacks.length
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* 触发回调
|
|
169
|
-
* @param {...any} args 回调的调用参数
|
|
170
|
-
*/
|
|
171
|
-
const trigger = (...args) => {
|
|
172
|
-
callbacks.forEach(opt => {
|
|
173
|
-
if (typeof opt === 'function') {
|
|
174
|
-
opt(...args)
|
|
175
|
-
} else {
|
|
176
|
-
const { callback, ctx } = opt
|
|
177
|
-
callback.call(ctx, ...args)
|
|
178
|
-
}
|
|
179
|
-
})
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
return {
|
|
183
|
-
add,
|
|
184
|
-
remove,
|
|
185
|
-
count,
|
|
186
|
-
trigger
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
function processOpenapi (apiName, defaultOptions, formatResult = res => res, formatParams = options => options) {
|
|
128
|
+
function processOpenApi (apiName: string, defaultOptions?: Record<string, unknown>, formatResult = res => res, formatParams = options => options) {
|
|
129
|
+
// @ts-ignore
|
|
191
130
|
if (!window.wx) {
|
|
192
131
|
return weixinCorpSupport(apiName)
|
|
193
132
|
}
|
|
@@ -206,6 +145,7 @@ function processOpenapi (apiName, defaultOptions, formatResult = res => res, for
|
|
|
206
145
|
}
|
|
207
146
|
}
|
|
208
147
|
})
|
|
148
|
+
// @ts-ignore
|
|
209
149
|
wx[apiName](formatParams(obj))
|
|
210
150
|
})
|
|
211
151
|
return p
|
|
@@ -229,20 +169,17 @@ const getTimingFunc = (easeFunc, frameCnt) => {
|
|
|
229
169
|
}
|
|
230
170
|
|
|
231
171
|
export {
|
|
232
|
-
|
|
172
|
+
shouldBeObject,
|
|
233
173
|
getParameterError,
|
|
234
174
|
inlineStyle,
|
|
235
175
|
setTransform,
|
|
236
|
-
successHandler,
|
|
237
|
-
errorHandler,
|
|
238
176
|
serializeParams,
|
|
239
177
|
temporarilyNotSupport,
|
|
240
178
|
weixinCorpSupport,
|
|
241
179
|
permanentlyNotSupport,
|
|
242
180
|
isValidColor,
|
|
243
181
|
isFunction,
|
|
244
|
-
|
|
245
|
-
processOpenapi,
|
|
182
|
+
processOpenApi,
|
|
246
183
|
easeInOut,
|
|
247
184
|
getTimingFunc
|
|
248
185
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import Taro from '@tarojs/api'
|
|
2
|
+
import { temporarilyNotSupport } from '../utils'
|
|
3
|
+
import { SelectorQuery } from './selectorQuery'
|
|
4
|
+
|
|
5
|
+
export const createSelectorQuery: typeof Taro.createSelectorQuery = () => {
|
|
6
|
+
return new SelectorQuery()
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const createIntersectionObserver = temporarilyNotSupport('createIntersectionObserver')
|