@tarojs/taro-h5 3.3.13 → 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.
Files changed (169) hide show
  1. package/dist/index.cjs.js +6134 -8352
  2. package/dist/index.js +9044 -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 +29 -0
  22. package/src/api/canvas/canvasPutImageData.ts +26 -0
  23. package/src/api/canvas/canvasToTempFilePath.ts +26 -0
  24. package/src/api/canvas/createCanvasContext.ts +20 -0
  25. package/src/api/canvas/{index.js → index.ts} +9 -3
  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 +89 -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 +74 -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 +92 -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 +99 -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 +80 -0
  63. package/src/api/{image → media/image}/getImageInfo.js +0 -0
  64. package/src/api/media/image/index.ts +13 -0
  65. package/src/api/{image → media/image}/previewImage.js +4 -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 -25
  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 -30
  83. package/src/api/{fileTransfer/utils.js → network/utils.ts} +0 -0
  84. package/src/api/{webSocket/index.js → network/websocket/index.ts} +50 -57
  85. package/src/api/{webSocket/socketTask.js → network/websocket/socketTask.ts} +16 -6
  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 +193 -0
  110. package/src/api/swan/index.ts +31 -0
  111. package/src/{taro/index.js → api/taro.ts} +133 -149
  112. package/src/api/{createAnimation/index.js → ui/animation/index.ts} +26 -14
  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} +102 -90
  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 +32 -0
  124. package/src/api/{scroll/index.js → ui/scroll/index.ts} +16 -28
  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} +24 -87
  130. package/src/api/worker/index.ts +4 -0
  131. package/src/api/wxml/index.ts +9 -0
  132. package/src/api/{createSelectorQuery/index.js → wxml/selectorQuery.ts} +86 -59
  133. package/src/index.ts +6 -0
  134. package/src/types/api.d.ts +4 -0
  135. package/src/types/define.d.ts +2 -0
  136. package/{types → src/types}/index.d.ts +0 -0
  137. package/{types → src/types}/type.ts +1 -1
  138. package/src/api/accelerometer/index.js +0 -105
  139. package/src/api/audio/index.js +0 -137
  140. package/src/api/canvas/canvasGetImageData.js +0 -44
  141. package/src/api/canvas/canvasPutImageData.js +0 -45
  142. package/src/api/canvas/canvasToTempFilePath.js +0 -49
  143. package/src/api/canvas/createCanvasContext.js +0 -340
  144. package/src/api/clipboard/index.js +0 -113
  145. package/src/api/compass/index.js +0 -99
  146. package/src/api/deviceMotion/index.js +0 -105
  147. package/src/api/fileTransfer/index.js +0 -2
  148. package/src/api/image/chooseImage.js +0 -87
  149. package/src/api/image/index.js +0 -7
  150. package/src/api/index.js +0 -29
  151. package/src/api/interactive/actionSheet.js +0 -214
  152. package/src/api/interactive/modal.js +0 -256
  153. package/src/api/location/chooseLocation.js +0 -143
  154. package/src/api/location/index.js +0 -5
  155. package/src/api/navigationBar/index.js +0 -57
  156. package/src/api/open/index.js +0 -5
  157. package/src/api/others/index.js +0 -43
  158. package/src/api/pullDownRefresh/index.js +0 -51
  159. package/src/api/storage/index.js +0 -211
  160. package/src/api/system/index.js +0 -9
  161. package/src/api/system/info.js +0 -36
  162. package/src/api/system/network.js +0 -68
  163. package/src/api/tabBar/index.js +0 -424
  164. package/src/api/unsupportedApi/index.js +0 -278
  165. package/src/api/vibrate/index.js +0 -49
  166. package/src/api/video/index.js +0 -87
  167. package/src/api/window/index.js +0 -38
  168. package/src/index.cjs.js +0 -11
  169. package/src/index.js +0 -6
@@ -0,0 +1,212 @@
1
+ import { inlineStyle, setTransform } from '../../utils'
2
+
3
+ const noop = function () {}
4
+
5
+ export default class ActionSheet {
6
+ options = {
7
+ itemList: [],
8
+ itemColor: '#000000',
9
+ success: noop,
10
+ fail: noop,
11
+ complete: noop
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
+ actionSheetStyle: {
25
+ 'z-index': '4999',
26
+ position: 'fixed',
27
+ left: '0',
28
+ bottom: '0',
29
+ '-webkit-transform': 'translate(0, 100%)',
30
+ transform: 'translate(0, 100%)',
31
+ width: '100%',
32
+ 'line-height': '1.6',
33
+ background: '#EFEFF4',
34
+ '-webkit-transition': '-webkit-transform .3s',
35
+ transition: 'transform .3s'
36
+ },
37
+ menuStyle: {
38
+ 'background-color': '#FCFCFD'
39
+ },
40
+ cellStyle: {
41
+ position: 'relative',
42
+ padding: '10px 0',
43
+ 'text-align': 'center',
44
+ 'font-size': '18px'
45
+ },
46
+ cancelStyle: {
47
+ 'margin-top': '6px',
48
+ padding: '10px 0',
49
+ 'text-align': 'center',
50
+ 'font-size': '18px',
51
+ color: '#000000',
52
+ 'background-color': '#FCFCFD'
53
+ }
54
+ }
55
+
56
+ lastConfig = {}
57
+ el: HTMLDivElement
58
+ actionSheet: HTMLDivElement
59
+ menu: HTMLDivElement
60
+ cells: HTMLDivElement[]
61
+ cancel: HTMLDivElement
62
+ hideOpacityTimer: any
63
+ hideDisplayTimer: any
64
+
65
+ create (options = {}) {
66
+ return new Promise<string | number>((resolve) => {
67
+ // style
68
+ const { maskStyle, actionSheetStyle, menuStyle, cellStyle, cancelStyle } = this.style
69
+
70
+ // configuration
71
+ const config = {
72
+ ...this.options,
73
+ ...options
74
+ }
75
+
76
+ this.lastConfig = config
77
+
78
+ // wrapper
79
+ this.el = document.createElement('div')
80
+ this.el.className = 'taro__actionSheet'
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.setAttribute('style', inlineStyle(maskStyle))
87
+
88
+ // actionSheet
89
+ this.actionSheet = document.createElement('div')
90
+ this.actionSheet.setAttribute('style', inlineStyle(actionSheetStyle))
91
+
92
+ // menu
93
+ this.menu = document.createElement('div')
94
+ this.menu.setAttribute('style', inlineStyle({
95
+ ...menuStyle,
96
+ color: config.itemColor
97
+ }))
98
+
99
+ // cells
100
+ this.cells = config.itemList.map((item, index) => {
101
+ const cell: HTMLDivElement = document.createElement('div')
102
+ cell.className = 'taro-actionsheet__cell'
103
+ cell.setAttribute('style', inlineStyle(cellStyle))
104
+ cell.textContent = item
105
+ cell.dataset.tapIndex = `${index}`
106
+ cell.onclick = e => {
107
+ this.hide()
108
+ const target = e.currentTarget as HTMLDivElement
109
+ const index = Number(target?.dataset.tapIndex) || 0
110
+ resolve(index)
111
+ }
112
+ return cell
113
+ })
114
+
115
+ // cancel
116
+ this.cancel = document.createElement('div')
117
+ this.cancel.setAttribute('style', inlineStyle(cancelStyle))
118
+ this.cancel.textContent = '取消'
119
+
120
+ // result
121
+ this.cells.forEach(item => this.menu.appendChild(item))
122
+ this.actionSheet.appendChild(this.menu)
123
+ this.actionSheet.appendChild(this.cancel)
124
+ this.el.appendChild(mask)
125
+ this.el.appendChild(this.actionSheet)
126
+
127
+ // callbacks
128
+ const cb = () => {
129
+ this.hide()
130
+ resolve('cancel')
131
+ }
132
+ mask.onclick = cb
133
+ this.cancel.onclick = cb
134
+
135
+ // show immediately
136
+ document.body.appendChild(this.el)
137
+ setTimeout(() => {
138
+ this.el.style.opacity = '1'
139
+ setTransform(this.actionSheet, 'translate(0, 0)')
140
+ }, 0)
141
+ })
142
+ }
143
+
144
+ show (options = {}) {
145
+ return new Promise<string | number>((resolve) => {
146
+ const config = {
147
+ ...this.options,
148
+ ...options
149
+ }
150
+
151
+ this.lastConfig = config
152
+
153
+ if (this.hideOpacityTimer) clearTimeout(this.hideOpacityTimer)
154
+ if (this.hideDisplayTimer) clearTimeout(this.hideDisplayTimer)
155
+
156
+ // itemColor
157
+ if (config.itemColor) this.menu.style.color = config.itemColor
158
+
159
+ // cells
160
+ const { cellStyle } = this.style
161
+
162
+ config.itemList.forEach((item, index) => {
163
+ let cell: HTMLDivElement
164
+ if (this.cells[index]) {
165
+ // assign new content
166
+ cell = this.cells[index]
167
+ } else {
168
+ // create new cell
169
+ cell = document.createElement('div')
170
+ cell.className = 'taro-actionsheet__cell'
171
+ cell.setAttribute('style', inlineStyle(cellStyle))
172
+ cell.dataset.tapIndex = `${index}`
173
+ this.cells.push(cell)
174
+ this.menu.appendChild(cell)
175
+ }
176
+ cell.textContent = item
177
+ cell.onclick = e => {
178
+ this.hide()
179
+ const target = e.currentTarget as HTMLDivElement
180
+ const index = Number(target?.dataset.tapIndex) || 0
181
+ resolve(index)
182
+ }
183
+ })
184
+ const cellsLen = this.cells.length
185
+ const itemListLen = config.itemList.length
186
+ if (cellsLen > itemListLen) {
187
+ for (let i = itemListLen; i < cellsLen; i++) {
188
+ this.menu.removeChild(this.cells[i])
189
+ }
190
+ this.cells.splice(itemListLen)
191
+ }
192
+
193
+ // show
194
+ this.el.style.display = 'block'
195
+ setTimeout(() => {
196
+ this.el.style.opacity = '1'
197
+ setTransform(this.actionSheet, 'translate(0, 0)')
198
+ }, 0)
199
+ })
200
+ }
201
+
202
+ hide () {
203
+ if (this.hideOpacityTimer) clearTimeout(this.hideOpacityTimer)
204
+ if (this.hideDisplayTimer) clearTimeout(this.hideDisplayTimer)
205
+
206
+ this.hideOpacityTimer = setTimeout(() => {
207
+ this.el.style.opacity = '0'
208
+ setTransform(this.actionSheet, 'translate(0, 100%)')
209
+ this.hideDisplayTimer = setTimeout(() => { this.el.style.display = 'none' }, 200)
210
+ }, 0)
211
+ }
212
+ }
@@ -1,9 +1,12 @@
1
1
  import Taro from '@tarojs/api'
2
- import { errorHandler, getParameterError } from '../utils'
2
+ import { getParameterError, temporarilyNotSupport } from '../../utils'
3
+ import { MethodHandler } from '../../utils/handler'
3
4
  import Toast from './toast'
4
5
  import Modal from './modal'
5
6
  import ActionSheet from './actionSheet'
6
7
 
8
+ // 交互
9
+
7
10
  let status = 'default'
8
11
 
9
12
  // inject necessary style
@@ -21,26 +24,20 @@ const toast = new Toast()
21
24
  const modal = new Modal()
22
25
  const actionSheet = new ActionSheet()
23
26
 
24
- function showToast (options = {}) {
27
+ const showToast: typeof Taro.showToast = (options = {
28
+ title: '',
29
+ icon: 'success',
30
+ image: '',
31
+ duration: 1500,
32
+ mask: false
33
+ }) => {
25
34
  init(document)
26
-
27
- const _default = {
28
- title: '',
29
- icon: 'success',
30
- image: '',
31
- duration: 1500,
32
- mask: false
33
- }
34
- options = Object.assign({}, _default, options)
35
- options._type = 'toast'
36
-
37
- // verify options
38
- const handler = errorHandler(options.fail, options.complete)
35
+ const { success, fail, complete } = options
36
+ const handle = new MethodHandler({ name: 'showToast', success, fail, complete })
39
37
 
40
38
  if (typeof options.title !== 'string') {
41
- return handler({
39
+ return handle.fail({
42
40
  errMsg: getParameterError({
43
- name: 'showToast',
44
41
  para: 'title',
45
42
  correct: 'String',
46
43
  wrong: options.title
@@ -49,9 +46,8 @@ function showToast (options = {}) {
49
46
  }
50
47
 
51
48
  if (typeof options.duration !== 'number') {
52
- return handler({
49
+ return handle.fail({
53
50
  errMsg: getParameterError({
54
- name: 'showToast',
55
51
  para: 'duration',
56
52
  correct: 'Number',
57
53
  wrong: options.duration
@@ -63,38 +59,41 @@ function showToast (options = {}) {
63
59
 
64
60
  options.mask = !!options.mask
65
61
 
66
- if (!toast.el) return toast.create(options)
67
- return toast.show(options)
62
+ let errMsg = ''
63
+ if (!toast.el) {
64
+ errMsg = toast.create(options, 'loading')
65
+ } else {
66
+ errMsg = toast.show(options, 'loading')
67
+ }
68
+ return handle.success({ errMsg })
68
69
  }
69
70
 
70
- function hideToast () {
71
- if (!toast.el) return
71
+ const hideToast: typeof Taro.hideToast = ({ success, fail, complete } = {}) => {
72
+ const handle = new MethodHandler({ name: 'hideToast', success, fail, complete })
73
+ if (!toast.el) return handle.success()
72
74
  toast.hide(0, 'toast')
75
+ return handle.success()
73
76
  }
74
77
 
75
- function showLoading (options = {}) {
78
+ const showLoading: typeof Taro.showLoading = (options = {
79
+ title: '',
80
+ mask: false
81
+ }) => {
76
82
  init(document)
83
+ const { success, fail, complete } = options
84
+ const handle = new MethodHandler({ name: 'showLoading', success, fail, complete })
77
85
 
78
- const _default = {
79
- title: '',
80
- mask: false
81
- }
82
86
  const config = {
83
87
  icon: 'loading',
84
88
  image: '',
85
89
  duration: -1
86
90
  }
87
91
 
88
- options = Object.assign({}, _default, options, config)
89
- options._type = 'loading'
90
-
91
- // verify options
92
- const handler = errorHandler(options.fail, options.complete)
92
+ options = Object.assign({}, options, config)
93
93
 
94
94
  if (typeof options.title !== 'string') {
95
- return handler({
95
+ return handle.fail({
96
96
  errMsg: getParameterError({
97
- name: 'showLoading',
98
97
  para: 'title',
99
98
  correct: 'String',
100
99
  wrong: options.title
@@ -104,36 +103,38 @@ function showLoading (options = {}) {
104
103
 
105
104
  options.mask = !!options.mask
106
105
 
107
- if (!toast.el) return toast.create(options)
108
- return toast.show(options)
106
+ let errMsg = ''
107
+ if (!toast.el) {
108
+ errMsg = toast.create(options, 'loading')
109
+ } else {
110
+ errMsg = toast.show(options, 'loading')
111
+ }
112
+ return handle.success({ errMsg })
109
113
  }
110
114
 
111
- function hideLoading () {
112
- if (!toast.el) return
115
+ const hideLoading: typeof Taro.hideLoading = ({ success, fail, complete } = {}) => {
116
+ const handle = new MethodHandler({ name: 'hideLoading', success, fail, complete })
117
+ if (!toast.el) return handle.success()
113
118
  toast.hide(0, 'loading')
119
+ return handle.success()
114
120
  }
115
121
 
116
- function showModal (options = {}) {
122
+ const showModal: typeof Taro.showModal = async (options = {
123
+ title: '',
124
+ content: '',
125
+ showCancel: true,
126
+ cancelText: '取消',
127
+ cancelColor: '#000000',
128
+ confirmText: '确定',
129
+ confirmColor: '#3CC51F'
130
+ }) => {
117
131
  init(document)
118
-
119
- const _default = {
120
- title: '',
121
- content: '',
122
- showCancel: true,
123
- cancelText: '取消',
124
- cancelColor: '#000000',
125
- confirmText: '确定',
126
- confirmColor: '#3CC51F'
127
- }
128
- options = Object.assign({}, _default, options)
129
-
130
- // verify options
131
- const handler = errorHandler(options.fail, options.complete)
132
+ const { success, fail, complete } = options
133
+ const handle = new MethodHandler({ name: 'showModal', success, fail, complete })
132
134
 
133
135
  if (typeof options.title !== 'string') {
134
- return handler({
136
+ return handle.fail({
135
137
  errMsg: getParameterError({
136
- name: 'showModal',
137
138
  para: 'title',
138
139
  correct: 'String',
139
140
  wrong: options.title
@@ -142,9 +143,8 @@ function showModal (options = {}) {
142
143
  }
143
144
 
144
145
  if (typeof options.content !== 'string') {
145
- return handler({
146
+ return handle.fail({
146
147
  errMsg: getParameterError({
147
- name: 'showModal',
148
148
  para: 'content',
149
149
  correct: 'String',
150
150
  wrong: options.content
@@ -153,9 +153,8 @@ function showModal (options = {}) {
153
153
  }
154
154
 
155
155
  if (typeof options.cancelText !== 'string') {
156
- return handler({
156
+ return handle.fail({
157
157
  errMsg: getParameterError({
158
- name: 'showModal',
159
158
  para: 'cancelText',
160
159
  correct: 'String',
161
160
  wrong: options.cancelText
@@ -164,13 +163,14 @@ function showModal (options = {}) {
164
163
  }
165
164
 
166
165
  if (options.cancelText.replace(/[\u0391-\uFFE5]/g, 'aa').length > 8) {
167
- return handler({ errMsg: 'showModal:fail cancelText length should not larger then 4 Chinese characters' })
166
+ return handle.fail({
167
+ errMsg: 'showModal:fail cancelText length should not larger then 4 Chinese characters'
168
+ })
168
169
  }
169
170
 
170
171
  if (typeof options.confirmText !== 'string') {
171
- return handler({
172
+ return handle.fail({
172
173
  errMsg: getParameterError({
173
- name: 'showModal',
174
174
  para: 'confirmText',
175
175
  correct: 'String',
176
176
  wrong: options.confirmText
@@ -179,13 +179,14 @@ function showModal (options = {}) {
179
179
  }
180
180
 
181
181
  if (options.confirmText.replace(/[\u0391-\uFFE5]/g, 'aa').length > 8) {
182
- return handler({ errMsg: 'showModal:fail confirmText length should not larger then 4 Chinese characters' })
182
+ return handle.fail({
183
+ errMsg: 'showModal:fail confirmText length should not larger then 4 Chinese characters'
184
+ })
183
185
  }
184
186
 
185
187
  if (typeof options.cancelColor !== 'string') {
186
- return handler({
188
+ return handle.fail({
187
189
  errMsg: getParameterError({
188
- name: 'showModal',
189
190
  para: 'cancelColor',
190
191
  correct: 'String',
191
192
  wrong: options.cancelColor
@@ -194,9 +195,8 @@ function showModal (options = {}) {
194
195
  }
195
196
 
196
197
  if (typeof options.confirmColor !== 'string') {
197
- return handler({
198
+ return handle.fail({
198
199
  errMsg: getParameterError({
199
- name: 'showModal',
200
200
  para: 'confirmColor',
201
201
  correct: 'String',
202
202
  wrong: options.confirmColor
@@ -206,8 +206,13 @@ function showModal (options = {}) {
206
206
 
207
207
  options.showCancel = !!options.showCancel
208
208
 
209
- if (!modal.el) return modal.create(options)
210
- return modal.show(options)
209
+ let errMsg = ''
210
+ if (!modal.el) {
211
+ errMsg = await modal.create(options)
212
+ } else {
213
+ errMsg = await modal.show(options)
214
+ }
215
+ return handle.success({ errMsg })
211
216
  }
212
217
 
213
218
  function hideModal () {
@@ -215,22 +220,18 @@ function hideModal () {
215
220
  modal.hide()
216
221
  }
217
222
 
218
- function showActionSheet (options = {}) {
223
+ const showActionSheet: typeof Taro.showActionSheet = async (options = {
224
+ itemColor: '#000000',
225
+ itemList: []
226
+ }) => {
219
227
  init(document)
220
-
221
- const _default = {
222
- itemColor: '#000000'
223
- }
224
- options = Object.assign({}, _default, options)
225
-
226
- // verify options
227
- const handler = errorHandler(options.fail, options.complete)
228
+ const { success, fail, complete } = options
229
+ const handle = new MethodHandler<Taro.showActionSheet.SuccessCallbackResult>({ name: 'showActionSheet', success, fail, complete })
228
230
 
229
231
  // list item String
230
232
  if (!Array.isArray(options.itemList)) {
231
- return handler({
233
+ return handle.fail({
232
234
  errMsg: getParameterError({
233
- name: 'showActionSheet',
234
235
  para: 'itemList',
235
236
  correct: 'Array',
236
237
  wrong: options.itemList
@@ -239,18 +240,17 @@ function showActionSheet (options = {}) {
239
240
  }
240
241
 
241
242
  if (options.itemList.length < 1) {
242
- return handler({ errMsg: 'showActionSheet:fail parameter error: parameter.itemList should have at least 1 item' })
243
+ return handle.fail({ errMsg: 'showActionSheet:fail parameter error: parameter.itemList should have at least 1 item' })
243
244
  }
244
245
 
245
246
  if (options.itemList.length > 6) {
246
- return handler({ errMsg: 'showActionSheet:fail parameter error: parameter.itemList should not be large than 6' })
247
+ return handle.fail({ errMsg: 'showActionSheet:fail parameter error: parameter.itemList should not be large than 6' })
247
248
  }
248
249
 
249
250
  for (let i = 0; i < options.itemList.length; i++) {
250
251
  if (typeof options.itemList[i] !== 'string') {
251
- return handler({
252
+ return handle.fail({
252
253
  errMsg: getParameterError({
253
- name: 'showActionSheet',
254
254
  para: `itemList[${i}]`,
255
255
  correct: 'String',
256
256
  wrong: options.itemList[i]
@@ -260,9 +260,8 @@ function showActionSheet (options = {}) {
260
260
  }
261
261
 
262
262
  if (typeof options.itemColor !== 'string') {
263
- return handler({
263
+ return handle.fail({
264
264
  errMsg: getParameterError({
265
- name: 'showActionSheet',
266
265
  para: 'itemColor',
267
266
  correct: 'String',
268
267
  wrong: options.itemColor
@@ -270,8 +269,18 @@ function showActionSheet (options = {}) {
270
269
  })
271
270
  }
272
271
 
273
- if (!actionSheet.el) return actionSheet.create(options)
274
- return actionSheet.show(options)
272
+ let result: number | string = ''
273
+ if (!actionSheet.el) {
274
+ result = await actionSheet.create(options)
275
+ } else {
276
+ result = await actionSheet.show(options)
277
+ }
278
+
279
+ if (typeof result === 'string') {
280
+ return handle.fail(({ errMsg: result }))
281
+ } else {
282
+ return handle.success(({ tapIndex: result }))
283
+ }
275
284
  }
276
285
 
277
286
  Taro.eventCenter.on('__taroRouterChange', () => {
@@ -280,4 +289,7 @@ Taro.eventCenter.on('__taroRouterChange', () => {
280
289
  hideModal()
281
290
  })
282
291
 
283
- export { showToast, hideToast, showLoading, hideLoading, showModal, showActionSheet }
292
+ const enableAlertBeforeUnload = temporarilyNotSupport('enableAlertBeforeUnload')
293
+ const disableAlertBeforeUnload = temporarilyNotSupport('disableAlertBeforeUnload')
294
+
295
+ export { showToast, showModal, showLoading, showActionSheet, hideToast, hideLoading, enableAlertBeforeUnload, disableAlertBeforeUnload }