@tarojs/taro-h5 3.4.0-beta.0 → 3.4.0-beta.1
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 +7971 -9468
- package/dist/index.js +10767 -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 +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 +101 -0
- package/src/api/media/index.ts +13 -0
- package/src/api/media/live.ts +5 -0
- package/src/api/media/map.ts +4 -0
- package/src/api/media/media-recorder.ts +4 -0
- package/src/api/media/recorder.ts +6 -0
- package/src/api/media/video/index.ts +82 -0
- package/src/api/media/video-decoder.ts +4 -0
- package/src/api/media/video-processing.ts +4 -0
- package/src/api/media/voip.ts +17 -0
- package/src/api/navigate/index.ts +7 -0
- package/src/api/{fileTransfer/downloadFile.js → network/download.ts} +16 -27
- package/src/api/network/index.ts +7 -0
- package/src/api/network/mdns.ts +13 -0
- package/src/api/{request/index.js → network/request/index.ts} +9 -6
- package/src/api/network/tcp.ts +4 -0
- package/src/api/network/udp.ts +4 -0
- package/src/api/{fileTransfer/uploadFile.js → network/upload.ts} +28 -32
- package/src/api/{fileTransfer/utils.js → network/utils.ts} +0 -0
- package/src/api/network/websocket/index.ts +88 -0
- package/src/api/{webSocket/socketTask.js → network/websocket/socketTask.ts} +17 -7
- package/src/api/open-api/account.ts +4 -0
- package/src/api/open-api/address.ts +4 -0
- package/src/api/open-api/authorize.ts +5 -0
- package/src/api/open-api/card.ts +5 -0
- package/src/api/open-api/channels-live.ts +9 -0
- package/src/api/open-api/customer-service.ts +4 -0
- package/src/api/open-api/facial.ts +7 -0
- package/src/api/open-api/favorites.ts +5 -0
- package/src/api/open-api/group.ts +4 -0
- package/src/api/open-api/index.ts +18 -0
- package/src/api/open-api/invoice.ts +5 -0
- package/src/api/open-api/license-plate.ts +4 -0
- package/src/api/open-api/login.ts +6 -0
- package/src/api/open-api/red-package.ts +4 -0
- package/src/api/open-api/settings.ts +5 -0
- package/src/api/open-api/soter.ts +6 -0
- package/src/api/open-api/subscribe-message.ts +4 -0
- package/src/api/open-api/user-info.ts +5 -0
- package/src/api/open-api/werun.ts +5 -0
- package/src/api/payment/index.ts +5 -0
- package/src/api/route/index.ts +10 -0
- package/src/api/share/index.ts +13 -0
- package/src/api/storage/background-fetch.ts +7 -0
- package/src/api/storage/index.ts +181 -0
- package/src/api/swan/index.ts +31 -0
- package/src/{taro/index.js → api/taro.ts} +89 -104
- package/src/api/{createAnimation/index.js → ui/animation/index.ts} +51 -35
- 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 +49 -0
- package/src/api/{createSelectorQuery/index.js → wxml/selectorQuery.ts} +75 -94
- 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/deviceMotion/index.js +0 -105
- package/src/api/fileTransfer/index.js +0 -2
- package/src/api/image/chooseImage.js +0 -87
- package/src/api/image/getImageInfo.js +0 -74
- package/src/api/image/index.js +0 -7
- package/src/api/image/previewImage.js +0 -94
- package/src/api/index.js +0 -29
- package/src/api/interactive/actionSheet.js +0 -214
- package/src/api/interactive/modal.js +0 -256
- package/src/api/location/chooseLocation.js +0 -143
- package/src/api/location/index.js +0 -5
- package/src/api/navigationBar/index.js +0 -57
- package/src/api/open/index.js +0 -5
- package/src/api/others/index.js +0 -43
- package/src/api/pullDownRefresh/index.js +0 -51
- package/src/api/scroll/index.js +0 -99
- package/src/api/storage/index.js +0 -211
- package/src/api/system/index.js +0 -9
- package/src/api/system/info.js +0 -36
- package/src/api/system/network.js +0 -68
- package/src/api/tabBar/index.js +0 -402
- package/src/api/unsupportedApi/index.js +0 -278
- package/src/api/vibrate/index.js +0 -49
- package/src/api/video/index.js +0 -87
- package/src/api/webSocket/index.js +0 -103
- package/src/api/window/index.js +0 -38
- package/src/index.cjs.js +0 -11
- package/src/index.js +0 -6
|
@@ -1,256 +0,0 @@
|
|
|
1
|
-
import { inlineStyle } from '../utils'
|
|
2
|
-
|
|
3
|
-
const noop = function () {}
|
|
4
|
-
|
|
5
|
-
export default class Modal {
|
|
6
|
-
options = {
|
|
7
|
-
title: '',
|
|
8
|
-
content: '',
|
|
9
|
-
showCancel: true,
|
|
10
|
-
cancelText: '取消',
|
|
11
|
-
cancelColor: '#000000',
|
|
12
|
-
confirmText: '确定',
|
|
13
|
-
confirmColor: '#3CC51F',
|
|
14
|
-
success: noop,
|
|
15
|
-
fail: noop,
|
|
16
|
-
complete: noop
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
style = {
|
|
20
|
-
maskStyle: {
|
|
21
|
-
position: 'fixed',
|
|
22
|
-
'z-index': '1000',
|
|
23
|
-
top: '0',
|
|
24
|
-
right: '0',
|
|
25
|
-
left: '0',
|
|
26
|
-
bottom: '0',
|
|
27
|
-
background: 'rgba(0,0,0,0.6)'
|
|
28
|
-
},
|
|
29
|
-
modalStyle: {
|
|
30
|
-
'z-index': '4999',
|
|
31
|
-
position: 'fixed',
|
|
32
|
-
top: '50%',
|
|
33
|
-
left: '50%',
|
|
34
|
-
transform: 'translate(-50%, -50%)',
|
|
35
|
-
width: '80%',
|
|
36
|
-
'max-width': '300px',
|
|
37
|
-
'border-radius': '3px',
|
|
38
|
-
'text-align': 'center',
|
|
39
|
-
'line-height': '1.6',
|
|
40
|
-
overflow: 'hidden',
|
|
41
|
-
background: '#FFFFFF'
|
|
42
|
-
},
|
|
43
|
-
titleStyle: {
|
|
44
|
-
padding: '20px 24px 9px',
|
|
45
|
-
'font-size': '18px'
|
|
46
|
-
},
|
|
47
|
-
textStyle: {
|
|
48
|
-
padding: '0 24px 12px',
|
|
49
|
-
'min-height': '40px',
|
|
50
|
-
'font-size': '15px',
|
|
51
|
-
'line-height': '1.3',
|
|
52
|
-
color: '#808080'
|
|
53
|
-
},
|
|
54
|
-
footStyle: {
|
|
55
|
-
position: 'relative',
|
|
56
|
-
'line-height': '48px',
|
|
57
|
-
'font-size': '18px',
|
|
58
|
-
display: 'flex'
|
|
59
|
-
},
|
|
60
|
-
btnStyle: {
|
|
61
|
-
position: 'relative',
|
|
62
|
-
'-webkit-box-flex': '1',
|
|
63
|
-
'-webkit-flex': '1',
|
|
64
|
-
flex: '1'
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
create (options = {}) {
|
|
69
|
-
// style
|
|
70
|
-
const { maskStyle, modalStyle, titleStyle, textStyle, footStyle, btnStyle } = this.style
|
|
71
|
-
|
|
72
|
-
// configuration
|
|
73
|
-
const config = {
|
|
74
|
-
...this.options,
|
|
75
|
-
...options
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// wrapper
|
|
79
|
-
this.el = document.createElement('div')
|
|
80
|
-
this.el.className = 'taro__modal'
|
|
81
|
-
this.el.style.opacity = '0'
|
|
82
|
-
this.el.style.transition = 'opacity 0.2s linear'
|
|
83
|
-
|
|
84
|
-
// mask
|
|
85
|
-
const mask = document.createElement('div')
|
|
86
|
-
mask.className = 'taro-modal__mask'
|
|
87
|
-
mask.setAttribute('style', inlineStyle(maskStyle))
|
|
88
|
-
|
|
89
|
-
// modal
|
|
90
|
-
const modal = document.createElement('div')
|
|
91
|
-
modal.className = 'taro-modal__content'
|
|
92
|
-
modal.setAttribute('style', inlineStyle(modalStyle))
|
|
93
|
-
|
|
94
|
-
// title
|
|
95
|
-
const titleCSS = config.title ? titleStyle : {
|
|
96
|
-
...titleStyle,
|
|
97
|
-
display: 'none'
|
|
98
|
-
}
|
|
99
|
-
this.title = document.createElement('div')
|
|
100
|
-
|
|
101
|
-
this.title.className = 'taro-modal__title'
|
|
102
|
-
this.title.setAttribute('style', inlineStyle(titleCSS))
|
|
103
|
-
this.title.textContent = config.title
|
|
104
|
-
|
|
105
|
-
// text
|
|
106
|
-
const textCSS = config.title ? textStyle : {
|
|
107
|
-
...textStyle,
|
|
108
|
-
padding: '40px 20px 26px',
|
|
109
|
-
color: '#353535'
|
|
110
|
-
}
|
|
111
|
-
this.text = document.createElement('div')
|
|
112
|
-
this.text.className = 'taro-modal__text'
|
|
113
|
-
this.text.setAttribute('style', inlineStyle(textCSS))
|
|
114
|
-
this.text.textContent = config.content
|
|
115
|
-
|
|
116
|
-
// foot
|
|
117
|
-
const foot = document.createElement('div')
|
|
118
|
-
foot.className = 'taro-modal__foot'
|
|
119
|
-
foot.setAttribute('style', inlineStyle(footStyle))
|
|
120
|
-
|
|
121
|
-
// cancel button
|
|
122
|
-
const cancelCSS = {
|
|
123
|
-
...btnStyle,
|
|
124
|
-
color: config.cancelColor,
|
|
125
|
-
display: config.showCancel ? 'block' : 'none'
|
|
126
|
-
}
|
|
127
|
-
this.cancel = document.createElement('div')
|
|
128
|
-
this.cancel.className = 'taro-model__btn taro-model__cancel'
|
|
129
|
-
this.cancel.setAttribute('style', inlineStyle(cancelCSS))
|
|
130
|
-
this.cancel.textContent = config.cancelText
|
|
131
|
-
this.cancel.onclick = () => {
|
|
132
|
-
this.hide()
|
|
133
|
-
const res = this.getRes('cancel')
|
|
134
|
-
config.success(res)
|
|
135
|
-
config.complete(res)
|
|
136
|
-
this.resolveHandler(res)
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
// confirm button
|
|
140
|
-
this.confirm = document.createElement('div')
|
|
141
|
-
this.confirm.className = 'taro-model__btn taro-model__confirm'
|
|
142
|
-
this.confirm.setAttribute('style', inlineStyle(btnStyle))
|
|
143
|
-
this.confirm.style.color = config.confirmColor
|
|
144
|
-
this.confirm.textContent = config.confirmText
|
|
145
|
-
this.confirm.onclick = () => {
|
|
146
|
-
this.hide()
|
|
147
|
-
const res = this.getRes('confirm')
|
|
148
|
-
config.success(res)
|
|
149
|
-
config.complete(res)
|
|
150
|
-
this.resolveHandler(res)
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// result
|
|
154
|
-
foot.appendChild(this.cancel)
|
|
155
|
-
foot.appendChild(this.confirm)
|
|
156
|
-
modal.appendChild(this.title)
|
|
157
|
-
modal.appendChild(this.text)
|
|
158
|
-
modal.appendChild(foot)
|
|
159
|
-
this.el.appendChild(mask)
|
|
160
|
-
this.el.appendChild(modal)
|
|
161
|
-
|
|
162
|
-
// show immediately
|
|
163
|
-
document.body.appendChild(this.el)
|
|
164
|
-
setTimeout(() => { this.el.style.opacity = '1' }, 0)
|
|
165
|
-
|
|
166
|
-
return new Promise(resolve => (this.resolveHandler = resolve))
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
getRes (type) {
|
|
170
|
-
const res = {
|
|
171
|
-
errMsg: 'showModal:ok',
|
|
172
|
-
cancel: false,
|
|
173
|
-
confirm: false
|
|
174
|
-
}
|
|
175
|
-
res[type] = true
|
|
176
|
-
return res
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
show (options = {}) {
|
|
180
|
-
const config = {
|
|
181
|
-
...this.options,
|
|
182
|
-
...options
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
if (this.hideOpacityTimer) clearTimeout(this.hideOpacityTimer)
|
|
186
|
-
if (this.hideDisplayTimer) clearTimeout(this.hideDisplayTimer)
|
|
187
|
-
|
|
188
|
-
// title & text
|
|
189
|
-
const { textStyle } = this.style
|
|
190
|
-
|
|
191
|
-
if (config.title) {
|
|
192
|
-
this.title.textContent = config.title
|
|
193
|
-
// none => block
|
|
194
|
-
this.title.style.display = 'block'
|
|
195
|
-
this.text.setAttribute('style', inlineStyle(textStyle))
|
|
196
|
-
} else {
|
|
197
|
-
// block => none
|
|
198
|
-
this.title.style.display = 'none'
|
|
199
|
-
const textCSS = {
|
|
200
|
-
...textStyle,
|
|
201
|
-
padding: '40px 20px 26px',
|
|
202
|
-
color: '#353535'
|
|
203
|
-
}
|
|
204
|
-
this.text.setAttribute('style', inlineStyle(textCSS))
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
this.text.textContent = config.content || ''
|
|
208
|
-
|
|
209
|
-
// showCancel
|
|
210
|
-
this.cancel.style.display = config.showCancel ? 'block' : 'none'
|
|
211
|
-
|
|
212
|
-
// cancelText
|
|
213
|
-
this.cancel.textContent = config.cancelText || ''
|
|
214
|
-
|
|
215
|
-
// cancelColor
|
|
216
|
-
this.cancel.style.color = config.cancelColor || undefined
|
|
217
|
-
|
|
218
|
-
// confirmText
|
|
219
|
-
this.confirm.textContent = config.confirmText || ''
|
|
220
|
-
|
|
221
|
-
// confirmColor
|
|
222
|
-
this.confirm.style.color = config.confirmColor || undefined
|
|
223
|
-
|
|
224
|
-
// cbs
|
|
225
|
-
this.cancel.onclick = () => {
|
|
226
|
-
this.hide()
|
|
227
|
-
const res = this.getRes('cancel')
|
|
228
|
-
config.success(res)
|
|
229
|
-
config.complete(res)
|
|
230
|
-
this.resolveHandler(res)
|
|
231
|
-
}
|
|
232
|
-
this.confirm.onclick = () => {
|
|
233
|
-
this.hide()
|
|
234
|
-
const res = this.getRes('confirm')
|
|
235
|
-
config.success(res)
|
|
236
|
-
config.complete(res)
|
|
237
|
-
this.resolveHandler(res)
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
// show
|
|
241
|
-
this.el.style.display = 'block'
|
|
242
|
-
setTimeout(() => { this.el.style.opacity = '1' }, 0)
|
|
243
|
-
|
|
244
|
-
return new Promise(resolve => (this.resolveHandler = resolve))
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
hide () {
|
|
248
|
-
if (this.hideOpacityTimer) clearTimeout(this.hideOpacityTimer)
|
|
249
|
-
if (this.hideDisplayTimer) clearTimeout(this.hideDisplayTimer)
|
|
250
|
-
|
|
251
|
-
this.hideOpacityTimer = setTimeout(() => {
|
|
252
|
-
this.el.style.opacity = '0'
|
|
253
|
-
this.hideDisplayTimer = setTimeout(() => { this.el.style.display = 'none' }, 200)
|
|
254
|
-
}, 0)
|
|
255
|
-
}
|
|
256
|
-
}
|
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
import './style.css'
|
|
2
|
-
|
|
3
|
-
function createLocaltionChooser (handler) {
|
|
4
|
-
const html = `
|
|
5
|
-
<div class='taro_chooselocation'>
|
|
6
|
-
<div class='taro_chooselocation_bar'>
|
|
7
|
-
<div class='taro_chooselocation_back'></div>
|
|
8
|
-
<p class='taro_chooselocation_title'>位置</p>
|
|
9
|
-
<button class='taro_chooselocation_submit'>完成</button>
|
|
10
|
-
</div>
|
|
11
|
-
<iframe class='taro_chooselocation_frame' frameborder='0' src='https://apis.map.qq.com/tools/locpicker?search=1&type=1&key=${LOCATION_APIKEY}&referer=myapp'></iframe>
|
|
12
|
-
</div>
|
|
13
|
-
`
|
|
14
|
-
const container = document.createElement('div')
|
|
15
|
-
container.innerHTML = html
|
|
16
|
-
const main = container.querySelector('.taro_chooselocation')
|
|
17
|
-
|
|
18
|
-
function show () {
|
|
19
|
-
setTimeout(() => {
|
|
20
|
-
main.style.top = '0'
|
|
21
|
-
})
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function hide () {
|
|
25
|
-
main.style.top = '100%'
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function back () {
|
|
29
|
-
handler({ errMsg: 'chooseLOcation:fail cancel' })
|
|
30
|
-
hide()
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function submit () {
|
|
34
|
-
handler()
|
|
35
|
-
hide()
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function remove () {
|
|
39
|
-
container.remove()
|
|
40
|
-
window.removeEventListener('popstate', back)
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
container.querySelector('.taro_chooselocation_back').addEventListener('click', back)
|
|
44
|
-
container.querySelector('.taro_chooselocation_submit').addEventListener('click', submit)
|
|
45
|
-
|
|
46
|
-
window.addEventListener('popstate', back)
|
|
47
|
-
|
|
48
|
-
return {
|
|
49
|
-
show,
|
|
50
|
-
remove,
|
|
51
|
-
container
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* @typedef {Object} OriginalLocationObject
|
|
57
|
-
* @property {string} module
|
|
58
|
-
* @property {{ lat: number, lng: number }} latlng
|
|
59
|
-
* @property {string} poiaddress
|
|
60
|
-
* @property {string} poiname
|
|
61
|
-
* @property {string} cityname
|
|
62
|
-
*/
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* @typedef {Object} LocationObject
|
|
66
|
-
* @property {string} errMsg 信息
|
|
67
|
-
* @property {string} name 位置名称
|
|
68
|
-
* @property {string} address 详细地址
|
|
69
|
-
* @property {string} latitude 纬度,浮点数,范围为-90~90,负数表示南纬。使用 gcj02 国测局坐标系
|
|
70
|
-
* @property {string} longitude 经度,浮点数,范围为-180~180,负数表示西经。使用 gcj02 国测局坐标系
|
|
71
|
-
*/
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* 打开地图选择位置。
|
|
75
|
-
* @param {Object} object 参数
|
|
76
|
-
* @param {(obj: LocationObject) => void} [object.success] 接口调用成功的回调函数
|
|
77
|
-
* @param {Function} [object.fail] 接口调用失败的回调函数
|
|
78
|
-
* @param {Function} [object.complete] 接口调用结束的回调函数(调用成功、失败都会执行)
|
|
79
|
-
*/
|
|
80
|
-
const chooseLocation = ({ success, fail, complete } = {}) => {
|
|
81
|
-
return new Promise((resolve, reject) => {
|
|
82
|
-
const choosenLocation = {}
|
|
83
|
-
const onSuccess = res => {
|
|
84
|
-
success && success(res)
|
|
85
|
-
complete && complete(res)
|
|
86
|
-
resolve(res)
|
|
87
|
-
}
|
|
88
|
-
const onError = res => {
|
|
89
|
-
fail && fail(res)
|
|
90
|
-
complete && complete(res)
|
|
91
|
-
reject(res)
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// eslint-disable-next-line
|
|
95
|
-
if (!LOCATION_APIKEY) {
|
|
96
|
-
const errMsg = 'chooseLocation:fail LOCATION_APIKEY needed'
|
|
97
|
-
console.warn('chooseLocation api 依赖腾讯地图定位api,需要在defineConstants中配置LOCATION_APIKEY')
|
|
98
|
-
return onError({ errMsg })
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
const onMessage = event => {
|
|
102
|
-
// 接收位置信息,用户选择确认位置点后选点组件会触发该事件,回传用户的位置信息
|
|
103
|
-
/** @type {OriginalLocationObject} */
|
|
104
|
-
const loc = event.data
|
|
105
|
-
|
|
106
|
-
// 防止其他应用也会向该页面post信息,需判断module是否为'locationPicker'
|
|
107
|
-
if (!loc || loc.module !== 'locationPicker') return
|
|
108
|
-
|
|
109
|
-
choosenLocation.name = loc.poiname
|
|
110
|
-
choosenLocation.address = loc.poiaddress
|
|
111
|
-
choosenLocation.latitude = loc.latlng.lat
|
|
112
|
-
choosenLocation.longitude = loc.latlng.lng
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
const chooser = createLocaltionChooser(res => {
|
|
116
|
-
if (res) {
|
|
117
|
-
onError(res)
|
|
118
|
-
} else {
|
|
119
|
-
if (choosenLocation.latitude && choosenLocation.longitude) {
|
|
120
|
-
onSuccess({
|
|
121
|
-
errMsg: 'chooseLocation:ok',
|
|
122
|
-
...choosenLocation
|
|
123
|
-
})
|
|
124
|
-
} else {
|
|
125
|
-
onError({
|
|
126
|
-
errMsg: 'chooseLocation:fail'
|
|
127
|
-
})
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
window.removeEventListener('message', onMessage, false)
|
|
131
|
-
setTimeout(() => {
|
|
132
|
-
chooser.remove()
|
|
133
|
-
}, 300)
|
|
134
|
-
})
|
|
135
|
-
|
|
136
|
-
document.body.appendChild(chooser.container)
|
|
137
|
-
|
|
138
|
-
window.addEventListener('message', onMessage, false)
|
|
139
|
-
chooser.show()
|
|
140
|
-
})
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
export default chooseLocation
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { shouldBeObject, getParameterError } from '../utils'
|
|
2
|
-
|
|
3
|
-
export function setNavigationBarTitle (options) {
|
|
4
|
-
// options must be an Object
|
|
5
|
-
const isObject = shouldBeObject(options)
|
|
6
|
-
if (!isObject.res) {
|
|
7
|
-
const res = { errMsg: `setNavigationBarTitle${isObject.msg}` }
|
|
8
|
-
console.error(res.errMsg)
|
|
9
|
-
return Promise.reject(res)
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const { title, success, fail, complete } = options
|
|
13
|
-
const res = { errMsg: 'setNavigationBarTitle:ok' }
|
|
14
|
-
|
|
15
|
-
if (!title || typeof title !== 'string') {
|
|
16
|
-
res.errMsg = getParameterError({
|
|
17
|
-
name: 'setNavigationBarTitle',
|
|
18
|
-
para: 'title',
|
|
19
|
-
correct: 'String',
|
|
20
|
-
wrong: title
|
|
21
|
-
})
|
|
22
|
-
console.error(res.errMsg)
|
|
23
|
-
typeof fail === 'function' && fail(res)
|
|
24
|
-
typeof complete === 'function' && complete(res)
|
|
25
|
-
return Promise.reject(res)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
if (document.title !== title) {
|
|
29
|
-
document.title = title
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
typeof success === 'function' && success(res)
|
|
33
|
-
typeof complete === 'function' && complete(res)
|
|
34
|
-
|
|
35
|
-
return Promise.resolve(res)
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* @typedef {Object} NavigationBarColorParam
|
|
40
|
-
* @property {string} frontColor 前景颜色值,包括按钮、标题、状态栏的颜色,仅支持 #ffffff 和 #000000
|
|
41
|
-
* @property {string} backgroundColor 背景颜色值,有效值为十六进制颜色
|
|
42
|
-
* @property {{duration: number, timingFunc: string}} animation 动画效果
|
|
43
|
-
* @property {function} [success] 接口调用成功的回调函数
|
|
44
|
-
* @property {function} [fail] 接口调用失败的回调函数
|
|
45
|
-
* @property {function} [complete] 接口调用结束的回调函数(调用成功、失败都会执行)
|
|
46
|
-
*/
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* 设置页面导航条颜色
|
|
50
|
-
* @param {NavigationBarColorParam} options
|
|
51
|
-
*/
|
|
52
|
-
export function setNavigationBarColor (options) {
|
|
53
|
-
const meta = document.createElement('meta')
|
|
54
|
-
meta.setAttribute('name', 'theme-color')
|
|
55
|
-
meta.setAttribute('content', options.backgroundColor)
|
|
56
|
-
document.head.appendChild(meta)
|
|
57
|
-
}
|
package/src/api/open/index.js
DELETED
package/src/api/others/index.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { fromByteArray, toByteArray } from 'base64-js'
|
|
2
|
-
import { shouldBeObject, getParameterError } from '../utils'
|
|
3
|
-
|
|
4
|
-
export function arrayBufferToBase64 (arrayBuffer) {
|
|
5
|
-
return fromByteArray(arrayBuffer)
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export function base64ToArrayBuffer (base64) {
|
|
9
|
-
return toByteArray(base64)
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export function makePhoneCall (options) {
|
|
13
|
-
// options must be an Object
|
|
14
|
-
const isObject = shouldBeObject(options)
|
|
15
|
-
if (!isObject.res) {
|
|
16
|
-
const res = { errMsg: `makePhoneCall${isObject.msg}` }
|
|
17
|
-
console.error(res.errMsg)
|
|
18
|
-
return Promise.reject(res)
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const { phoneNumber, success, fail, complete } = options
|
|
22
|
-
const res = { errMsg: 'makePhoneCall:ok' }
|
|
23
|
-
|
|
24
|
-
if (typeof phoneNumber !== 'string') {
|
|
25
|
-
res.errMsg = getParameterError({
|
|
26
|
-
name: 'makePhoneCall',
|
|
27
|
-
para: 'phoneNumber',
|
|
28
|
-
correct: 'String',
|
|
29
|
-
wrong: phoneNumber
|
|
30
|
-
})
|
|
31
|
-
console.error(res.errMsg)
|
|
32
|
-
typeof fail === 'function' && fail(res)
|
|
33
|
-
typeof complete === 'function' && complete(res)
|
|
34
|
-
return Promise.reject(res)
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
window.location.href = `tel:${phoneNumber}`
|
|
38
|
-
|
|
39
|
-
typeof success === 'function' && success(res)
|
|
40
|
-
typeof complete === 'function' && complete(res)
|
|
41
|
-
|
|
42
|
-
return Promise.resolve(res)
|
|
43
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import Taro from '@tarojs/api'
|
|
2
|
-
/**
|
|
3
|
-
* 开始下拉刷新。调用后触发下拉刷新动画,效果与用户手动下拉刷新一致。
|
|
4
|
-
* @param {Object} object 参数
|
|
5
|
-
*/
|
|
6
|
-
const startPullDownRefresh = function (object = {}) {
|
|
7
|
-
return new Promise((resolve, reject) => {
|
|
8
|
-
const { success, fail, complete } = object
|
|
9
|
-
const res = {}
|
|
10
|
-
Taro.eventCenter.trigger('__taroStartPullDownRefresh', {
|
|
11
|
-
successHandler: () => {
|
|
12
|
-
success && success(res)
|
|
13
|
-
complete && complete()
|
|
14
|
-
resolve(res)
|
|
15
|
-
},
|
|
16
|
-
errorHandler: () => {
|
|
17
|
-
fail && fail(res)
|
|
18
|
-
complete && complete()
|
|
19
|
-
reject(res)
|
|
20
|
-
}
|
|
21
|
-
})
|
|
22
|
-
})
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* 停止当前页面下拉刷新。
|
|
27
|
-
* @param {Object} object 参数
|
|
28
|
-
*/
|
|
29
|
-
const stopPullDownRefresh = function (object = {}) {
|
|
30
|
-
return new Promise((resolve, reject) => {
|
|
31
|
-
const { success, fail, complete } = object
|
|
32
|
-
const res = {}
|
|
33
|
-
Taro.eventCenter.trigger('__taroStopPullDownRefresh', {
|
|
34
|
-
successHandler: () => {
|
|
35
|
-
success && success(res)
|
|
36
|
-
complete && complete()
|
|
37
|
-
resolve(res)
|
|
38
|
-
},
|
|
39
|
-
errorHandler: () => {
|
|
40
|
-
fail && fail(res)
|
|
41
|
-
complete && complete()
|
|
42
|
-
reject(res)
|
|
43
|
-
}
|
|
44
|
-
})
|
|
45
|
-
})
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export {
|
|
49
|
-
startPullDownRefresh,
|
|
50
|
-
stopPullDownRefresh
|
|
51
|
-
}
|
package/src/api/scroll/index.js
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import { getTimingFunc, easeInOut } from '../utils/index'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @typedef {object} PageScrollToParam pageScrollTo参数
|
|
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
|
-
*/
|
|
12
|
-
|
|
13
|
-
let scrollFunc
|
|
14
|
-
let timer
|
|
15
|
-
const FRAME_DURATION = 17
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* 将页面滚动到目标位置
|
|
19
|
-
* @param {PageScrollToParam} object 参数
|
|
20
|
-
*/
|
|
21
|
-
export const pageScrollTo = ({ scrollTop, selector, duration = 300, success, fail, complete }) => {
|
|
22
|
-
return new Promise((resolve, reject) => {
|
|
23
|
-
try {
|
|
24
|
-
if (scrollTop === undefined && !selector) {
|
|
25
|
-
throw Error('"scrollTop" 或 "selector" 需要其之一')
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
let el
|
|
29
|
-
if (document.querySelector('.taro-tabbar__tabbar') === null) {
|
|
30
|
-
// 没设置tabbar
|
|
31
|
-
el = window
|
|
32
|
-
} else {
|
|
33
|
-
// 有设置tabbar
|
|
34
|
-
el = document.querySelector('.taro-tabbar__panel') || window
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
if (!scrollFunc) {
|
|
38
|
-
if (el === window) {
|
|
39
|
-
scrollFunc = pos => {
|
|
40
|
-
if (pos === undefined) {
|
|
41
|
-
return window.pageYOffset
|
|
42
|
-
} else {
|
|
43
|
-
window.scrollTo(0, pos)
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
} else {
|
|
47
|
-
scrollFunc = pos => {
|
|
48
|
-
if (pos === undefined) {
|
|
49
|
-
return el.scrollTop
|
|
50
|
-
} else {
|
|
51
|
-
el.scrollTop = pos
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
if (scrollTop && selector) {
|
|
58
|
-
console.warn('"scrollTop" 或 "selector" 建议只设一个值,全部设置会忽略selector')
|
|
59
|
-
}
|
|
60
|
-
const from = scrollFunc()
|
|
61
|
-
let to
|
|
62
|
-
if (typeof scrollTop === 'number') {
|
|
63
|
-
to = scrollTop
|
|
64
|
-
} else {
|
|
65
|
-
to = document.querySelector(selector).offsetTop
|
|
66
|
-
}
|
|
67
|
-
const delta = to - from
|
|
68
|
-
|
|
69
|
-
const frameCnt = duration / FRAME_DURATION
|
|
70
|
-
const easeFunc = getTimingFunc(easeInOut, frameCnt)
|
|
71
|
-
|
|
72
|
-
const scroll = (frame = 0) => {
|
|
73
|
-
const dest = from + delta * easeFunc(frame)
|
|
74
|
-
scrollFunc(dest)
|
|
75
|
-
if (frame < frameCnt) {
|
|
76
|
-
timer && clearTimeout(timer)
|
|
77
|
-
timer = setTimeout(() => {
|
|
78
|
-
scroll(frame + 1)
|
|
79
|
-
}, FRAME_DURATION)
|
|
80
|
-
} else {
|
|
81
|
-
const res = {
|
|
82
|
-
errMsg: 'pageScrollTo:ok'
|
|
83
|
-
}
|
|
84
|
-
success && success(res)
|
|
85
|
-
complete && complete()
|
|
86
|
-
resolve(res)
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
scroll()
|
|
90
|
-
} catch (e) {
|
|
91
|
-
const res = {
|
|
92
|
-
errMsg: `pageScrollTo:fail ${e.message}`
|
|
93
|
-
}
|
|
94
|
-
fail && fail(res)
|
|
95
|
-
complete && complete()
|
|
96
|
-
reject(res)
|
|
97
|
-
}
|
|
98
|
-
})
|
|
99
|
-
}
|