@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.
Files changed (175) hide show
  1. package/dist/index.cjs.js +7971 -9468
  2. package/dist/index.js +10767 -0
  3. package/dist/taroApis.js +1 -1
  4. package/package.json +9 -9
  5. package/src/api/ad/index.ts +5 -0
  6. package/src/api/ai/facial.ts +6 -0
  7. package/src/api/ai/index.ts +2 -0
  8. package/src/api/ai/visual.ts +4 -0
  9. package/src/api/alipay/index.ts +4 -0
  10. package/src/api/base/crypto.ts +4 -0
  11. package/src/api/base/debug.ts +5 -0
  12. package/src/api/base/index.ts +23 -0
  13. package/src/api/base/performance.ts +5 -0
  14. package/src/api/base/system/index.ts +2 -0
  15. package/src/api/base/system/info.ts +64 -0
  16. package/src/api/base/system/network.ts +70 -0
  17. package/src/api/base/update.ts +5 -0
  18. package/src/api/base/weapp/app-event.ts +19 -0
  19. package/src/api/base/weapp/life-cycle.ts +5 -0
  20. package/src/api/canvas/CanvasContext.ts +230 -0
  21. package/src/api/canvas/canvasGetImageData.ts +27 -0
  22. package/src/api/canvas/canvasPutImageData.ts +24 -0
  23. package/src/api/canvas/canvasToTempFilePath.ts +24 -0
  24. package/src/api/canvas/createCanvasContext.ts +18 -0
  25. package/src/api/canvas/index.ts +10 -0
  26. package/src/api/cloud/index.ts +27 -0
  27. package/src/api/data-analysis/index.ts +6 -0
  28. package/src/api/device/accelerometer.ts +87 -0
  29. package/src/api/device/accessibility.ts +4 -0
  30. package/src/api/device/battery.ts +5 -0
  31. package/src/api/device/bluetooth-ble.ts +19 -0
  32. package/src/api/device/bluetooth-peripheral.ts +6 -0
  33. package/src/api/device/bluetooth.ts +16 -0
  34. package/src/api/device/calendar.ts +5 -0
  35. package/src/api/device/clipboard.ts +67 -0
  36. package/src/api/device/compass.ts +67 -0
  37. package/src/api/device/contact.ts +5 -0
  38. package/src/api/device/crypto.ts +4 -0
  39. package/src/api/device/gyroscope.ts +7 -0
  40. package/src/api/device/iBeacon.ts +10 -0
  41. package/src/api/device/index.ts +22 -0
  42. package/src/api/device/keyboard.ts +7 -0
  43. package/src/api/device/memory.ts +5 -0
  44. package/src/api/device/motion.ts +85 -0
  45. package/src/api/device/nfc.ts +10 -0
  46. package/src/api/device/phone.ts +30 -0
  47. package/src/api/device/scan.ts +7 -0
  48. package/src/api/device/screen.ts +9 -0
  49. package/src/api/device/vibrate.ts +36 -0
  50. package/src/api/device/wifi.ts +13 -0
  51. package/src/api/ext/index.ts +5 -0
  52. package/src/api/files/index.ts +11 -0
  53. package/src/api/framework/index.ts +10 -0
  54. package/src/api/index.ts +25 -0
  55. package/src/api/location/chooseLocation.ts +106 -0
  56. package/src/api/location/index.ts +19 -0
  57. package/src/api/location/style.css +8 -8
  58. package/src/api/media/audio/index.ts +105 -0
  59. package/src/api/media/background-audio.ts +12 -0
  60. package/src/api/media/camera.ts +4 -0
  61. package/src/api/media/editor.ts +29 -0
  62. package/src/api/media/image/chooseImage.ts +78 -0
  63. package/src/api/media/image/getImageInfo.ts +35 -0
  64. package/src/api/media/image/index.ts +13 -0
  65. package/src/api/media/image/previewImage.ts +101 -0
  66. package/src/api/media/index.ts +13 -0
  67. package/src/api/media/live.ts +5 -0
  68. package/src/api/media/map.ts +4 -0
  69. package/src/api/media/media-recorder.ts +4 -0
  70. package/src/api/media/recorder.ts +6 -0
  71. package/src/api/media/video/index.ts +82 -0
  72. package/src/api/media/video-decoder.ts +4 -0
  73. package/src/api/media/video-processing.ts +4 -0
  74. package/src/api/media/voip.ts +17 -0
  75. package/src/api/navigate/index.ts +7 -0
  76. package/src/api/{fileTransfer/downloadFile.js → network/download.ts} +16 -27
  77. package/src/api/network/index.ts +7 -0
  78. package/src/api/network/mdns.ts +13 -0
  79. package/src/api/{request/index.js → network/request/index.ts} +9 -6
  80. package/src/api/network/tcp.ts +4 -0
  81. package/src/api/network/udp.ts +4 -0
  82. package/src/api/{fileTransfer/uploadFile.js → network/upload.ts} +28 -32
  83. package/src/api/{fileTransfer/utils.js → network/utils.ts} +0 -0
  84. package/src/api/network/websocket/index.ts +88 -0
  85. package/src/api/{webSocket/socketTask.js → network/websocket/socketTask.ts} +17 -7
  86. package/src/api/open-api/account.ts +4 -0
  87. package/src/api/open-api/address.ts +4 -0
  88. package/src/api/open-api/authorize.ts +5 -0
  89. package/src/api/open-api/card.ts +5 -0
  90. package/src/api/open-api/channels-live.ts +9 -0
  91. package/src/api/open-api/customer-service.ts +4 -0
  92. package/src/api/open-api/facial.ts +7 -0
  93. package/src/api/open-api/favorites.ts +5 -0
  94. package/src/api/open-api/group.ts +4 -0
  95. package/src/api/open-api/index.ts +18 -0
  96. package/src/api/open-api/invoice.ts +5 -0
  97. package/src/api/open-api/license-plate.ts +4 -0
  98. package/src/api/open-api/login.ts +6 -0
  99. package/src/api/open-api/red-package.ts +4 -0
  100. package/src/api/open-api/settings.ts +5 -0
  101. package/src/api/open-api/soter.ts +6 -0
  102. package/src/api/open-api/subscribe-message.ts +4 -0
  103. package/src/api/open-api/user-info.ts +5 -0
  104. package/src/api/open-api/werun.ts +5 -0
  105. package/src/api/payment/index.ts +5 -0
  106. package/src/api/route/index.ts +10 -0
  107. package/src/api/share/index.ts +13 -0
  108. package/src/api/storage/background-fetch.ts +7 -0
  109. package/src/api/storage/index.ts +181 -0
  110. package/src/api/swan/index.ts +31 -0
  111. package/src/{taro/index.js → api/taro.ts} +89 -104
  112. package/src/api/{createAnimation/index.js → ui/animation/index.ts} +51 -35
  113. package/src/api/ui/background.ts +5 -0
  114. package/src/api/ui/custom-component.ts +4 -0
  115. package/src/api/ui/fonts.ts +4 -0
  116. package/src/api/ui/index.ts +12 -0
  117. package/src/api/ui/interaction/actionSheet.ts +212 -0
  118. package/src/api/{interactive/index.js → ui/interaction/index.ts} +93 -77
  119. package/src/api/ui/interaction/modal.ts +237 -0
  120. package/src/api/{interactive/toast.js → ui/interaction/toast.ts} +35 -33
  121. package/src/api/ui/menu.ts +4 -0
  122. package/src/api/ui/navigation-bar/index.ts +52 -0
  123. package/src/api/ui/pull-down-refresh.ts +27 -0
  124. package/src/api/ui/scroll/index.ts +85 -0
  125. package/src/api/ui/sticky.ts +4 -0
  126. package/src/api/ui/tab-bar.ts +326 -0
  127. package/src/api/ui/window.ts +37 -0
  128. package/src/api/utils/handler.ts +105 -0
  129. package/src/api/utils/{index.js → index.ts} +36 -115
  130. package/src/api/worker/index.ts +4 -0
  131. package/src/api/wxml/index.ts +9 -0
  132. package/src/api/wxml/nodesRef.ts +49 -0
  133. package/src/api/{createSelectorQuery/index.js → wxml/selectorQuery.ts} +75 -94
  134. package/src/index.ts +6 -0
  135. package/src/types/api.d.ts +4 -0
  136. package/src/types/define.d.ts +2 -0
  137. package/{types → src/types}/index.d.ts +0 -0
  138. package/{types → src/types}/type.ts +1 -1
  139. package/src/api/accelerometer/index.js +0 -105
  140. package/src/api/audio/index.js +0 -137
  141. package/src/api/canvas/canvasGetImageData.js +0 -44
  142. package/src/api/canvas/canvasPutImageData.js +0 -45
  143. package/src/api/canvas/canvasToTempFilePath.js +0 -49
  144. package/src/api/canvas/createCanvasContext.js +0 -340
  145. package/src/api/canvas/index.js +0 -4
  146. package/src/api/clipboard/index.js +0 -113
  147. package/src/api/compass/index.js +0 -99
  148. package/src/api/deviceMotion/index.js +0 -105
  149. package/src/api/fileTransfer/index.js +0 -2
  150. package/src/api/image/chooseImage.js +0 -87
  151. package/src/api/image/getImageInfo.js +0 -74
  152. package/src/api/image/index.js +0 -7
  153. package/src/api/image/previewImage.js +0 -94
  154. package/src/api/index.js +0 -29
  155. package/src/api/interactive/actionSheet.js +0 -214
  156. package/src/api/interactive/modal.js +0 -256
  157. package/src/api/location/chooseLocation.js +0 -143
  158. package/src/api/location/index.js +0 -5
  159. package/src/api/navigationBar/index.js +0 -57
  160. package/src/api/open/index.js +0 -5
  161. package/src/api/others/index.js +0 -43
  162. package/src/api/pullDownRefresh/index.js +0 -51
  163. package/src/api/scroll/index.js +0 -99
  164. package/src/api/storage/index.js +0 -211
  165. package/src/api/system/index.js +0 -9
  166. package/src/api/system/info.js +0 -36
  167. package/src/api/system/network.js +0 -68
  168. package/src/api/tabBar/index.js +0 -402
  169. package/src/api/unsupportedApi/index.js +0 -278
  170. package/src/api/vibrate/index.js +0 -49
  171. package/src/api/video/index.js +0 -87
  172. package/src/api/webSocket/index.js +0 -103
  173. package/src/api/window/index.js +0 -38
  174. package/src/index.cjs.js +0 -11
  175. 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 '../utils'
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: '0',
49
- 'vertical-align': 'middle',
50
- 'font-family': 'taro',
51
- '-webkit-font-smoothing': 'antialiased',
52
- color: '#FFFFFF',
53
- 'font-size': '55px',
54
- 'line-height': '1'
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
- create (options = {}) {
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
- const errMsg = this.type === 'loading' ? 'showLoading:ok' : 'showToast:ok'
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
- const errMsg = this.type === 'loading' ? 'showLoading:ok' : 'showToast:ok'
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,4 @@
1
+ import { temporarilyNotSupport } from '../utils'
2
+
3
+ // 菜单
4
+ export const getMenuButtonBoundingClientRect = temporarilyNotSupport('getMenuButtonBoundingClientRect')
@@ -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,27 @@
1
+ import Taro from '@tarojs/api'
2
+ import { MethodHandler } from '../utils/handler'
3
+ /**
4
+ * 开始下拉刷新。调用后触发下拉刷新动画,效果与用户手动下拉刷新一致。
5
+ */
6
+ export 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
+ export 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
+ }
@@ -0,0 +1,85 @@
1
+ import Taro from '@tarojs/api'
2
+ import { Current } from '@tarojs/runtime'
3
+
4
+ import { MethodHandler } from '../../utils/handler'
5
+ import { getTimingFunc, easeInOut } from '../../utils'
6
+
7
+ let timer: number
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
25
+ const el: HTMLDivElement | null = (id
26
+ ? document.getElementById(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
+ }
@@ -0,0 +1,4 @@
1
+ import { temporarilyNotSupport } from '../utils'
2
+
3
+ // 置顶
4
+ export const setTopBarText = temporarilyNotSupport('setTopBarText')