@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
|
@@ -1,237 +0,0 @@
|
|
|
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: ReturnType<typeof setTimeout>
|
|
69
|
-
hideDisplayTimer: ReturnType<typeof setTimeout>
|
|
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
|
-
}
|
|
@@ -1,220 +0,0 @@
|
|
|
1
|
-
import { inlineStyle } from '../../../utils'
|
|
2
|
-
|
|
3
|
-
export default class Toast {
|
|
4
|
-
options = {
|
|
5
|
-
title: '',
|
|
6
|
-
icon: 'none',
|
|
7
|
-
image: '',
|
|
8
|
-
duration: 1500,
|
|
9
|
-
mask: false
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
style = {
|
|
13
|
-
maskStyle: {
|
|
14
|
-
position: 'fixed',
|
|
15
|
-
'z-index': '1000',
|
|
16
|
-
top: '0',
|
|
17
|
-
right: '0',
|
|
18
|
-
left: '0',
|
|
19
|
-
bottom: '0'
|
|
20
|
-
},
|
|
21
|
-
toastStyle: {
|
|
22
|
-
'z-index': '5000',
|
|
23
|
-
'box-sizing': 'border-box',
|
|
24
|
-
display: 'flex',
|
|
25
|
-
'flex-direction': 'column',
|
|
26
|
-
'justify-content': 'center',
|
|
27
|
-
'-webkit-justify-content': 'center',
|
|
28
|
-
position: 'fixed',
|
|
29
|
-
top: '50%',
|
|
30
|
-
left: '50%',
|
|
31
|
-
'min-width': '120px',
|
|
32
|
-
'max-width': '200px',
|
|
33
|
-
'min-height': '120px',
|
|
34
|
-
padding: '15px',
|
|
35
|
-
transform: 'translate(-50%, -50%)',
|
|
36
|
-
'border-radius': '5px',
|
|
37
|
-
'text-align': 'center',
|
|
38
|
-
'line-height': '1.6',
|
|
39
|
-
color: '#FFFFFF',
|
|
40
|
-
background: 'rgba(17, 17, 17, 0.7)'
|
|
41
|
-
},
|
|
42
|
-
successStyle: {
|
|
43
|
-
margin: '6px auto',
|
|
44
|
-
width: '38px',
|
|
45
|
-
height: '38px',
|
|
46
|
-
background: 'transparent url(data:image/svg+xml;base64,PHN2ZyB0PSIxNjM5NTQ4OTYzMjA0IiBjbGFzcz0iaWNvbiIgdmlld0JveD0iMCAwIDEwMjQgMTAyNCIgdmVyc2lvbj0iMS4xIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHAtaWQ9IjQzNDgiIHdpZHRoPSIyMDAiIGhlaWdodD0iMjAwIj48cGF0aCBkPSJNMjE5Ljk1MiA1MTIuNTc2bDIxMC40MzIgMjEwLjQzMi00NS4yNDggNDUuMjU2LTIxMC40MzItMjEwLjQzMnoiIHAtaWQ9IjQzNDkiIGZpbGw9IiNmZmZmZmYiPjwvcGF0aD48cGF0aCBkPSJNNzk5LjY3MiAyNjIuMjY0bDQ1LjI1NiA0NS4yNTYtNDYwLjQ2NCA0NjAuNDY0LTQ1LjI1Ni00NS4yNTZ6IiBwLWlkPSI0MzUwIiBmaWxsPSIjZmZmZmZmIj48L3BhdGg+PC9zdmc+) no-repeat',
|
|
47
|
-
'background-size': '100%'
|
|
48
|
-
},
|
|
49
|
-
errrorStyle: {
|
|
50
|
-
margin: '6px auto',
|
|
51
|
-
width: '38px',
|
|
52
|
-
height: '38px',
|
|
53
|
-
background: 'transparent url(data:image/svg+xml;base64,PHN2ZyB0PSIxNjM5NTUxMDU1MTgzIiBjbGFzcz0iaWNvbiIgdmlld0JveD0iMCAwIDEwMjQgMTAyNCIgdmVyc2lvbj0iMS4xIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHAtaWQ9IjE0MDc2IiB3aWR0aD0iMjAwIiBoZWlnaHQ9IjIwMCI+PHBhdGggZD0iTTUxMiA2NEMyNjQuNTggNjQgNjQgMjY0LjU4IDY0IDUxMnMyMDAuNTggNDQ4IDQ0OCA0NDggNDQ4LTIwMC41OCA0NDgtNDQ4Uzc1OS40MiA2NCA1MTIgNjR6IG0wIDc1MmEzNiAzNiAwIDEgMSAzNi0zNiAzNiAzNiAwIDAgMS0zNiAzNnogbTUxLjgzLTU1MS45NUw1NDggNjM2YTM2IDM2IDAgMCAxLTcyIDBsLTE1LjgzLTM3MS45NWMtMC4xLTEuMzMtMC4xNy0yLjY4LTAuMTctNC4wNWE1MiA1MiAwIDAgMSAxMDQgMGMwIDEuMzctMC4wNyAyLjcyLTAuMTcgNC4wNXoiIHAtaWQ9IjE0MDc3IiBmaWxsPSIjZmZmZmZmIj48L3BhdGg+PC9zdmc+) no-repeat',
|
|
54
|
-
'background-size': '100%'
|
|
55
|
-
},
|
|
56
|
-
loadingStyle: {
|
|
57
|
-
margin: '6px auto',
|
|
58
|
-
width: '38px',
|
|
59
|
-
height: '38px',
|
|
60
|
-
'-webkit-animation': 'taroLoading 1s steps(12, end) infinite',
|
|
61
|
-
animation: 'taroLoading 1s steps(12, end) infinite',
|
|
62
|
-
background: 'transparent url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxMjAiIGhlaWdodD0iMTIwIiB2aWV3Qm94PSIwIDAgMTAwIDEwMCI+PHBhdGggZmlsbD0ibm9uZSIgZD0iTTAgMGgxMDB2MTAwSDB6Ii8+PHJlY3Qgd2lkdGg9IjciIGhlaWdodD0iMjAiIHg9IjQ2LjUiIHk9IjQwIiBmaWxsPSIjRTlFOUU5IiByeD0iNSIgcnk9IjUiIHRyYW5zZm9ybT0idHJhbnNsYXRlKDAgLTMwKSIvPjxyZWN0IHdpZHRoPSI3IiBoZWlnaHQ9IjIwIiB4PSI0Ni41IiB5PSI0MCIgZmlsbD0iIzk4OTY5NyIgcng9IjUiIHJ5PSI1IiB0cmFuc2Zvcm09InJvdGF0ZSgzMCAxMDUuOTggNjUpIi8+PHJlY3Qgd2lkdGg9IjciIGhlaWdodD0iMjAiIHg9IjQ2LjUiIHk9IjQwIiBmaWxsPSIjOUI5OTlBIiByeD0iNSIgcnk9IjUiIHRyYW5zZm9ybT0icm90YXRlKDYwIDc1Ljk4IDY1KSIvPjxyZWN0IHdpZHRoPSI3IiBoZWlnaHQ9IjIwIiB4PSI0Ni41IiB5PSI0MCIgZmlsbD0iI0EzQTFBMiIgcng9IjUiIHJ5PSI1IiB0cmFuc2Zvcm09InJvdGF0ZSg5MCA2NSA2NSkiLz48cmVjdCB3aWR0aD0iNyIgaGVpZ2h0PSIyMCIgeD0iNDYuNSIgeT0iNDAiIGZpbGw9IiNBQkE5QUEiIHJ4PSI1IiByeT0iNSIgdHJhbnNmb3JtPSJyb3RhdGUoMTIwIDU4LjY2IDY1KSIvPjxyZWN0IHdpZHRoPSI3IiBoZWlnaHQ9IjIwIiB4PSI0Ni41IiB5PSI0MCIgZmlsbD0iI0IyQjJCMiIgcng9IjUiIHJ5PSI1IiB0cmFuc2Zvcm09InJvdGF0ZSgxNTAgNTQuMDIgNjUpIi8+PHJlY3Qgd2lkdGg9IjciIGhlaWdodD0iMjAiIHg9IjQ2LjUiIHk9IjQwIiBmaWxsPSIjQkFCOEI5IiByeD0iNSIgcnk9IjUiIHRyYW5zZm9ybT0icm90YXRlKDE4MCA1MCA2NSkiLz48cmVjdCB3aWR0aD0iNyIgaGVpZ2h0PSIyMCIgeD0iNDYuNSIgeT0iNDAiIGZpbGw9IiNDMkMwQzEiIHJ4PSI1IiByeT0iNSIgdHJhbnNmb3JtPSJyb3RhdGUoLTE1MCA0NS45OCA2NSkiLz48cmVjdCB3aWR0aD0iNyIgaGVpZ2h0PSIyMCIgeD0iNDYuNSIgeT0iNDAiIGZpbGw9IiNDQkNCQ0IiIHJ4PSI1IiByeT0iNSIgdHJhbnNmb3JtPSJyb3RhdGUoLTEyMCA0MS4zNCA2NSkiLz48cmVjdCB3aWR0aD0iNyIgaGVpZ2h0PSIyMCIgeD0iNDYuNSIgeT0iNDAiIGZpbGw9IiNEMkQyRDIiIHJ4PSI1IiByeT0iNSIgdHJhbnNmb3JtPSJyb3RhdGUoLTkwIDM1IDY1KSIvPjxyZWN0IHdpZHRoPSI3IiBoZWlnaHQ9IjIwIiB4PSI0Ni41IiB5PSI0MCIgZmlsbD0iI0RBREFEQSIgcng9IjUiIHJ5PSI1IiB0cmFuc2Zvcm09InJvdGF0ZSgtNjAgMjQuMDIgNjUpIi8+PHJlY3Qgd2lkdGg9IjciIGhlaWdodD0iMjAiIHg9IjQ2LjUiIHk9IjQwIiBmaWxsPSIjRTJFMkUyIiByeD0iNSIgcnk9IjUiIHRyYW5zZm9ybT0icm90YXRlKC0zMCAtNS45OCA2NSkiLz48L3N2Zz4=) no-repeat',
|
|
63
|
-
'background-size': '100%'
|
|
64
|
-
},
|
|
65
|
-
imageStyle: {
|
|
66
|
-
margin: '6px auto',
|
|
67
|
-
width: '40px',
|
|
68
|
-
height: '40px',
|
|
69
|
-
background: 'transparent no-repeat',
|
|
70
|
-
'background-size': '100%'
|
|
71
|
-
},
|
|
72
|
-
textStyle: {
|
|
73
|
-
margin: '0',
|
|
74
|
-
'font-size': '16px'
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
el: HTMLDivElement
|
|
79
|
-
mask: HTMLDivElement
|
|
80
|
-
icon: HTMLParagraphElement
|
|
81
|
-
toast: HTMLDivElement
|
|
82
|
-
title: HTMLParagraphElement
|
|
83
|
-
type: any
|
|
84
|
-
hideOpacityTimer: ReturnType<typeof setTimeout>
|
|
85
|
-
hideDisplayTimer: ReturnType<typeof setTimeout>
|
|
86
|
-
|
|
87
|
-
create (options = {}, _type: 'loading' | 'toast' = 'toast') {
|
|
88
|
-
// style
|
|
89
|
-
const { maskStyle, toastStyle, successStyle, errrorStyle, loadingStyle, imageStyle, textStyle } = this.style
|
|
90
|
-
|
|
91
|
-
// configuration
|
|
92
|
-
const config = {
|
|
93
|
-
...this.options,
|
|
94
|
-
...options,
|
|
95
|
-
_type
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// wrapper
|
|
99
|
-
this.el = document.createElement('div')
|
|
100
|
-
this.el.className = 'taro__toast'
|
|
101
|
-
this.el.style.opacity = '0'
|
|
102
|
-
this.el.style.transition = 'opacity 0.1s linear'
|
|
103
|
-
|
|
104
|
-
// mask
|
|
105
|
-
this.mask = document.createElement('div')
|
|
106
|
-
this.mask.setAttribute('style', inlineStyle(maskStyle))
|
|
107
|
-
this.mask.style.display = config.mask ? 'block' : 'none'
|
|
108
|
-
|
|
109
|
-
// icon
|
|
110
|
-
this.icon = document.createElement('p')
|
|
111
|
-
if (config.image) {
|
|
112
|
-
this.icon.setAttribute('style', inlineStyle({
|
|
113
|
-
...imageStyle,
|
|
114
|
-
'background-image': `url(${config.image})`
|
|
115
|
-
}))
|
|
116
|
-
} else {
|
|
117
|
-
const iconStyle = config.icon === 'loading' ? loadingStyle : config.icon === 'error' ? errrorStyle : successStyle
|
|
118
|
-
this.icon.setAttribute('style', inlineStyle({
|
|
119
|
-
...iconStyle,
|
|
120
|
-
...(config.icon === 'none' ? { display: 'none' } : {})
|
|
121
|
-
}))
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
// toast
|
|
125
|
-
this.toast = document.createElement('div')
|
|
126
|
-
this.toast.setAttribute('style', inlineStyle({
|
|
127
|
-
...toastStyle,
|
|
128
|
-
...(config.icon === 'none' ? {
|
|
129
|
-
'min-height': '0',
|
|
130
|
-
padding: '10px 15px'
|
|
131
|
-
} : {})
|
|
132
|
-
}))
|
|
133
|
-
|
|
134
|
-
// title
|
|
135
|
-
this.title = document.createElement('p')
|
|
136
|
-
this.title.setAttribute('style', inlineStyle(textStyle))
|
|
137
|
-
this.title.textContent = config.title
|
|
138
|
-
|
|
139
|
-
// result
|
|
140
|
-
this.toast.appendChild(this.icon)
|
|
141
|
-
this.toast.appendChild(this.title)
|
|
142
|
-
this.el.appendChild(this.mask)
|
|
143
|
-
this.el.appendChild(this.toast)
|
|
144
|
-
|
|
145
|
-
// show immediately
|
|
146
|
-
document.body.appendChild(this.el)
|
|
147
|
-
setTimeout(() => { this.el.style.opacity = '1' }, 0)
|
|
148
|
-
this.type = config._type
|
|
149
|
-
|
|
150
|
-
// disappear after duration
|
|
151
|
-
config.duration >= 0 && this.hide(config.duration, this.type)
|
|
152
|
-
|
|
153
|
-
return ''
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
show (options = {}, _type: 'loading' | 'toast' = 'toast') {
|
|
157
|
-
const config = {
|
|
158
|
-
...this.options,
|
|
159
|
-
...options,
|
|
160
|
-
_type
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
if (this.hideOpacityTimer) clearTimeout(this.hideOpacityTimer)
|
|
164
|
-
if (this.hideDisplayTimer) clearTimeout(this.hideDisplayTimer)
|
|
165
|
-
|
|
166
|
-
// title
|
|
167
|
-
this.title.textContent = config.title || ''
|
|
168
|
-
|
|
169
|
-
// mask
|
|
170
|
-
this.mask.style.display = config.mask ? 'block' : 'none'
|
|
171
|
-
|
|
172
|
-
// image
|
|
173
|
-
const { toastStyle, successStyle, errrorStyle, loadingStyle, imageStyle } = this.style
|
|
174
|
-
if (config.image) {
|
|
175
|
-
this.icon.setAttribute('style', inlineStyle({
|
|
176
|
-
...imageStyle,
|
|
177
|
-
'background-image': `url(${config.image})`
|
|
178
|
-
}))
|
|
179
|
-
} else {
|
|
180
|
-
if (!config.image && config.icon) {
|
|
181
|
-
const iconStyle = config.icon === 'loading' ? loadingStyle : config.icon === 'error' ? errrorStyle : successStyle
|
|
182
|
-
this.icon.setAttribute('style', inlineStyle({
|
|
183
|
-
...iconStyle,
|
|
184
|
-
...(config.icon === 'none' ? { display: 'none' } : {})
|
|
185
|
-
}))
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
// toast
|
|
190
|
-
this.toast.setAttribute('style', inlineStyle({
|
|
191
|
-
...toastStyle,
|
|
192
|
-
...(config.icon === 'none' ? {
|
|
193
|
-
'min-height': '0',
|
|
194
|
-
padding: '10px 15px'
|
|
195
|
-
} : {})
|
|
196
|
-
}))
|
|
197
|
-
|
|
198
|
-
// show
|
|
199
|
-
this.el.style.display = 'block'
|
|
200
|
-
setTimeout(() => { this.el.style.opacity = '1' }, 0)
|
|
201
|
-
this.type = config._type
|
|
202
|
-
|
|
203
|
-
// disappear after duration
|
|
204
|
-
config.duration >= 0 && this.hide(config.duration, this.type)
|
|
205
|
-
|
|
206
|
-
return ''
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
hide (duration = 0, type) {
|
|
210
|
-
if (this.type !== type) return
|
|
211
|
-
|
|
212
|
-
if (this.hideOpacityTimer) clearTimeout(this.hideOpacityTimer)
|
|
213
|
-
if (this.hideDisplayTimer) clearTimeout(this.hideDisplayTimer)
|
|
214
|
-
|
|
215
|
-
this.hideOpacityTimer = setTimeout(() => {
|
|
216
|
-
this.el.style.opacity = '0'
|
|
217
|
-
this.hideDisplayTimer = setTimeout(() => { this.el.style.display = 'none' }, 100)
|
|
218
|
-
}, duration)
|
|
219
|
-
}
|
|
220
|
-
}
|
package/src/api/ui/menu.ts
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import Taro from '@tarojs/api'
|
|
2
|
-
|
|
3
|
-
import { getParameterError, shouldBeObject, temporarilyNotSupport } from '../../../utils'
|
|
4
|
-
import { MethodHandler } from '../../../utils/handler'
|
|
5
|
-
|
|
6
|
-
// 导航栏
|
|
7
|
-
export const showNavigationBarLoading = temporarilyNotSupport('showNavigationBarLoading')
|
|
8
|
-
|
|
9
|
-
export function setNavigationBarTitle (options) {
|
|
10
|
-
// options must be an Object
|
|
11
|
-
const isObject = shouldBeObject(options)
|
|
12
|
-
if (!isObject.flag) {
|
|
13
|
-
const res = { errMsg: `setNavigationBarTitle:fail ${isObject.msg}` }
|
|
14
|
-
console.error(res.errMsg)
|
|
15
|
-
return Promise.reject(res)
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const { title, success, fail, complete } = options
|
|
19
|
-
const handle = new MethodHandler({ name: 'setNavigationBarTitle', success, fail, complete })
|
|
20
|
-
|
|
21
|
-
if (!title || typeof title !== 'string') {
|
|
22
|
-
return handle.fail({
|
|
23
|
-
errMsg: getParameterError({
|
|
24
|
-
para: 'title',
|
|
25
|
-
correct: 'String',
|
|
26
|
-
wrong: title
|
|
27
|
-
})
|
|
28
|
-
})
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (document.title !== title) {
|
|
32
|
-
document.title = title
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return handle.success()
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* 设置页面导航条颜色
|
|
40
|
-
*/
|
|
41
|
-
export const setNavigationBarColor: typeof Taro.setNavigationBarColor = (options) => {
|
|
42
|
-
const { backgroundColor, success, fail, complete } = options
|
|
43
|
-
const handle = new MethodHandler({ name: 'setNavigationBarColor', success, fail, complete })
|
|
44
|
-
const meta = document.createElement('meta')
|
|
45
|
-
meta.setAttribute('name', 'theme-color')
|
|
46
|
-
meta.setAttribute('content', backgroundColor)
|
|
47
|
-
document.head.appendChild(meta)
|
|
48
|
-
return handle.success()
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export const hideNavigationBarLoading = temporarilyNotSupport('hideNavigationBarLoading')
|
|
52
|
-
export const hideHomeButton = temporarilyNotSupport('hideHomeButton')
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import Taro from '@tarojs/api'
|
|
2
|
-
|
|
3
|
-
import { MethodHandler } from '../../utils/handler'
|
|
4
|
-
/**
|
|
5
|
-
* 开始下拉刷新。调用后触发下拉刷新动画,效果与用户手动下拉刷新一致。
|
|
6
|
-
*/
|
|
7
|
-
export const startPullDownRefresh: typeof Taro.startPullDownRefresh = function ({ success, fail, complete } = {}) {
|
|
8
|
-
const handle = new MethodHandler({ name: 'startPullDownRefresh', success, fail, complete })
|
|
9
|
-
return new Promise((resolve, reject) => {
|
|
10
|
-
Taro.eventCenter.trigger('__taroStartPullDownRefresh', {
|
|
11
|
-
successHandler: (res = {}) => handle.success(res, resolve as any),
|
|
12
|
-
errorHandler: (res = {}) => handle.fail(res, reject as any)
|
|
13
|
-
})
|
|
14
|
-
})
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* 停止当前页面下拉刷新。
|
|
19
|
-
*/
|
|
20
|
-
export const stopPullDownRefresh: typeof Taro.stopPullDownRefresh = function ({ success, fail, complete } = {}) {
|
|
21
|
-
const handle = new MethodHandler({ name: 'stopPullDownRefresh', success, fail, complete })
|
|
22
|
-
return new Promise((resolve, reject) => {
|
|
23
|
-
Taro.eventCenter.trigger('__taroStopPullDownRefresh', {
|
|
24
|
-
successHandler: (res = {}) => handle.success(res, resolve as any),
|
|
25
|
-
errorHandler: (res = {}) => handle.fail(res, reject as any)
|
|
26
|
-
})
|
|
27
|
-
})
|
|
28
|
-
}
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import Taro from '@tarojs/api'
|
|
2
|
-
import { Current } from '@tarojs/runtime'
|
|
3
|
-
|
|
4
|
-
import { easeInOut, getTimingFunc } from '../../../utils'
|
|
5
|
-
import { MethodHandler } from '../../../utils/handler'
|
|
6
|
-
|
|
7
|
-
let timer: ReturnType<typeof setTimeout>
|
|
8
|
-
const FRAME_DURATION = 17
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* 将页面滚动到目标位置
|
|
12
|
-
*/
|
|
13
|
-
export const pageScrollTo: typeof Taro.pageScrollTo = ({ scrollTop, selector = '', duration = 300, success, fail, complete }) => {
|
|
14
|
-
let scrollFunc
|
|
15
|
-
const handle = new MethodHandler({ name: 'pageScrollTo', success, fail, complete })
|
|
16
|
-
return new Promise((resolve, reject) => {
|
|
17
|
-
try {
|
|
18
|
-
if (scrollTop === undefined && !selector) {
|
|
19
|
-
return handle.fail({
|
|
20
|
-
errMsg: 'scrollTop" 或 "selector" 需要其之一'
|
|
21
|
-
}, reject)
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const id = Current.page?.path?.replace(/([^a-z0-9\u00a0-\uffff_-])/ig, '\\$1')
|
|
25
|
-
const el: HTMLDivElement | null = (id
|
|
26
|
-
? document.querySelector(`.taro_page#${id}`)
|
|
27
|
-
: document.querySelector('.taro_page') ||
|
|
28
|
-
document.querySelector('.taro_router')) as HTMLDivElement
|
|
29
|
-
|
|
30
|
-
if (!scrollFunc) {
|
|
31
|
-
if (!el) {
|
|
32
|
-
scrollFunc = pos => {
|
|
33
|
-
if (pos === undefined) {
|
|
34
|
-
return window.pageYOffset
|
|
35
|
-
} else {
|
|
36
|
-
window.scrollTo(0, pos)
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
} else {
|
|
40
|
-
scrollFunc = pos => {
|
|
41
|
-
if (pos === undefined) {
|
|
42
|
-
return el.scrollTop
|
|
43
|
-
} else {
|
|
44
|
-
el.scrollTop = pos
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
if (scrollTop && selector) {
|
|
51
|
-
console.warn('"scrollTop" 或 "selector" 建议只设一个值,全部设置会忽略selector')
|
|
52
|
-
}
|
|
53
|
-
const from = scrollFunc()
|
|
54
|
-
let to: number
|
|
55
|
-
if (typeof scrollTop === 'number') {
|
|
56
|
-
to = scrollTop
|
|
57
|
-
} else {
|
|
58
|
-
const el = document.querySelector(selector) as HTMLElement
|
|
59
|
-
to = el?.offsetTop || 0
|
|
60
|
-
}
|
|
61
|
-
const delta = to - from
|
|
62
|
-
|
|
63
|
-
const frameCnt = duration / FRAME_DURATION
|
|
64
|
-
const easeFunc = getTimingFunc(easeInOut, frameCnt)
|
|
65
|
-
|
|
66
|
-
const scroll = (frame = 0) => {
|
|
67
|
-
const dest = from + delta * easeFunc(frame)
|
|
68
|
-
scrollFunc(dest)
|
|
69
|
-
if (frame < frameCnt) {
|
|
70
|
-
timer && clearTimeout(timer)
|
|
71
|
-
timer = setTimeout(() => {
|
|
72
|
-
scroll(frame + 1)
|
|
73
|
-
}, FRAME_DURATION)
|
|
74
|
-
} else {
|
|
75
|
-
return handle.success({}, resolve)
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
scroll()
|
|
79
|
-
} catch (e) {
|
|
80
|
-
return handle.fail({
|
|
81
|
-
errMsg: e.message
|
|
82
|
-
}, reject)
|
|
83
|
-
}
|
|
84
|
-
})
|
|
85
|
-
}
|
package/src/api/ui/sticky.ts
DELETED