@tarojs/taro-h5 3.3.16 → 3.3.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.js +5863 -8163
- package/dist/index.js +9044 -0
- package/dist/taroApis.js +1 -1
- package/package.json +9 -9
- package/src/api/ad/index.ts +5 -0
- package/src/api/ai/facial.ts +6 -0
- package/src/api/ai/index.ts +2 -0
- package/src/api/ai/visual.ts +4 -0
- package/src/api/alipay/index.ts +4 -0
- package/src/api/base/crypto.ts +4 -0
- package/src/api/base/debug.ts +5 -0
- package/src/api/base/index.ts +23 -0
- package/src/api/base/performance.ts +5 -0
- package/src/api/base/system/index.ts +2 -0
- package/src/api/base/system/info.ts +64 -0
- package/src/api/base/system/network.ts +70 -0
- package/src/api/base/update.ts +5 -0
- package/src/api/base/weapp/app-event.ts +19 -0
- package/src/api/base/weapp/life-cycle.ts +5 -0
- package/src/api/canvas/CanvasContext.ts +230 -0
- package/src/api/canvas/canvasGetImageData.ts +29 -0
- package/src/api/canvas/canvasPutImageData.ts +26 -0
- package/src/api/canvas/canvasToTempFilePath.ts +26 -0
- package/src/api/canvas/createCanvasContext.ts +20 -0
- package/src/api/canvas/{index.js → index.ts} +9 -3
- package/src/api/cloud/index.ts +27 -0
- package/src/api/data-analysis/index.ts +6 -0
- package/src/api/device/accelerometer.ts +89 -0
- package/src/api/device/accessibility.ts +4 -0
- package/src/api/device/battery.ts +5 -0
- package/src/api/device/bluetooth-ble.ts +19 -0
- package/src/api/device/bluetooth-peripheral.ts +6 -0
- package/src/api/device/bluetooth.ts +16 -0
- package/src/api/device/calendar.ts +5 -0
- package/src/api/device/clipboard.ts +67 -0
- package/src/api/device/compass.ts +74 -0
- package/src/api/device/contact.ts +5 -0
- package/src/api/device/crypto.ts +4 -0
- package/src/api/device/gyroscope.ts +7 -0
- package/src/api/device/iBeacon.ts +10 -0
- package/src/api/device/index.ts +22 -0
- package/src/api/device/keyboard.ts +7 -0
- package/src/api/device/memory.ts +5 -0
- package/src/api/device/motion.ts +92 -0
- package/src/api/device/nfc.ts +10 -0
- package/src/api/device/phone.ts +30 -0
- package/src/api/device/scan.ts +7 -0
- package/src/api/device/screen.ts +9 -0
- package/src/api/device/vibrate.ts +36 -0
- package/src/api/device/wifi.ts +13 -0
- package/src/api/ext/index.ts +5 -0
- package/src/api/files/index.ts +11 -0
- package/src/api/framework/index.ts +10 -0
- package/src/api/index.ts +25 -0
- package/src/api/location/chooseLocation.ts +106 -0
- package/src/api/location/index.ts +19 -0
- package/src/api/location/style.css +8 -8
- package/src/api/media/audio/index.ts +99 -0
- package/src/api/media/background-audio.ts +12 -0
- package/src/api/media/camera.ts +4 -0
- package/src/api/media/editor.ts +29 -0
- package/src/api/media/image/chooseImage.ts +80 -0
- package/src/api/{image → media/image}/getImageInfo.js +0 -0
- package/src/api/media/image/index.ts +13 -0
- package/src/api/{image → media/image}/previewImage.js +4 -0
- package/src/api/media/index.ts +13 -0
- package/src/api/media/live.ts +5 -0
- package/src/api/media/map.ts +4 -0
- package/src/api/media/media-recorder.ts +4 -0
- package/src/api/media/recorder.ts +6 -0
- package/src/api/media/video/index.ts +82 -0
- package/src/api/media/video-decoder.ts +4 -0
- package/src/api/media/video-processing.ts +4 -0
- package/src/api/media/voip.ts +17 -0
- package/src/api/navigate/index.ts +7 -0
- package/src/api/{fileTransfer/downloadFile.js → network/download.ts} +16 -25
- package/src/api/network/index.ts +7 -0
- package/src/api/network/mdns.ts +13 -0
- package/src/api/{request/index.js → network/request/index.ts} +9 -6
- package/src/api/network/tcp.ts +4 -0
- package/src/api/network/udp.ts +4 -0
- package/src/api/{fileTransfer/uploadFile.js → network/upload.ts} +28 -30
- package/src/api/{fileTransfer/utils.js → network/utils.ts} +0 -0
- package/src/api/{webSocket/index.js → network/websocket/index.ts} +49 -56
- package/src/api/{webSocket/socketTask.js → network/websocket/socketTask.ts} +16 -6
- package/src/api/open-api/account.ts +4 -0
- package/src/api/open-api/address.ts +4 -0
- package/src/api/open-api/authorize.ts +5 -0
- package/src/api/open-api/card.ts +5 -0
- package/src/api/open-api/channels-live.ts +9 -0
- package/src/api/open-api/customer-service.ts +4 -0
- package/src/api/open-api/facial.ts +7 -0
- package/src/api/open-api/favorites.ts +5 -0
- package/src/api/open-api/group.ts +4 -0
- package/src/api/open-api/index.ts +18 -0
- package/src/api/open-api/invoice.ts +5 -0
- package/src/api/open-api/license-plate.ts +4 -0
- package/src/api/open-api/login.ts +6 -0
- package/src/api/open-api/red-package.ts +4 -0
- package/src/api/open-api/settings.ts +5 -0
- package/src/api/open-api/soter.ts +6 -0
- package/src/api/open-api/subscribe-message.ts +4 -0
- package/src/api/open-api/user-info.ts +5 -0
- package/src/api/open-api/werun.ts +5 -0
- package/src/api/payment/index.ts +5 -0
- package/src/api/route/index.ts +10 -0
- package/src/api/share/index.ts +13 -0
- package/src/api/storage/background-fetch.ts +7 -0
- package/src/api/storage/index.ts +193 -0
- package/src/api/swan/index.ts +31 -0
- package/src/{taro/index.js → api/taro.ts} +133 -149
- package/src/api/{createAnimation/index.js → ui/animation/index.ts} +26 -14
- package/src/api/ui/background.ts +5 -0
- package/src/api/ui/custom-component.ts +4 -0
- package/src/api/ui/fonts.ts +4 -0
- package/src/api/ui/index.ts +12 -0
- package/src/api/ui/interaction/actionSheet.ts +212 -0
- package/src/api/{interactive/index.js → ui/interaction/index.ts} +102 -90
- package/src/api/ui/interaction/modal.ts +237 -0
- package/src/api/{interactive/toast.js → ui/interaction/toast.ts} +35 -33
- package/src/api/ui/menu.ts +4 -0
- package/src/api/ui/navigation-bar/index.ts +52 -0
- package/src/api/ui/pull-down-refresh.ts +32 -0
- package/src/api/{scroll/index.js → ui/scroll/index.ts} +16 -28
- package/src/api/ui/sticky.ts +4 -0
- package/src/api/ui/tab-bar.ts +326 -0
- package/src/api/ui/window.ts +37 -0
- package/src/api/utils/handler.ts +105 -0
- package/src/api/utils/{index.js → index.ts} +23 -86
- package/src/api/worker/index.ts +4 -0
- package/src/api/wxml/index.ts +9 -0
- package/src/api/{createSelectorQuery/index.js → wxml/selectorQuery.ts} +86 -59
- package/src/index.ts +6 -0
- package/src/types/api.d.ts +4 -0
- package/src/types/define.d.ts +2 -0
- package/{types → src/types}/index.d.ts +0 -0
- package/{types → src/types}/type.ts +1 -1
- package/src/api/accelerometer/index.js +0 -105
- package/src/api/audio/index.js +0 -137
- package/src/api/canvas/canvasGetImageData.js +0 -44
- package/src/api/canvas/canvasPutImageData.js +0 -45
- package/src/api/canvas/canvasToTempFilePath.js +0 -49
- package/src/api/canvas/createCanvasContext.js +0 -340
- package/src/api/clipboard/index.js +0 -113
- package/src/api/compass/index.js +0 -99
- package/src/api/deviceMotion/index.js +0 -105
- package/src/api/fileTransfer/index.js +0 -2
- package/src/api/image/chooseImage.js +0 -87
- package/src/api/image/index.js +0 -7
- package/src/api/index.js +0 -29
- package/src/api/interactive/actionSheet.js +0 -214
- package/src/api/interactive/modal.js +0 -256
- package/src/api/location/chooseLocation.js +0 -143
- package/src/api/location/index.js +0 -5
- package/src/api/navigationBar/index.js +0 -57
- package/src/api/open/index.js +0 -5
- package/src/api/others/index.js +0 -43
- package/src/api/pullDownRefresh/index.js +0 -51
- package/src/api/storage/index.js +0 -211
- package/src/api/system/index.js +0 -9
- package/src/api/system/info.js +0 -36
- package/src/api/system/network.js +0 -68
- package/src/api/tabBar/index.js +0 -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/window/index.js +0 -38
- package/src/index.cjs.js +0 -11
- package/src/index.js +0 -6
|
@@ -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
|
+
}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { inlineStyle } from '
|
|
2
|
-
|
|
3
|
-
const noop = function () {}
|
|
1
|
+
import { inlineStyle } from '../../utils'
|
|
4
2
|
|
|
5
3
|
export default class Toast {
|
|
6
4
|
options = {
|
|
@@ -8,10 +6,7 @@ export default class Toast {
|
|
|
8
6
|
icon: 'none',
|
|
9
7
|
image: '',
|
|
10
8
|
duration: 1500,
|
|
11
|
-
mask: false
|
|
12
|
-
success: noop,
|
|
13
|
-
fail: noop,
|
|
14
|
-
complete: noop
|
|
9
|
+
mask: false
|
|
15
10
|
}
|
|
16
11
|
|
|
17
12
|
style = {
|
|
@@ -45,13 +40,18 @@ export default class Toast {
|
|
|
45
40
|
background: 'rgba(17, 17, 17, 0.7)'
|
|
46
41
|
},
|
|
47
42
|
successStyle: {
|
|
48
|
-
margin: '
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
'
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
55
|
},
|
|
56
56
|
loadingStyle: {
|
|
57
57
|
margin: '6px auto',
|
|
@@ -75,14 +75,24 @@ export default class Toast {
|
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
|
|
78
|
+
el: HTMLDivElement
|
|
79
|
+
mask: HTMLDivElement
|
|
80
|
+
icon: HTMLParagraphElement
|
|
81
|
+
toast: HTMLDivElement
|
|
82
|
+
title: HTMLParagraphElement
|
|
83
|
+
type: any
|
|
84
|
+
hideOpacityTimer: any
|
|
85
|
+
hideDisplayTimer: any
|
|
86
|
+
|
|
87
|
+
create (options = {}, _type: 'loading' | 'toast' = 'toast') {
|
|
79
88
|
// style
|
|
80
|
-
const { maskStyle, toastStyle, successStyle, loadingStyle, imageStyle, textStyle } = this.style
|
|
89
|
+
const { maskStyle, toastStyle, successStyle, errrorStyle, loadingStyle, imageStyle, textStyle } = this.style
|
|
81
90
|
|
|
82
91
|
// configuration
|
|
83
92
|
const config = {
|
|
84
93
|
...this.options,
|
|
85
|
-
...options
|
|
94
|
+
...options,
|
|
95
|
+
_type
|
|
86
96
|
}
|
|
87
97
|
|
|
88
98
|
// wrapper
|
|
@@ -104,12 +114,11 @@ export default class Toast {
|
|
|
104
114
|
'background-image': `url(${config.image})`
|
|
105
115
|
}))
|
|
106
116
|
} else {
|
|
107
|
-
const iconStyle = config.icon === 'loading' ? loadingStyle : successStyle
|
|
117
|
+
const iconStyle = config.icon === 'loading' ? loadingStyle : config.icon === 'error' ? errrorStyle : successStyle
|
|
108
118
|
this.icon.setAttribute('style', inlineStyle({
|
|
109
119
|
...iconStyle,
|
|
110
120
|
...(config.icon === 'none' ? { display: 'none' } : {})
|
|
111
121
|
}))
|
|
112
|
-
if (config.icon !== 'loading') this.icon.textContent = ''
|
|
113
122
|
}
|
|
114
123
|
|
|
115
124
|
// toast
|
|
@@ -141,16 +150,14 @@ export default class Toast {
|
|
|
141
150
|
// disappear after duration
|
|
142
151
|
config.duration >= 0 && this.hide(config.duration, this.type)
|
|
143
152
|
|
|
144
|
-
|
|
145
|
-
config.success && config.success({ errMsg })
|
|
146
|
-
config.complete && config.complete({ errMsg })
|
|
147
|
-
return Promise.resolve({ errMsg })
|
|
153
|
+
return ''
|
|
148
154
|
}
|
|
149
155
|
|
|
150
|
-
show (options = {}) {
|
|
156
|
+
show (options = {}, _type: 'loading' | 'toast' = 'toast') {
|
|
151
157
|
const config = {
|
|
152
158
|
...this.options,
|
|
153
|
-
...options
|
|
159
|
+
...options,
|
|
160
|
+
_type
|
|
154
161
|
}
|
|
155
162
|
|
|
156
163
|
if (this.hideOpacityTimer) clearTimeout(this.hideOpacityTimer)
|
|
@@ -163,21 +170,19 @@ export default class Toast {
|
|
|
163
170
|
this.mask.style.display = config.mask ? 'block' : 'none'
|
|
164
171
|
|
|
165
172
|
// image
|
|
166
|
-
const { toastStyle, successStyle, loadingStyle, imageStyle } = this.style
|
|
173
|
+
const { toastStyle, successStyle, errrorStyle, loadingStyle, imageStyle } = this.style
|
|
167
174
|
if (config.image) {
|
|
168
175
|
this.icon.setAttribute('style', inlineStyle({
|
|
169
176
|
...imageStyle,
|
|
170
177
|
'background-image': `url(${config.image})`
|
|
171
178
|
}))
|
|
172
|
-
this.icon.textContent = ''
|
|
173
179
|
} else {
|
|
174
180
|
if (!config.image && config.icon) {
|
|
175
|
-
const iconStyle = config.icon === 'loading' ? loadingStyle : successStyle
|
|
181
|
+
const iconStyle = config.icon === 'loading' ? loadingStyle : config.icon === 'error' ? errrorStyle : successStyle
|
|
176
182
|
this.icon.setAttribute('style', inlineStyle({
|
|
177
183
|
...iconStyle,
|
|
178
184
|
...(config.icon === 'none' ? { display: 'none' } : {})
|
|
179
185
|
}))
|
|
180
|
-
this.icon.textContent = config.icon === 'loading' ? '' : ''
|
|
181
186
|
}
|
|
182
187
|
}
|
|
183
188
|
|
|
@@ -198,10 +203,7 @@ export default class Toast {
|
|
|
198
203
|
// disappear after duration
|
|
199
204
|
config.duration >= 0 && this.hide(config.duration, this.type)
|
|
200
205
|
|
|
201
|
-
|
|
202
|
-
config.success && config.success({ errMsg })
|
|
203
|
-
config.complete && config.complete({ errMsg })
|
|
204
|
-
return Promise.resolve({ errMsg })
|
|
206
|
+
return ''
|
|
205
207
|
}
|
|
206
208
|
|
|
207
209
|
hide (duration = 0, type) {
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import Taro from '@tarojs/taro'
|
|
2
|
+
|
|
3
|
+
import { MethodHandler } from '../../utils/handler'
|
|
4
|
+
import { getParameterError, shouldBeObject, temporarilyNotSupport } from '../../utils'
|
|
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: 'makePhoneCall', 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')
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import Taro from '@tarojs/api'
|
|
2
|
+
import { MethodHandler } from '../utils/handler'
|
|
3
|
+
/**
|
|
4
|
+
* 开始下拉刷新。调用后触发下拉刷新动画,效果与用户手动下拉刷新一致。
|
|
5
|
+
*/
|
|
6
|
+
const startPullDownRefresh: typeof Taro.startPullDownRefresh = function ({ success, fail, complete } = {}) {
|
|
7
|
+
const handle = new MethodHandler({ name: 'startPullDownRefresh', success, fail, complete })
|
|
8
|
+
return new Promise((resolve, reject) => {
|
|
9
|
+
Taro.eventCenter.trigger('__taroStartPullDownRefresh', {
|
|
10
|
+
successHandler: (res = {}) => handle.success(res, resolve as any),
|
|
11
|
+
errorHandler: (res = {}) => handle.fail(res, reject as any)
|
|
12
|
+
})
|
|
13
|
+
})
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* 停止当前页面下拉刷新。
|
|
18
|
+
*/
|
|
19
|
+
const stopPullDownRefresh: typeof Taro.stopPullDownRefresh = function ({ success, fail, complete } = {}) {
|
|
20
|
+
const handle = new MethodHandler({ name: 'stopPullDownRefresh', success, fail, complete })
|
|
21
|
+
return new Promise((resolve, reject) => {
|
|
22
|
+
Taro.eventCenter.trigger('__taroStopPullDownRefresh', {
|
|
23
|
+
successHandler: (res = {}) => handle.success(res, resolve as any),
|
|
24
|
+
errorHandler: (res = {}) => handle.fail(res, reject as any)
|
|
25
|
+
})
|
|
26
|
+
})
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export {
|
|
30
|
+
startPullDownRefresh,
|
|
31
|
+
stopPullDownRefresh
|
|
32
|
+
}
|
|
@@ -1,28 +1,23 @@
|
|
|
1
|
-
import
|
|
1
|
+
import Taro from '@tarojs/api'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
* @property {number} scrollTop 滚动到页面的目标位置,单位 px
|
|
6
|
-
* @property {string} selector 选择器, css selector
|
|
7
|
-
* @property {number} [duration=300] 滚动动画的时长,单位 ms
|
|
8
|
-
* @property {function} [success] 接口调用成功的回调函数
|
|
9
|
-
* @property {function} [fail] 接口调用失败的回调函数
|
|
10
|
-
* @property {function} [complete] 接口调用结束的回调函数(调用成功、失败都会执行)
|
|
11
|
-
*/
|
|
3
|
+
import { MethodHandler } from '../../utils/handler'
|
|
4
|
+
import { getTimingFunc, easeInOut } from '../../utils'
|
|
12
5
|
|
|
13
6
|
let scrollFunc
|
|
14
|
-
let timer
|
|
7
|
+
let timer: NodeJS.Timeout
|
|
15
8
|
const FRAME_DURATION = 17
|
|
16
9
|
|
|
17
10
|
/**
|
|
18
11
|
* 将页面滚动到目标位置
|
|
19
|
-
* @param {PageScrollToParam} object 参数
|
|
20
12
|
*/
|
|
21
|
-
export const pageScrollTo = ({ scrollTop, selector, duration = 300, success, fail, complete }) => {
|
|
13
|
+
export const pageScrollTo: typeof Taro.pageScrollTo = ({ scrollTop, selector = '', duration = 300, success, fail, complete }) => {
|
|
14
|
+
const handle = new MethodHandler({ name: 'pageScrollTo', success, fail, complete })
|
|
22
15
|
return new Promise((resolve, reject) => {
|
|
23
16
|
try {
|
|
24
17
|
if (scrollTop === undefined && !selector) {
|
|
25
|
-
|
|
18
|
+
return handle.fail({
|
|
19
|
+
errMsg: 'scrollTop" 或 "selector" 需要其之一'
|
|
20
|
+
}, reject)
|
|
26
21
|
}
|
|
27
22
|
|
|
28
23
|
let el
|
|
@@ -58,11 +53,12 @@ export const pageScrollTo = ({ scrollTop, selector, duration = 300, success, fai
|
|
|
58
53
|
console.warn('"scrollTop" 或 "selector" 建议只设一个值,全部设置会忽略selector')
|
|
59
54
|
}
|
|
60
55
|
const from = scrollFunc()
|
|
61
|
-
let to
|
|
56
|
+
let to: number
|
|
62
57
|
if (typeof scrollTop === 'number') {
|
|
63
58
|
to = scrollTop
|
|
64
59
|
} else {
|
|
65
|
-
|
|
60
|
+
const el = document.querySelector(selector) as HTMLElement
|
|
61
|
+
to = el?.offsetTop || 0
|
|
66
62
|
}
|
|
67
63
|
const delta = to - from
|
|
68
64
|
|
|
@@ -78,22 +74,14 @@ export const pageScrollTo = ({ scrollTop, selector, duration = 300, success, fai
|
|
|
78
74
|
scroll(frame + 1)
|
|
79
75
|
}, FRAME_DURATION)
|
|
80
76
|
} else {
|
|
81
|
-
|
|
82
|
-
errMsg: 'pageScrollTo:ok'
|
|
83
|
-
}
|
|
84
|
-
success && success(res)
|
|
85
|
-
complete && complete()
|
|
86
|
-
resolve(res)
|
|
77
|
+
return handle.success({}, resolve)
|
|
87
78
|
}
|
|
88
79
|
}
|
|
89
80
|
scroll()
|
|
90
81
|
} catch (e) {
|
|
91
|
-
|
|
92
|
-
errMsg:
|
|
93
|
-
}
|
|
94
|
-
fail && fail(res)
|
|
95
|
-
complete && complete()
|
|
96
|
-
reject(res)
|
|
82
|
+
return handle.fail({
|
|
83
|
+
errMsg: e.message
|
|
84
|
+
}, reject)
|
|
97
85
|
}
|
|
98
86
|
})
|
|
99
87
|
}
|