@tarojs/taro-h5 3.5.0-alpha.13 → 3.5.0-alpha.16
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/api/ad/index.d.ts +6 -0
- package/dist/api/ai/facial.d.ts +9 -0
- package/dist/api/ai/index.d.ts +2 -0
- package/dist/api/ai/visual.d.ts +6 -0
- package/dist/api/alipay/index.d.ts +3 -0
- package/dist/api/base/crypto.d.ts +3 -0
- package/dist/api/base/debug.d.ts +9 -0
- package/dist/api/base/index.d.ts +12 -0
- package/dist/api/base/performance.d.ts +6 -0
- package/dist/api/base/system.d.ts +27 -0
- package/dist/api/base/system.js +2 -2
- package/dist/api/base/update.d.ts +6 -0
- package/dist/api/base/weapp/app-event.d.ts +41 -0
- package/dist/api/base/weapp/app-event.js +55 -4
- package/dist/api/base/weapp/life-cycle.d.ts +6 -0
- package/dist/api/canvas/CanvasContext.d.ts +104 -0
- package/dist/api/canvas/canvasGetImageData.d.ts +5 -0
- package/dist/api/canvas/canvasPutImageData.d.ts +6 -0
- package/dist/api/canvas/canvasToTempFilePath.d.ts +6 -0
- package/dist/api/canvas/canvasToTempFilePath.js +1 -1
- package/dist/api/canvas/createCanvasContext.d.ts +5 -0
- package/dist/api/canvas/index.d.ts +12 -0
- package/dist/api/cloud/index.d.ts +31 -0
- package/dist/api/data-analysis/index.d.ts +12 -0
- package/dist/api/device/accelerometer.d.ts +17 -0
- package/dist/api/device/accessibility.d.ts +3 -0
- package/dist/api/device/battery.d.ts +5 -0
- package/dist/api/device/bluetooth-ble.d.ts +48 -0
- package/dist/api/device/bluetooth-peripheral.d.ts +9 -0
- package/dist/api/device/bluetooth.d.ts +39 -0
- package/dist/api/device/calendar.d.ts +6 -0
- package/dist/api/device/clipboard.d.ts +15 -0
- package/dist/api/device/compass.d.ts +17 -0
- package/dist/api/device/contact.d.ts +6 -0
- package/dist/api/device/crypto.d.ts +3 -0
- package/dist/api/device/gyroscope.d.ts +12 -0
- package/dist/api/device/iBeacon.d.ts +21 -0
- package/dist/api/device/index.d.ts +23 -0
- package/dist/api/device/keyboard.d.ts +12 -0
- package/dist/api/device/memory.d.ts +6 -0
- package/dist/api/device/motion.d.ts +17 -0
- package/dist/api/device/network.d.ts +20 -0
- package/dist/api/device/nfc.d.ts +21 -0
- package/dist/api/device/phone.d.ts +2 -0
- package/dist/api/device/scan.d.ts +3 -0
- package/dist/api/device/screen.d.ts +18 -0
- package/dist/api/device/vibrate.d.ts +9 -0
- package/dist/api/device/vibrate.js +5 -7
- package/dist/api/device/wifi.d.ts +33 -0
- package/dist/api/ext/index.d.ts +6 -0
- package/dist/api/files/index.d.ts +24 -0
- package/dist/api/framework/index.d.ts +4 -0
- package/dist/api/index.d.ts +24 -0
- package/dist/api/location/chooseLocation.d.ts +6 -0
- package/dist/api/location/getLocation.d.ts +2 -0
- package/dist/api/location/index.d.ts +32 -0
- package/dist/api/location/index.js +1 -0
- package/dist/api/media/EditorContext.d.ts +42 -0
- package/dist/api/media/audio/InnerAudioContext.d.ts +58 -0
- package/dist/api/media/audio/InnerAudioContext.js +1 -1
- package/dist/api/media/audio/index.d.ts +29 -0
- package/dist/api/media/background-audio/BackgroundAudioManager.d.ts +71 -0
- package/dist/api/media/background-audio/index.d.ts +29 -0
- package/dist/api/media/camera.d.ts +3 -0
- package/dist/api/media/image/chooseImage.d.ts +5 -0
- package/dist/api/media/image/getImageInfo.d.ts +5 -0
- package/dist/api/media/image/index.d.ts +15 -0
- package/dist/api/media/image/previewImage.d.ts +8 -0
- package/dist/api/media/index.d.ts +12 -0
- package/dist/api/media/live.d.ts +6 -0
- package/dist/api/media/map.d.ts +3 -0
- package/dist/api/media/media-recorder.d.ts +3 -0
- package/dist/api/media/recorder.d.ts +9 -0
- package/dist/api/media/video/index.d.ts +24 -0
- package/dist/api/media/video-decoder.d.ts +3 -0
- package/dist/api/media/video-processing.d.ts +3 -0
- package/dist/api/media/voip.d.ts +42 -0
- package/dist/api/navigate/index.d.ts +12 -0
- package/dist/api/network/download.d.ts +6 -0
- package/dist/api/network/download.js +1 -0
- package/dist/api/network/index.d.ts +7 -0
- package/dist/api/network/mdns.d.ts +30 -0
- package/dist/api/network/request/index.d.ts +4 -0
- package/dist/api/network/tcp.d.ts +3 -0
- package/dist/api/network/udp.d.ts +3 -0
- package/dist/api/network/upload.d.ts +5 -0
- package/dist/api/network/upload.js +2 -1
- package/{src/api/network/utils.ts → dist/api/network/utils.d.ts} +44 -71
- package/dist/api/network/utils.js +1 -0
- package/dist/api/network/websocket/index.d.ts +7 -0
- package/dist/api/network/websocket/socketTask.d.ts +25 -0
- package/dist/api/open-api/account.d.ts +3 -0
- package/dist/api/open-api/address.d.ts +3 -0
- package/dist/api/open-api/authorize.d.ts +6 -0
- package/dist/api/open-api/card.d.ts +6 -0
- package/dist/api/open-api/channels-live.d.ts +18 -0
- package/dist/api/open-api/customer-service.d.ts +3 -0
- package/dist/api/open-api/facial.d.ts +12 -0
- package/dist/api/open-api/favorites.d.ts +6 -0
- package/dist/api/open-api/group.d.ts +3 -0
- package/dist/api/open-api/index.d.ts +18 -0
- package/dist/api/open-api/invoice.d.ts +6 -0
- package/dist/api/open-api/license-plate.d.ts +3 -0
- package/dist/api/open-api/login.d.ts +9 -0
- package/dist/api/open-api/red-package.d.ts +3 -0
- package/dist/api/open-api/settings.d.ts +6 -0
- package/dist/api/open-api/soter.d.ts +9 -0
- package/dist/api/open-api/subscribe-message.d.ts +3 -0
- package/dist/api/open-api/user-info.d.ts +6 -0
- package/dist/api/open-api/werun.d.ts +6 -0
- package/dist/api/payment/index.d.ts +6 -0
- package/dist/api/route/index.d.ts +1 -0
- package/dist/api/share/index.d.ts +30 -0
- package/dist/api/storage/background-fetch.d.ts +12 -0
- package/dist/api/storage/index.d.ts +18 -0
- package/dist/api/swan/index.d.ts +63 -0
- package/dist/api/taro.d.ts +12 -0
- package/dist/api/ui/animation/index.d.ts +2 -0
- package/dist/api/ui/background.d.ts +6 -0
- package/dist/api/ui/custom-component.d.ts +1 -0
- package/dist/api/ui/fonts.d.ts +2 -0
- package/dist/api/ui/index.d.ts +12 -0
- package/dist/api/ui/interaction/actionSheet.d.ts +61 -0
- package/dist/api/ui/interaction/index.d.ts +14 -0
- package/dist/api/ui/interaction/modal.d.ts +69 -0
- package/dist/api/ui/interaction/modal.js +1 -0
- package/dist/api/ui/interaction/toast.d.ts +85 -0
- package/dist/api/ui/menu.d.ts +3 -0
- package/dist/api/ui/navigation-bar/index.d.ts +15 -0
- package/dist/api/ui/navigation-bar/index.js +2 -3
- package/dist/api/ui/pull-down-refresh.d.ts +9 -0
- package/dist/api/ui/scroll/index.d.ts +5 -0
- package/dist/api/ui/sticky.d.ts +3 -0
- package/dist/api/ui/tab-bar.d.ts +34 -0
- package/dist/api/ui/window.d.ts +15 -0
- package/dist/api/worker/index.d.ts +3 -0
- package/dist/api/wxml/index.d.ts +5 -0
- package/dist/api/wxml/nodesRef.d.ts +13 -0
- package/dist/api/wxml/selectorQuery.d.ts +24 -0
- package/dist/api/wxml/selectorQuery.js +1 -1
- package/dist/index.cjs.d.ts +1373 -0
- package/dist/index.cjs.js +105 -81
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.esm.d.ts +1373 -0
- package/dist/index.esm.js +93 -69
- package/dist/index.esm.js.map +1 -1
- package/dist/taroApis.d.ts +1364 -0
- package/dist/taroApis.js +1 -1
- package/dist/utils/animation.d.ts +6 -0
- package/dist/utils/handler.d.ts +48 -0
- package/dist/utils/index.d.ts +39 -0
- package/dist/utils/index.js +3 -7
- package/dist/utils/lodash.d.ts +2 -0
- package/dist/utils/valid.d.ts +2 -0
- package/package.json +17 -19
- package/types/api.d.ts +4 -0
- package/types/define.d.ts +2 -0
- package/types/index.d.ts +33 -0
- package/types/overlay.d.ts +9 -0
- package/LICENSE +0 -21
- package/src/api/ad/index.ts +0 -5
- package/src/api/ai/facial.ts +0 -6
- package/src/api/ai/index.ts +0 -2
- package/src/api/ai/visual.ts +0 -7
- package/src/api/alipay/index.ts +0 -4
- package/src/api/base/crypto.ts +0 -4
- package/src/api/base/debug.ts +0 -5
- package/src/api/base/index.ts +0 -23
- package/src/api/base/performance.ts +0 -5
- package/src/api/base/system.ts +0 -207
- package/src/api/base/update.ts +0 -5
- package/src/api/base/weapp/app-event.ts +0 -19
- package/src/api/base/weapp/life-cycle.ts +0 -5
- package/src/api/canvas/CanvasContext.ts +0 -233
- package/src/api/canvas/canvasGetImageData.ts +0 -28
- package/src/api/canvas/canvasPutImageData.ts +0 -25
- package/src/api/canvas/canvasToTempFilePath.ts +0 -25
- package/src/api/canvas/createCanvasContext.ts +0 -19
- package/src/api/canvas/index.ts +0 -18
- package/src/api/cloud/index.ts +0 -32
- package/src/api/data-analysis/index.ts +0 -6
- package/src/api/device/accelerometer.ts +0 -79
- package/src/api/device/accessibility.ts +0 -4
- package/src/api/device/battery.ts +0 -23
- package/src/api/device/bluetooth-ble.ts +0 -19
- package/src/api/device/bluetooth-peripheral.ts +0 -6
- package/src/api/device/bluetooth.ts +0 -16
- package/src/api/device/calendar.ts +0 -5
- package/src/api/device/clipboard.ts +0 -68
- package/src/api/device/compass.ts +0 -83
- package/src/api/device/contact.ts +0 -5
- package/src/api/device/crypto.ts +0 -4
- package/src/api/device/gyroscope.ts +0 -7
- package/src/api/device/iBeacon.ts +0 -10
- package/src/api/device/index.ts +0 -23
- package/src/api/device/keyboard.ts +0 -7
- package/src/api/device/memory.ts +0 -5
- package/src/api/device/motion.ts +0 -77
- package/src/api/device/network.ts +0 -90
- package/src/api/device/nfc.ts +0 -10
- package/src/api/device/phone.ts +0 -31
- package/src/api/device/scan.ts +0 -11
- package/src/api/device/screen.ts +0 -9
- package/src/api/device/vibrate.ts +0 -37
- package/src/api/device/wifi.ts +0 -14
- package/src/api/ext/index.ts +0 -5
- package/src/api/files/index.ts +0 -11
- package/src/api/framework/index.ts +0 -10
- package/src/api/index.ts +0 -24
- package/src/api/location/chooseLocation.ts +0 -117
- package/src/api/location/getLocation.ts +0 -81
- package/src/api/location/index.ts +0 -22
- package/src/api/location/style.css +0 -79
- package/src/api/media/EditorContext.ts +0 -32
- package/src/api/media/audio/InnerAudioContext.ts +0 -99
- package/src/api/media/audio/index.ts +0 -21
- package/src/api/media/background-audio/BackgroundAudioManager.ts +0 -104
- package/src/api/media/background-audio/index.ts +0 -17
- package/src/api/media/camera.ts +0 -4
- package/src/api/media/image/chooseImage.ts +0 -95
- package/src/api/media/image/getImageInfo.ts +0 -50
- package/src/api/media/image/index.ts +0 -13
- package/src/api/media/image/previewImage.ts +0 -80
- package/src/api/media/index.ts +0 -12
- package/src/api/media/live.ts +0 -5
- package/src/api/media/map.ts +0 -4
- package/src/api/media/media-recorder.ts +0 -4
- package/src/api/media/recorder.ts +0 -6
- package/src/api/media/video/index.ts +0 -82
- package/src/api/media/video-decoder.ts +0 -4
- package/src/api/media/video-processing.ts +0 -4
- package/src/api/media/voip.ts +0 -17
- package/src/api/navigate/index.ts +0 -7
- package/src/api/network/download.ts +0 -141
- package/src/api/network/index.ts +0 -7
- package/src/api/network/mdns.ts +0 -13
- package/src/api/network/request/index.ts +0 -135
- package/src/api/network/tcp.ts +0 -4
- package/src/api/network/udp.ts +0 -4
- package/src/api/network/upload.ts +0 -169
- package/src/api/network/websocket/index.ts +0 -88
- package/src/api/network/websocket/socketTask.ts +0 -89
- package/src/api/open-api/account.ts +0 -4
- package/src/api/open-api/address.ts +0 -4
- package/src/api/open-api/authorize.ts +0 -5
- package/src/api/open-api/card.ts +0 -5
- package/src/api/open-api/channels-live.ts +0 -9
- package/src/api/open-api/customer-service.ts +0 -4
- package/src/api/open-api/facial.ts +0 -7
- package/src/api/open-api/favorites.ts +0 -5
- package/src/api/open-api/group.ts +0 -4
- package/src/api/open-api/index.ts +0 -18
- package/src/api/open-api/invoice.ts +0 -5
- package/src/api/open-api/license-plate.ts +0 -4
- package/src/api/open-api/login.ts +0 -6
- package/src/api/open-api/red-package.ts +0 -4
- package/src/api/open-api/settings.ts +0 -5
- package/src/api/open-api/soter.ts +0 -6
- package/src/api/open-api/subscribe-message.ts +0 -4
- package/src/api/open-api/user-info.ts +0 -5
- package/src/api/open-api/werun.ts +0 -5
- package/src/api/payment/index.ts +0 -5
- package/src/api/route/index.ts +0 -10
- package/src/api/share/index.ts +0 -13
- package/src/api/storage/background-fetch.ts +0 -7
- package/src/api/storage/index.ts +0 -182
- package/src/api/swan/index.ts +0 -31
- package/src/api/taro.ts +0 -84
- package/src/api/ui/animation/index.ts +0 -356
- package/src/api/ui/background.ts +0 -5
- package/src/api/ui/custom-component.ts +0 -4
- package/src/api/ui/fonts.ts +0 -64
- package/src/api/ui/index.ts +0 -12
- package/src/api/ui/interaction/actionSheet.ts +0 -212
- package/src/api/ui/interaction/index.ts +0 -302
- package/src/api/ui/interaction/modal.ts +0 -237
- package/src/api/ui/interaction/toast.ts +0 -220
- package/src/api/ui/menu.ts +0 -4
- package/src/api/ui/navigation-bar/index.ts +0 -52
- package/src/api/ui/pull-down-refresh.ts +0 -28
- package/src/api/ui/scroll/index.ts +0 -85
- package/src/api/ui/sticky.ts +0 -4
- package/src/api/ui/tab-bar.ts +0 -327
- package/src/api/ui/window.ts +0 -38
- package/src/api/worker/index.ts +0 -4
- package/src/api/wxml/index.ts +0 -10
- package/src/api/wxml/nodesRef.ts +0 -56
- package/src/api/wxml/selectorQuery.ts +0 -220
- package/src/index.ts +0 -6
- package/src/utils/animation.ts +0 -15
- package/src/utils/handler.ts +0 -105
- package/src/utils/index.ts +0 -184
- package/src/utils/lodash.ts +0 -30
- package/src/utils/valid.ts +0 -8
package/src/utils/handler.ts
DELETED
|
@@ -1,105 +0,0 @@
|
|
|
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
|
-
}
|
package/src/utils/index.ts
DELETED
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
/* eslint-disable prefer-promise-reject-errors */
|
|
2
|
-
import { container, Current, IHooks, SERVICE_IDENTIFIER, TaroElement } from '@tarojs/runtime'
|
|
3
|
-
|
|
4
|
-
export function shouldBeObject (target: unknown) {
|
|
5
|
-
if (target && typeof target === 'object') return { flag: true }
|
|
6
|
-
return {
|
|
7
|
-
flag: false,
|
|
8
|
-
msg: getParameterError({
|
|
9
|
-
correct: 'Object',
|
|
10
|
-
wrong: target
|
|
11
|
-
})
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function findDOM (inst?): TaroElement | HTMLElement | undefined {
|
|
16
|
-
const runtimeHooks = container.get<IHooks>(SERVICE_IDENTIFIER.Hooks)
|
|
17
|
-
|
|
18
|
-
if (inst) {
|
|
19
|
-
const find = runtimeHooks.getDOMNode
|
|
20
|
-
if (typeof find === 'function') {
|
|
21
|
-
return find(inst)
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const page = Current.page
|
|
26
|
-
const path = page?.path
|
|
27
|
-
const msg = '没有找到已经加载了的页面,请在页面加载完成后时候此 API。'
|
|
28
|
-
if (path == null) {
|
|
29
|
-
throw new Error(msg)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const el = document.getElementById(path)
|
|
33
|
-
if (el == null) {
|
|
34
|
-
throw new Error('在已加载页面中没有找到对应的容器元素。')
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return el
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
interface IParameterErrorParam {
|
|
41
|
-
name?: string
|
|
42
|
-
para?: string
|
|
43
|
-
correct?: string
|
|
44
|
-
wrong?: unknown
|
|
45
|
-
}
|
|
46
|
-
export function getParameterError ({ name = '', para, correct, wrong }: IParameterErrorParam) {
|
|
47
|
-
const parameter = para ? `parameter.${para}` : 'parameter'
|
|
48
|
-
const errorType = upperCaseFirstLetter(wrong === null ? 'Null' : typeof wrong)
|
|
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
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function upperCaseFirstLetter (string) {
|
|
57
|
-
if (typeof string !== 'string') return string
|
|
58
|
-
string = string.replace(/^./, match => match.toUpperCase())
|
|
59
|
-
return string
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export function inlineStyle (style) {
|
|
63
|
-
let res = ''
|
|
64
|
-
for (const attr in style) res += `${attr}: ${style[attr]};`
|
|
65
|
-
if (res.indexOf('display: flex;') >= 0) res += 'display: -webkit-box;display: -webkit-flex;'
|
|
66
|
-
res = res.replace(/transform:(.+?);/g, (s, $1) => `${s}-webkit-transform:${$1};`)
|
|
67
|
-
res = res.replace(/flex-direction:(.+?);/g, (s, $1) => `${s}-webkit-flex-direction:${$1};`)
|
|
68
|
-
return res
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export function setTransform (el, val) {
|
|
72
|
-
el.style.webkitTransform = val
|
|
73
|
-
el.style.transform = val
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export function serializeParams (params) {
|
|
77
|
-
if (!params) {
|
|
78
|
-
return ''
|
|
79
|
-
}
|
|
80
|
-
return Object.keys(params)
|
|
81
|
-
.map(key => (
|
|
82
|
-
`${encodeURIComponent(key)}=${typeof (params[key]) === 'object'
|
|
83
|
-
? encodeURIComponent(JSON.stringify(params[key]))
|
|
84
|
-
: encodeURIComponent(params[key])}`))
|
|
85
|
-
.join('&')
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export function temporarilyNotSupport (apiName) {
|
|
89
|
-
return () => {
|
|
90
|
-
const errMsg = `暂时不支持 API ${apiName}`
|
|
91
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
92
|
-
console.error(errMsg)
|
|
93
|
-
return Promise.reject({
|
|
94
|
-
errMsg
|
|
95
|
-
})
|
|
96
|
-
} else {
|
|
97
|
-
console.warn(errMsg)
|
|
98
|
-
return Promise.resolve({
|
|
99
|
-
errMsg
|
|
100
|
-
})
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
export function weixinCorpSupport (apiName) {
|
|
106
|
-
return () => {
|
|
107
|
-
const errMsg = `h5端当前仅在微信公众号JS-SDK环境下支持此 API ${apiName}`
|
|
108
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
109
|
-
console.error(errMsg)
|
|
110
|
-
return Promise.reject({
|
|
111
|
-
errMsg
|
|
112
|
-
})
|
|
113
|
-
} else {
|
|
114
|
-
console.warn(errMsg)
|
|
115
|
-
return Promise.resolve({
|
|
116
|
-
errMsg
|
|
117
|
-
})
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
export function permanentlyNotSupport (apiName) {
|
|
123
|
-
return () => {
|
|
124
|
-
const errMsg = `不支持 API ${apiName}`
|
|
125
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
126
|
-
console.error(errMsg)
|
|
127
|
-
return Promise.reject({
|
|
128
|
-
errMsg
|
|
129
|
-
})
|
|
130
|
-
} else {
|
|
131
|
-
console.warn(errMsg)
|
|
132
|
-
return Promise.resolve({
|
|
133
|
-
errMsg
|
|
134
|
-
})
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
interface IProcessOpenApi<TOptions = Record<string, unknown>, TResult extends TaroGeneral.CallbackResult = any> {
|
|
140
|
-
name: string
|
|
141
|
-
defaultOptions?: TOptions
|
|
142
|
-
standardMethod?: (opts: TOptions) => Promise<TResult>
|
|
143
|
-
formatOptions?: (opts: TOptions) => TOptions
|
|
144
|
-
formatResult?: (res: TResult) => TResult
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
export function processOpenApi<TOptions = Record<string, unknown>, TResult extends TaroGeneral.CallbackResult = any> ({
|
|
148
|
-
name,
|
|
149
|
-
defaultOptions,
|
|
150
|
-
standardMethod,
|
|
151
|
-
formatOptions = options => options,
|
|
152
|
-
formatResult = res => res
|
|
153
|
-
}: IProcessOpenApi<TOptions, TResult>) {
|
|
154
|
-
const notSupported = weixinCorpSupport(name)
|
|
155
|
-
return (options: Partial<TOptions> = {}): Promise<TResult> => {
|
|
156
|
-
// @ts-ignore
|
|
157
|
-
const targetApi = window?.wx?.[name]
|
|
158
|
-
const opts = formatOptions(Object.assign({}, defaultOptions, options))
|
|
159
|
-
if (typeof targetApi === 'function') {
|
|
160
|
-
return new Promise<TResult>((resolve, reject) => {
|
|
161
|
-
['fail', 'success', 'complete'].forEach(k => {
|
|
162
|
-
opts[k] = preRef => {
|
|
163
|
-
const res = formatResult(preRef)
|
|
164
|
-
options[k] && options[k](res)
|
|
165
|
-
if (k === 'success') {
|
|
166
|
-
resolve(res)
|
|
167
|
-
} else if (k === 'fail') {
|
|
168
|
-
reject(res)
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
return targetApi(opts)
|
|
172
|
-
})
|
|
173
|
-
})
|
|
174
|
-
} else if (typeof standardMethod === 'function') {
|
|
175
|
-
return standardMethod(opts)
|
|
176
|
-
} else {
|
|
177
|
-
return notSupported() as Promise<TResult>
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
export * from './animation'
|
|
183
|
-
export * from './lodash'
|
|
184
|
-
export * from './valid'
|
package/src/utils/lodash.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
export function throttle (fn, threshold = 250, scope?) {
|
|
2
|
-
let lastTime = 0
|
|
3
|
-
let deferTimer: ReturnType<typeof setTimeout>
|
|
4
|
-
return function (...args) {
|
|
5
|
-
const context = scope || this
|
|
6
|
-
const now = Date.now()
|
|
7
|
-
if (now - lastTime > threshold) {
|
|
8
|
-
fn.apply(this, args)
|
|
9
|
-
lastTime = now
|
|
10
|
-
} else {
|
|
11
|
-
clearTimeout(deferTimer)
|
|
12
|
-
deferTimer = setTimeout(() => {
|
|
13
|
-
lastTime = now
|
|
14
|
-
fn.apply(context, args)
|
|
15
|
-
}, threshold)
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export function debounce (fn, ms = 250, scope?) {
|
|
21
|
-
let timer: ReturnType<typeof setTimeout>
|
|
22
|
-
|
|
23
|
-
return function (...args) {
|
|
24
|
-
const context = scope || this
|
|
25
|
-
clearTimeout(timer)
|
|
26
|
-
timer = setTimeout(function () {
|
|
27
|
-
fn.apply(context, args)
|
|
28
|
-
}, ms)
|
|
29
|
-
}
|
|
30
|
-
}
|