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