@tarojs/taro-h5 3.4.0-beta.0 → 3.4.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/dist/api/ad/index.js +4 -0
- package/dist/api/ai/facial.js +5 -0
- package/dist/api/ai/index.js +2 -0
- package/dist/api/ai/visual.js +3 -0
- package/dist/api/alipay/index.js +3 -0
- package/dist/api/base/crypto.js +3 -0
- package/dist/api/base/debug.js +4 -0
- package/dist/api/base/index.js +17 -0
- package/dist/api/base/performance.js +4 -0
- package/dist/api/base/system/index.js +2 -0
- package/dist/api/base/system/info.js +57 -0
- package/dist/api/base/system/network.js +63 -0
- package/dist/api/base/update.js +4 -0
- package/dist/api/base/weapp/app-event.js +18 -0
- package/dist/api/base/weapp/life-cycle.js +4 -0
- package/dist/api/canvas/CanvasContext.js +191 -0
- package/dist/api/canvas/canvasGetImageData.js +25 -0
- package/dist/api/canvas/canvasPutImageData.js +22 -0
- package/dist/api/canvas/canvasToTempFilePath.js +22 -0
- package/dist/api/canvas/createCanvasContext.js +16 -0
- package/dist/api/canvas/index.js +8 -0
- package/dist/api/cloud/index.js +17 -0
- package/dist/api/data-analysis/index.js +5 -0
- package/dist/api/device/accelerometer.js +83 -0
- package/dist/api/device/accessibility.js +3 -0
- package/dist/api/device/battery.js +4 -0
- package/dist/api/device/bluetooth-ble.js +18 -0
- package/dist/api/device/bluetooth-peripheral.js +5 -0
- package/dist/api/device/bluetooth.js +15 -0
- package/dist/api/device/calendar.js +4 -0
- package/dist/api/device/clipboard.js +65 -0
- package/dist/api/device/compass.js +64 -0
- package/dist/api/device/contact.js +4 -0
- package/dist/api/device/crypto.js +3 -0
- package/dist/api/device/gyroscope.js +6 -0
- package/dist/api/device/iBeacon.js +9 -0
- package/dist/api/device/index.js +22 -0
- package/dist/api/device/keyboard.js +6 -0
- package/dist/api/device/memory.js +4 -0
- package/dist/api/device/motion.js +81 -0
- package/dist/api/device/nfc.js +9 -0
- package/dist/api/device/phone.js +24 -0
- package/dist/api/device/scan.js +6 -0
- package/dist/api/device/screen.js +8 -0
- package/dist/api/device/vibrate.js +35 -0
- package/dist/api/device/wifi.js +12 -0
- package/dist/api/ext/index.js +4 -0
- package/dist/api/files/index.js +10 -0
- package/dist/api/framework/index.js +7 -0
- package/dist/api/index.js +24 -0
- package/dist/api/location/chooseLocation.js +93 -0
- package/dist/api/location/index.js +13 -0
- package/dist/api/location/style.css +79 -0
- package/dist/api/media/audio/index.js +88 -0
- package/dist/api/media/background-audio.js +11 -0
- package/dist/api/media/camera.js +3 -0
- package/dist/api/media/editor.js +18 -0
- package/dist/api/media/image/chooseImage.js +74 -0
- package/dist/api/media/image/getImageInfo.js +31 -0
- package/dist/api/media/image/index.js +9 -0
- package/dist/api/media/image/previewImage.js +67 -0
- package/dist/api/media/index.js +13 -0
- package/dist/api/media/live.js +4 -0
- package/dist/api/media/map.js +3 -0
- package/dist/api/media/media-recorder.js +3 -0
- package/dist/api/media/recorder.js +5 -0
- package/dist/api/media/video/index.js +74 -0
- package/dist/api/media/video-decoder.js +3 -0
- package/dist/api/media/video-processing.js +3 -0
- package/dist/api/media/voip.js +16 -0
- package/dist/api/navigate/index.js +6 -0
- package/dist/api/network/download.js +124 -0
- package/dist/api/network/index.js +7 -0
- package/dist/api/network/mdns.js +12 -0
- package/dist/api/network/request/index.js +125 -0
- package/dist/api/network/tcp.js +3 -0
- package/dist/api/network/udp.js +3 -0
- package/dist/api/network/upload.js +151 -0
- package/dist/api/network/utils.js +65 -0
- package/dist/api/network/websocket/index.js +70 -0
- package/dist/api/network/websocket/socketTask.js +63 -0
- package/dist/api/open-api/account.js +3 -0
- package/dist/api/open-api/address.js +3 -0
- package/dist/api/open-api/authorize.js +4 -0
- package/dist/api/open-api/card.js +4 -0
- package/dist/api/open-api/channels-live.js +8 -0
- package/dist/api/open-api/customer-service.js +3 -0
- package/dist/api/open-api/facial.js +6 -0
- package/dist/api/open-api/favorites.js +4 -0
- package/dist/api/open-api/group.js +3 -0
- package/dist/api/open-api/index.js +18 -0
- package/dist/api/open-api/invoice.js +4 -0
- package/dist/api/open-api/license-plate.js +3 -0
- package/dist/api/open-api/login.js +5 -0
- package/dist/api/open-api/red-package.js +3 -0
- package/dist/api/open-api/settings.js +4 -0
- package/dist/api/open-api/soter.js +5 -0
- package/dist/api/open-api/subscribe-message.js +3 -0
- package/dist/api/open-api/user-info.js +4 -0
- package/dist/api/open-api/werun.js +4 -0
- package/dist/api/payment/index.js +4 -0
- package/dist/api/route/index.js +3 -0
- package/dist/api/share/index.js +12 -0
- package/dist/api/storage/background-fetch.js +6 -0
- package/dist/api/storage/index.js +157 -0
- package/dist/api/swan/index.js +26 -0
- package/dist/api/taro.js +47 -0
- package/dist/api/ui/animation/index.js +284 -0
- package/dist/api/ui/background.js +4 -0
- package/dist/api/ui/custom-component.js +3 -0
- package/dist/api/ui/fonts.js +3 -0
- package/dist/api/ui/index.js +12 -0
- package/dist/api/ui/interaction/actionSheet.js +188 -0
- package/dist/api/ui/interaction/index.js +268 -0
- package/dist/api/ui/interaction/modal.js +207 -0
- package/dist/api/ui/interaction/toast.js +195 -0
- package/dist/api/ui/menu.js +3 -0
- package/dist/api/ui/navigation-bar/index.js +42 -0
- package/dist/api/ui/pull-down-refresh.js +26 -0
- package/dist/api/ui/scroll/index.js +83 -0
- package/dist/api/ui/sticky.js +3 -0
- package/dist/api/ui/tab-bar.js +282 -0
- package/dist/api/ui/window.js +31 -0
- package/dist/api/utils/handler.js +80 -0
- package/dist/api/utils/index.js +148 -0
- package/dist/api/worker/index.js +3 -0
- package/dist/api/wxml/index.js +6 -0
- package/dist/api/wxml/nodesRef.js +42 -0
- package/dist/api/wxml/selectorQuery.js +201 -0
- package/dist/index.cjs.js +7852 -11638
- package/dist/index.js +4 -0
- package/dist/taroApis.js +1 -1
- package/dist/types/type.js +2 -0
- package/package.json +14 -16
- 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 +233 -0
- package/src/api/canvas/canvasGetImageData.ts +27 -0
- package/src/api/canvas/canvasPutImageData.ts +24 -0
- package/src/api/canvas/canvasToTempFilePath.ts +24 -0
- package/src/api/canvas/createCanvasContext.ts +18 -0
- package/src/api/canvas/index.ts +10 -0
- package/src/api/cloud/index.ts +27 -0
- package/src/api/data-analysis/index.ts +6 -0
- package/src/api/device/accelerometer.ts +87 -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 +67 -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 +85 -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 +105 -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 +78 -0
- package/src/api/media/image/getImageInfo.ts +35 -0
- package/src/api/media/image/index.ts +13 -0
- package/src/api/media/image/previewImage.ts +80 -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 -27
- 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 -32
- package/src/api/{fileTransfer/utils.js → network/utils.ts} +0 -0
- package/src/api/network/websocket/index.ts +88 -0
- package/src/api/{webSocket/socketTask.js → network/websocket/socketTask.ts} +17 -7
- 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 +181 -0
- package/src/api/swan/index.ts +31 -0
- package/src/{taro/index.js → api/taro.ts} +89 -104
- package/src/api/{createAnimation/index.js → ui/animation/index.ts} +52 -41
- 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} +95 -77
- 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 +27 -0
- package/src/api/ui/scroll/index.ts +85 -0
- 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} +36 -115
- package/src/api/worker/index.ts +4 -0
- package/src/api/wxml/index.ts +9 -0
- package/src/api/wxml/nodesRef.ts +56 -0
- package/src/api/wxml/selectorQuery.ts +219 -0
- 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/canvas/index.js +0 -4
- package/src/api/clipboard/index.js +0 -113
- package/src/api/compass/index.js +0 -99
- package/src/api/createSelectorQuery/index.js +0 -193
- 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/getImageInfo.js +0 -74
- package/src/api/image/index.js +0 -7
- package/src/api/image/previewImage.js +0 -94
- 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/scroll/index.js +0 -99
- 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 -402
- 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/webSocket/index.js +0 -103
- package/src/api/window/index.js +0 -38
- package/src/index.cjs.js +0 -11
- package/src/index.js +0 -6
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import Taro from '@tarojs/api'
|
|
2
|
-
import {
|
|
2
|
+
import { getParameterError, temporarilyNotSupport } from '../../utils'
|
|
3
|
+
import { MethodHandler } from '../../utils/handler'
|
|
3
4
|
import Toast from './toast'
|
|
4
5
|
import Modal from './modal'
|
|
5
6
|
import ActionSheet from './actionSheet'
|
|
6
7
|
|
|
8
|
+
// 交互
|
|
9
|
+
|
|
7
10
|
let status = 'default'
|
|
8
11
|
|
|
9
12
|
// inject necessary style
|
|
@@ -21,26 +24,21 @@ const toast = new Toast()
|
|
|
21
24
|
const modal = new Modal()
|
|
22
25
|
const actionSheet = new ActionSheet()
|
|
23
26
|
|
|
24
|
-
|
|
27
|
+
const showToast: typeof Taro.showToast = (options = { title: '' }) => {
|
|
25
28
|
init(document)
|
|
26
|
-
|
|
27
|
-
const _default = {
|
|
29
|
+
options = Object.assign({
|
|
28
30
|
title: '',
|
|
29
31
|
icon: 'success',
|
|
30
32
|
image: '',
|
|
31
33
|
duration: 1500,
|
|
32
34
|
mask: false
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
// verify options
|
|
38
|
-
const handler = errorHandler(options.fail, options.complete)
|
|
35
|
+
}, options)
|
|
36
|
+
const { success, fail, complete } = options
|
|
37
|
+
const handle = new MethodHandler({ name: 'showToast', success, fail, complete })
|
|
39
38
|
|
|
40
39
|
if (typeof options.title !== 'string') {
|
|
41
|
-
return
|
|
40
|
+
return handle.fail({
|
|
42
41
|
errMsg: getParameterError({
|
|
43
|
-
name: 'showToast',
|
|
44
42
|
para: 'title',
|
|
45
43
|
correct: 'String',
|
|
46
44
|
wrong: options.title
|
|
@@ -49,9 +47,8 @@ function showToast (options = {}) {
|
|
|
49
47
|
}
|
|
50
48
|
|
|
51
49
|
if (typeof options.duration !== 'number') {
|
|
52
|
-
return
|
|
50
|
+
return handle.fail({
|
|
53
51
|
errMsg: getParameterError({
|
|
54
|
-
name: 'showToast',
|
|
55
52
|
para: 'duration',
|
|
56
53
|
correct: 'Number',
|
|
57
54
|
wrong: options.duration
|
|
@@ -63,38 +60,42 @@ function showToast (options = {}) {
|
|
|
63
60
|
|
|
64
61
|
options.mask = !!options.mask
|
|
65
62
|
|
|
66
|
-
|
|
67
|
-
|
|
63
|
+
let errMsg = ''
|
|
64
|
+
if (!toast.el) {
|
|
65
|
+
errMsg = toast.create(options, 'toast')
|
|
66
|
+
} else {
|
|
67
|
+
errMsg = toast.show(options, 'toast')
|
|
68
|
+
}
|
|
69
|
+
return handle.success({ errMsg })
|
|
68
70
|
}
|
|
69
71
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
+
const hideToast: typeof Taro.hideToast = ({ success, fail, complete } = {}) => {
|
|
73
|
+
const handle = new MethodHandler({ name: 'hideToast', success, fail, complete })
|
|
74
|
+
if (!toast.el) return handle.success()
|
|
72
75
|
toast.hide(0, 'toast')
|
|
76
|
+
return handle.success()
|
|
73
77
|
}
|
|
74
78
|
|
|
75
|
-
|
|
79
|
+
const showLoading: typeof Taro.showLoading = (options = { title: '' }) => {
|
|
76
80
|
init(document)
|
|
77
|
-
|
|
78
|
-
const _default = {
|
|
81
|
+
options = Object.assign({
|
|
79
82
|
title: '',
|
|
80
83
|
mask: false
|
|
81
|
-
}
|
|
84
|
+
}, options)
|
|
85
|
+
const { success, fail, complete } = options
|
|
86
|
+
const handle = new MethodHandler({ name: 'showLoading', success, fail, complete })
|
|
87
|
+
|
|
82
88
|
const config = {
|
|
83
89
|
icon: 'loading',
|
|
84
90
|
image: '',
|
|
85
91
|
duration: -1
|
|
86
92
|
}
|
|
87
93
|
|
|
88
|
-
options = Object.assign({},
|
|
89
|
-
options._type = 'loading'
|
|
90
|
-
|
|
91
|
-
// verify options
|
|
92
|
-
const handler = errorHandler(options.fail, options.complete)
|
|
94
|
+
options = Object.assign({}, options, config)
|
|
93
95
|
|
|
94
96
|
if (typeof options.title !== 'string') {
|
|
95
|
-
return
|
|
97
|
+
return handle.fail({
|
|
96
98
|
errMsg: getParameterError({
|
|
97
|
-
name: 'showLoading',
|
|
98
99
|
para: 'title',
|
|
99
100
|
correct: 'String',
|
|
100
101
|
wrong: options.title
|
|
@@ -104,19 +105,25 @@ function showLoading (options = {}) {
|
|
|
104
105
|
|
|
105
106
|
options.mask = !!options.mask
|
|
106
107
|
|
|
107
|
-
|
|
108
|
-
|
|
108
|
+
let errMsg = ''
|
|
109
|
+
if (!toast.el) {
|
|
110
|
+
errMsg = toast.create(options, 'loading')
|
|
111
|
+
} else {
|
|
112
|
+
errMsg = toast.show(options, 'loading')
|
|
113
|
+
}
|
|
114
|
+
return handle.success({ errMsg })
|
|
109
115
|
}
|
|
110
116
|
|
|
111
|
-
|
|
112
|
-
|
|
117
|
+
const hideLoading: typeof Taro.hideLoading = ({ success, fail, complete } = {}) => {
|
|
118
|
+
const handle = new MethodHandler({ name: 'hideLoading', success, fail, complete })
|
|
119
|
+
if (!toast.el) return handle.success()
|
|
113
120
|
toast.hide(0, 'loading')
|
|
121
|
+
return handle.success()
|
|
114
122
|
}
|
|
115
123
|
|
|
116
|
-
|
|
124
|
+
const showModal: typeof Taro.showModal = async (options = {}) => {
|
|
117
125
|
init(document)
|
|
118
|
-
|
|
119
|
-
const _default = {
|
|
126
|
+
options = Object.assign({
|
|
120
127
|
title: '',
|
|
121
128
|
content: '',
|
|
122
129
|
showCancel: true,
|
|
@@ -124,16 +131,13 @@ function showModal (options = {}) {
|
|
|
124
131
|
cancelColor: '#000000',
|
|
125
132
|
confirmText: '确定',
|
|
126
133
|
confirmColor: '#3CC51F'
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
// verify options
|
|
131
|
-
const handler = errorHandler(options.fail, options.complete)
|
|
134
|
+
}, options)
|
|
135
|
+
const { success, fail, complete } = options
|
|
136
|
+
const handle = new MethodHandler({ name: 'showModal', success, fail, complete })
|
|
132
137
|
|
|
133
138
|
if (typeof options.title !== 'string') {
|
|
134
|
-
return
|
|
139
|
+
return handle.fail({
|
|
135
140
|
errMsg: getParameterError({
|
|
136
|
-
name: 'showModal',
|
|
137
141
|
para: 'title',
|
|
138
142
|
correct: 'String',
|
|
139
143
|
wrong: options.title
|
|
@@ -142,9 +146,8 @@ function showModal (options = {}) {
|
|
|
142
146
|
}
|
|
143
147
|
|
|
144
148
|
if (typeof options.content !== 'string') {
|
|
145
|
-
return
|
|
149
|
+
return handle.fail({
|
|
146
150
|
errMsg: getParameterError({
|
|
147
|
-
name: 'showModal',
|
|
148
151
|
para: 'content',
|
|
149
152
|
correct: 'String',
|
|
150
153
|
wrong: options.content
|
|
@@ -153,9 +156,8 @@ function showModal (options = {}) {
|
|
|
153
156
|
}
|
|
154
157
|
|
|
155
158
|
if (typeof options.cancelText !== 'string') {
|
|
156
|
-
return
|
|
159
|
+
return handle.fail({
|
|
157
160
|
errMsg: getParameterError({
|
|
158
|
-
name: 'showModal',
|
|
159
161
|
para: 'cancelText',
|
|
160
162
|
correct: 'String',
|
|
161
163
|
wrong: options.cancelText
|
|
@@ -164,13 +166,14 @@ function showModal (options = {}) {
|
|
|
164
166
|
}
|
|
165
167
|
|
|
166
168
|
if (options.cancelText.replace(/[\u0391-\uFFE5]/g, 'aa').length > 8) {
|
|
167
|
-
return
|
|
169
|
+
return handle.fail({
|
|
170
|
+
errMsg: 'cancelText length should not larger then 4 Chinese characters'
|
|
171
|
+
})
|
|
168
172
|
}
|
|
169
173
|
|
|
170
174
|
if (typeof options.confirmText !== 'string') {
|
|
171
|
-
return
|
|
175
|
+
return handle.fail({
|
|
172
176
|
errMsg: getParameterError({
|
|
173
|
-
name: 'showModal',
|
|
174
177
|
para: 'confirmText',
|
|
175
178
|
correct: 'String',
|
|
176
179
|
wrong: options.confirmText
|
|
@@ -179,13 +182,14 @@ function showModal (options = {}) {
|
|
|
179
182
|
}
|
|
180
183
|
|
|
181
184
|
if (options.confirmText.replace(/[\u0391-\uFFE5]/g, 'aa').length > 8) {
|
|
182
|
-
return
|
|
185
|
+
return handle.fail({
|
|
186
|
+
errMsg: 'confirmText length should not larger then 4 Chinese characters'
|
|
187
|
+
})
|
|
183
188
|
}
|
|
184
189
|
|
|
185
190
|
if (typeof options.cancelColor !== 'string') {
|
|
186
|
-
return
|
|
191
|
+
return handle.fail({
|
|
187
192
|
errMsg: getParameterError({
|
|
188
|
-
name: 'showModal',
|
|
189
193
|
para: 'cancelColor',
|
|
190
194
|
correct: 'String',
|
|
191
195
|
wrong: options.cancelColor
|
|
@@ -194,9 +198,8 @@ function showModal (options = {}) {
|
|
|
194
198
|
}
|
|
195
199
|
|
|
196
200
|
if (typeof options.confirmColor !== 'string') {
|
|
197
|
-
return
|
|
201
|
+
return handle.fail({
|
|
198
202
|
errMsg: getParameterError({
|
|
199
|
-
name: 'showModal',
|
|
200
203
|
para: 'confirmColor',
|
|
201
204
|
correct: 'String',
|
|
202
205
|
wrong: options.confirmColor
|
|
@@ -206,8 +209,15 @@ function showModal (options = {}) {
|
|
|
206
209
|
|
|
207
210
|
options.showCancel = !!options.showCancel
|
|
208
211
|
|
|
209
|
-
|
|
210
|
-
|
|
212
|
+
let result = ''
|
|
213
|
+
if (!modal.el) {
|
|
214
|
+
result = await modal.create(options)
|
|
215
|
+
} else {
|
|
216
|
+
result = await modal.show(options)
|
|
217
|
+
}
|
|
218
|
+
const res = { cancel: !1, confirm: !1 }
|
|
219
|
+
res[result] = !0
|
|
220
|
+
return handle.success(res)
|
|
211
221
|
}
|
|
212
222
|
|
|
213
223
|
function hideModal () {
|
|
@@ -215,22 +225,19 @@ function hideModal () {
|
|
|
215
225
|
modal.hide()
|
|
216
226
|
}
|
|
217
227
|
|
|
218
|
-
|
|
228
|
+
const showActionSheet: typeof Taro.showActionSheet = async (options = { itemList: [] }) => {
|
|
219
229
|
init(document)
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
// verify options
|
|
227
|
-
const handler = errorHandler(options.fail, options.complete)
|
|
230
|
+
options = Object.assign({
|
|
231
|
+
itemColor: '#000000',
|
|
232
|
+
itemList: []
|
|
233
|
+
}, options)
|
|
234
|
+
const { success, fail, complete } = options
|
|
235
|
+
const handle = new MethodHandler<Taro.showActionSheet.SuccessCallbackResult>({ name: 'showActionSheet', success, fail, complete })
|
|
228
236
|
|
|
229
237
|
// list item String
|
|
230
238
|
if (!Array.isArray(options.itemList)) {
|
|
231
|
-
return
|
|
239
|
+
return handle.fail({
|
|
232
240
|
errMsg: getParameterError({
|
|
233
|
-
name: 'showActionSheet',
|
|
234
241
|
para: 'itemList',
|
|
235
242
|
correct: 'Array',
|
|
236
243
|
wrong: options.itemList
|
|
@@ -239,18 +246,17 @@ function showActionSheet (options = {}) {
|
|
|
239
246
|
}
|
|
240
247
|
|
|
241
248
|
if (options.itemList.length < 1) {
|
|
242
|
-
return
|
|
249
|
+
return handle.fail({ errMsg: 'parameter error: parameter.itemList should have at least 1 item' })
|
|
243
250
|
}
|
|
244
251
|
|
|
245
252
|
if (options.itemList.length > 6) {
|
|
246
|
-
return
|
|
253
|
+
return handle.fail({ errMsg: 'parameter error: parameter.itemList should not be large than 6' })
|
|
247
254
|
}
|
|
248
255
|
|
|
249
256
|
for (let i = 0; i < options.itemList.length; i++) {
|
|
250
257
|
if (typeof options.itemList[i] !== 'string') {
|
|
251
|
-
return
|
|
258
|
+
return handle.fail({
|
|
252
259
|
errMsg: getParameterError({
|
|
253
|
-
name: 'showActionSheet',
|
|
254
260
|
para: `itemList[${i}]`,
|
|
255
261
|
correct: 'String',
|
|
256
262
|
wrong: options.itemList[i]
|
|
@@ -260,9 +266,8 @@ function showActionSheet (options = {}) {
|
|
|
260
266
|
}
|
|
261
267
|
|
|
262
268
|
if (typeof options.itemColor !== 'string') {
|
|
263
|
-
return
|
|
269
|
+
return handle.fail({
|
|
264
270
|
errMsg: getParameterError({
|
|
265
|
-
name: 'showActionSheet',
|
|
266
271
|
para: 'itemColor',
|
|
267
272
|
correct: 'String',
|
|
268
273
|
wrong: options.itemColor
|
|
@@ -270,8 +275,18 @@ function showActionSheet (options = {}) {
|
|
|
270
275
|
})
|
|
271
276
|
}
|
|
272
277
|
|
|
273
|
-
|
|
274
|
-
|
|
278
|
+
let result: number | string = ''
|
|
279
|
+
if (!actionSheet.el) {
|
|
280
|
+
result = await actionSheet.create(options)
|
|
281
|
+
} else {
|
|
282
|
+
result = await actionSheet.show(options)
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
if (typeof result === 'string') {
|
|
286
|
+
return handle.fail(({ errMsg: result }))
|
|
287
|
+
} else {
|
|
288
|
+
return handle.success(({ tapIndex: result }))
|
|
289
|
+
}
|
|
275
290
|
}
|
|
276
291
|
|
|
277
292
|
Taro.eventCenter.on('__taroRouterChange', () => {
|
|
@@ -280,4 +295,7 @@ Taro.eventCenter.on('__taroRouterChange', () => {
|
|
|
280
295
|
hideModal()
|
|
281
296
|
})
|
|
282
297
|
|
|
283
|
-
|
|
298
|
+
const enableAlertBeforeUnload = temporarilyNotSupport('enableAlertBeforeUnload')
|
|
299
|
+
const disableAlertBeforeUnload = temporarilyNotSupport('disableAlertBeforeUnload')
|
|
300
|
+
|
|
301
|
+
export { showToast, showModal, showLoading, showActionSheet, hideToast, hideLoading, enableAlertBeforeUnload, disableAlertBeforeUnload }
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import { inlineStyle } from '../../utils'
|
|
2
|
+
|
|
3
|
+
export default class Modal {
|
|
4
|
+
options = {
|
|
5
|
+
title: '',
|
|
6
|
+
content: '',
|
|
7
|
+
showCancel: true,
|
|
8
|
+
cancelText: '取消',
|
|
9
|
+
cancelColor: '#000000',
|
|
10
|
+
confirmText: '确定',
|
|
11
|
+
confirmColor: '#3CC51F'
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
style = {
|
|
15
|
+
maskStyle: {
|
|
16
|
+
position: 'fixed',
|
|
17
|
+
'z-index': '1000',
|
|
18
|
+
top: '0',
|
|
19
|
+
right: '0',
|
|
20
|
+
left: '0',
|
|
21
|
+
bottom: '0',
|
|
22
|
+
background: 'rgba(0,0,0,0.6)'
|
|
23
|
+
},
|
|
24
|
+
modalStyle: {
|
|
25
|
+
'z-index': '4999',
|
|
26
|
+
position: 'fixed',
|
|
27
|
+
top: '50%',
|
|
28
|
+
left: '50%',
|
|
29
|
+
transform: 'translate(-50%, -50%)',
|
|
30
|
+
width: '80%',
|
|
31
|
+
'max-width': '300px',
|
|
32
|
+
'border-radius': '3px',
|
|
33
|
+
'text-align': 'center',
|
|
34
|
+
'line-height': '1.6',
|
|
35
|
+
overflow: 'hidden',
|
|
36
|
+
background: '#FFFFFF'
|
|
37
|
+
},
|
|
38
|
+
titleStyle: {
|
|
39
|
+
padding: '20px 24px 9px',
|
|
40
|
+
'font-size': '18px'
|
|
41
|
+
},
|
|
42
|
+
textStyle: {
|
|
43
|
+
padding: '0 24px 12px',
|
|
44
|
+
'min-height': '40px',
|
|
45
|
+
'font-size': '15px',
|
|
46
|
+
'line-height': '1.3',
|
|
47
|
+
color: '#808080'
|
|
48
|
+
},
|
|
49
|
+
footStyle: {
|
|
50
|
+
position: 'relative',
|
|
51
|
+
'line-height': '48px',
|
|
52
|
+
'font-size': '18px',
|
|
53
|
+
display: 'flex'
|
|
54
|
+
},
|
|
55
|
+
btnStyle: {
|
|
56
|
+
position: 'relative',
|
|
57
|
+
'-webkit-box-flex': '1',
|
|
58
|
+
'-webkit-flex': '1',
|
|
59
|
+
flex: '1'
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
el: HTMLDivElement
|
|
64
|
+
title: HTMLDivElement
|
|
65
|
+
text: HTMLDivElement
|
|
66
|
+
cancel: HTMLDivElement
|
|
67
|
+
confirm: HTMLDivElement
|
|
68
|
+
hideOpacityTimer: any
|
|
69
|
+
hideDisplayTimer: any
|
|
70
|
+
|
|
71
|
+
create (options = {}) {
|
|
72
|
+
return new Promise<string>((resolve) => {
|
|
73
|
+
// style
|
|
74
|
+
const { maskStyle, modalStyle, titleStyle, textStyle, footStyle, btnStyle } = this.style
|
|
75
|
+
|
|
76
|
+
// configuration
|
|
77
|
+
const config = {
|
|
78
|
+
...this.options,
|
|
79
|
+
...options
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// wrapper
|
|
83
|
+
this.el = document.createElement('div')
|
|
84
|
+
this.el.className = 'taro__modal'
|
|
85
|
+
this.el.style.opacity = '0'
|
|
86
|
+
this.el.style.transition = 'opacity 0.2s linear'
|
|
87
|
+
|
|
88
|
+
// mask
|
|
89
|
+
const mask = document.createElement('div')
|
|
90
|
+
mask.className = 'taro-modal__mask'
|
|
91
|
+
mask.setAttribute('style', inlineStyle(maskStyle))
|
|
92
|
+
|
|
93
|
+
// modal
|
|
94
|
+
const modal = document.createElement('div')
|
|
95
|
+
modal.className = 'taro-modal__content'
|
|
96
|
+
modal.setAttribute('style', inlineStyle(modalStyle))
|
|
97
|
+
|
|
98
|
+
// title
|
|
99
|
+
const titleCSS = config.title ? titleStyle : {
|
|
100
|
+
...titleStyle,
|
|
101
|
+
display: 'none'
|
|
102
|
+
}
|
|
103
|
+
this.title = document.createElement('div')
|
|
104
|
+
|
|
105
|
+
this.title.className = 'taro-modal__title'
|
|
106
|
+
this.title.setAttribute('style', inlineStyle(titleCSS))
|
|
107
|
+
this.title.textContent = config.title
|
|
108
|
+
|
|
109
|
+
// text
|
|
110
|
+
const textCSS = config.title ? textStyle : {
|
|
111
|
+
...textStyle,
|
|
112
|
+
padding: '40px 20px 26px',
|
|
113
|
+
color: '#353535'
|
|
114
|
+
}
|
|
115
|
+
this.text = document.createElement('div')
|
|
116
|
+
this.text.className = 'taro-modal__text'
|
|
117
|
+
this.text.setAttribute('style', inlineStyle(textCSS))
|
|
118
|
+
this.text.textContent = config.content
|
|
119
|
+
|
|
120
|
+
// foot
|
|
121
|
+
const foot = document.createElement('div')
|
|
122
|
+
foot.className = 'taro-modal__foot'
|
|
123
|
+
foot.setAttribute('style', inlineStyle(footStyle))
|
|
124
|
+
|
|
125
|
+
// cancel button
|
|
126
|
+
const cancelCSS = {
|
|
127
|
+
...btnStyle,
|
|
128
|
+
color: config.cancelColor,
|
|
129
|
+
display: config.showCancel ? 'block' : 'none'
|
|
130
|
+
}
|
|
131
|
+
this.cancel = document.createElement('div')
|
|
132
|
+
this.cancel.className = 'taro-model__btn taro-model__cancel'
|
|
133
|
+
this.cancel.setAttribute('style', inlineStyle(cancelCSS))
|
|
134
|
+
this.cancel.textContent = config.cancelText
|
|
135
|
+
this.cancel.onclick = () => {
|
|
136
|
+
this.hide()
|
|
137
|
+
resolve('cancel')
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// confirm button
|
|
141
|
+
this.confirm = document.createElement('div')
|
|
142
|
+
this.confirm.className = 'taro-model__btn taro-model__confirm'
|
|
143
|
+
this.confirm.setAttribute('style', inlineStyle(btnStyle))
|
|
144
|
+
this.confirm.style.color = config.confirmColor
|
|
145
|
+
this.confirm.textContent = config.confirmText
|
|
146
|
+
this.confirm.onclick = () => {
|
|
147
|
+
this.hide()
|
|
148
|
+
resolve('confirm')
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// result
|
|
152
|
+
foot.appendChild(this.cancel)
|
|
153
|
+
foot.appendChild(this.confirm)
|
|
154
|
+
modal.appendChild(this.title)
|
|
155
|
+
modal.appendChild(this.text)
|
|
156
|
+
modal.appendChild(foot)
|
|
157
|
+
this.el.appendChild(mask)
|
|
158
|
+
this.el.appendChild(modal)
|
|
159
|
+
|
|
160
|
+
// show immediately
|
|
161
|
+
document.body.appendChild(this.el)
|
|
162
|
+
setTimeout(() => { this.el.style.opacity = '1' }, 0)
|
|
163
|
+
})
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
show (options = {}) {
|
|
167
|
+
return new Promise<string>((resolve) => {
|
|
168
|
+
const config = {
|
|
169
|
+
...this.options,
|
|
170
|
+
...options
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
if (this.hideOpacityTimer) clearTimeout(this.hideOpacityTimer)
|
|
174
|
+
if (this.hideDisplayTimer) clearTimeout(this.hideDisplayTimer)
|
|
175
|
+
|
|
176
|
+
// title & text
|
|
177
|
+
const { textStyle } = this.style
|
|
178
|
+
|
|
179
|
+
if (config.title) {
|
|
180
|
+
this.title.textContent = config.title
|
|
181
|
+
// none => block
|
|
182
|
+
this.title.style.display = 'block'
|
|
183
|
+
this.text.setAttribute('style', inlineStyle(textStyle))
|
|
184
|
+
} else {
|
|
185
|
+
// block => none
|
|
186
|
+
this.title.style.display = 'none'
|
|
187
|
+
const textCSS = {
|
|
188
|
+
...textStyle,
|
|
189
|
+
padding: '40px 20px 26px',
|
|
190
|
+
color: '#353535'
|
|
191
|
+
}
|
|
192
|
+
this.text.setAttribute('style', inlineStyle(textCSS))
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
this.text.textContent = config.content || ''
|
|
196
|
+
|
|
197
|
+
// showCancel
|
|
198
|
+
this.cancel.style.display = config.showCancel ? 'block' : 'none'
|
|
199
|
+
|
|
200
|
+
// cancelText
|
|
201
|
+
this.cancel.textContent = config.cancelText || ''
|
|
202
|
+
|
|
203
|
+
// cancelColor
|
|
204
|
+
this.cancel.style.color = config.cancelColor || ''
|
|
205
|
+
|
|
206
|
+
// confirmText
|
|
207
|
+
this.confirm.textContent = config.confirmText || ''
|
|
208
|
+
|
|
209
|
+
// confirmColor
|
|
210
|
+
this.confirm.style.color = config.confirmColor || ''
|
|
211
|
+
|
|
212
|
+
// cbs
|
|
213
|
+
this.cancel.onclick = () => {
|
|
214
|
+
this.hide()
|
|
215
|
+
resolve('cancel')
|
|
216
|
+
}
|
|
217
|
+
this.confirm.onclick = () => {
|
|
218
|
+
this.hide()
|
|
219
|
+
resolve('confirm')
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// show
|
|
223
|
+
this.el.style.display = 'block'
|
|
224
|
+
setTimeout(() => { this.el.style.opacity = '1' }, 0)
|
|
225
|
+
})
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
hide () {
|
|
229
|
+
if (this.hideOpacityTimer) clearTimeout(this.hideOpacityTimer)
|
|
230
|
+
if (this.hideDisplayTimer) clearTimeout(this.hideDisplayTimer)
|
|
231
|
+
|
|
232
|
+
this.hideOpacityTimer = setTimeout(() => {
|
|
233
|
+
this.el.style.opacity = '0'
|
|
234
|
+
this.hideDisplayTimer = setTimeout(() => { this.el.style.display = 'none' }, 200)
|
|
235
|
+
}, 0)
|
|
236
|
+
}
|
|
237
|
+
}
|