@tarojs/taro-h5 3.3.17 → 3.4.0-beta.2
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 +2890 -1176
- package/dist/index.js +2867 -1144
- package/dist/taroApis.js +1 -1
- package/package.json +6 -10
- package/src/api/base/system/index.ts +2 -2
- package/src/api/canvas/canvasGetImageData.ts +1 -3
- package/src/api/canvas/canvasPutImageData.ts +1 -3
- package/src/api/canvas/canvasToTempFilePath.ts +1 -3
- package/src/api/canvas/createCanvasContext.ts +1 -3
- package/src/api/canvas/index.ts +4 -4
- package/src/api/cloud/index.ts +1 -1
- package/src/api/device/accelerometer.ts +4 -6
- package/src/api/device/compass.ts +4 -11
- package/src/api/device/motion.ts +4 -11
- package/src/api/location/index.ts +1 -1
- package/src/api/media/audio/index.ts +12 -6
- package/src/api/media/image/chooseImage.ts +1 -3
- package/src/api/media/image/getImageInfo.ts +35 -0
- package/src/api/media/image/index.ts +3 -3
- package/src/api/media/image/previewImage.ts +101 -0
- package/src/api/network/download.ts +1 -3
- package/src/api/network/upload.ts +1 -3
- package/src/api/network/websocket/index.ts +12 -20
- package/src/api/network/websocket/socketTask.ts +1 -1
- package/src/api/storage/index.ts +58 -70
- package/src/api/taro.ts +4 -48
- package/src/api/ui/animation/index.ts +25 -21
- package/src/api/ui/interaction/index.ts +28 -24
- package/src/api/ui/pull-down-refresh.ts +2 -7
- package/src/api/ui/scroll/index.ts +9 -11
- package/src/api/utils/index.ts +17 -33
- package/src/api/wxml/nodesRef.ts +49 -0
- package/src/api/wxml/selectorQuery.ts +2 -48
- package/src/api/media/image/getImageInfo.js +0 -74
- package/src/api/media/image/previewImage.js +0 -98
package/src/api/storage/index.ts
CHANGED
|
@@ -2,8 +2,22 @@ import Taro from '@tarojs/api'
|
|
|
2
2
|
import { shouldBeObject, getParameterError, temporarilyNotSupport } from '../utils'
|
|
3
3
|
import { MethodHandler } from '../utils/handler'
|
|
4
4
|
|
|
5
|
+
function getItem (key) {
|
|
6
|
+
let item
|
|
7
|
+
try {
|
|
8
|
+
item = JSON.parse(localStorage.getItem(key) || '')
|
|
9
|
+
} catch (e) {}
|
|
10
|
+
|
|
11
|
+
// 只返回使用 Taro.setStorage API 存储的数据
|
|
12
|
+
if (item && typeof item === 'object' && item.hasOwnProperty('data')) {
|
|
13
|
+
return { result: true, data: item.data }
|
|
14
|
+
} else {
|
|
15
|
+
return { result: false }
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
5
19
|
// 数据缓存
|
|
6
|
-
const setStorageSync: typeof Taro.setStorageSync = (key, data = '') => {
|
|
20
|
+
export const setStorageSync: typeof Taro.setStorageSync = (key, data = '') => {
|
|
7
21
|
if (typeof key !== 'string') {
|
|
8
22
|
console.error(getParameterError({
|
|
9
23
|
name: 'setStorage',
|
|
@@ -24,7 +38,7 @@ const setStorageSync: typeof Taro.setStorageSync = (key, data = '') => {
|
|
|
24
38
|
localStorage.setItem(key, JSON.stringify(obj))
|
|
25
39
|
}
|
|
26
40
|
|
|
27
|
-
const setStorage: typeof Taro.setStorage = (options) => {
|
|
41
|
+
export const setStorage: typeof Taro.setStorage = (options) => {
|
|
28
42
|
// options must be an Object
|
|
29
43
|
const isObject = shouldBeObject(options)
|
|
30
44
|
if (!isObject.flag) {
|
|
@@ -50,17 +64,31 @@ const setStorage: typeof Taro.setStorage = (options) => {
|
|
|
50
64
|
return handle.success()
|
|
51
65
|
}
|
|
52
66
|
|
|
53
|
-
const
|
|
67
|
+
export const revokeBufferURL = temporarilyNotSupport('revokeBufferURL')
|
|
68
|
+
|
|
69
|
+
export const removeStorageSync: typeof Taro.removeStorageSync = (key: string) => {
|
|
70
|
+
if (typeof key !== 'string') {
|
|
71
|
+
console.error(getParameterError({
|
|
72
|
+
name: 'removeStorage',
|
|
73
|
+
correct: 'String',
|
|
74
|
+
wrong: key
|
|
75
|
+
}))
|
|
76
|
+
return
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
localStorage.removeItem(key)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export const removeStorage: typeof Taro.removeStorage = (options: Taro.removeStorage.Option) => {
|
|
54
83
|
// options must be an Object
|
|
55
84
|
const isObject = shouldBeObject(options)
|
|
56
85
|
if (!isObject.flag) {
|
|
57
|
-
const res = { errMsg: `
|
|
86
|
+
const res = { errMsg: `removeStorage:fail ${isObject.msg}` }
|
|
58
87
|
console.error(res.errMsg)
|
|
59
88
|
return Promise.reject(res)
|
|
60
89
|
}
|
|
61
|
-
|
|
62
90
|
const { key, success, fail, complete } = options
|
|
63
|
-
const handle = new MethodHandler
|
|
91
|
+
const handle = new MethodHandler({ name: 'removeStorage', success, fail, complete })
|
|
64
92
|
|
|
65
93
|
if (typeof key !== 'string') {
|
|
66
94
|
return handle.fail({
|
|
@@ -72,17 +100,11 @@ const getStorage: typeof Taro.getStorage = <T>(options) => {
|
|
|
72
100
|
})
|
|
73
101
|
}
|
|
74
102
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
return handle.success({ data })
|
|
78
|
-
} else {
|
|
79
|
-
return handle.fail({
|
|
80
|
-
errMsg: 'data not found'
|
|
81
|
-
})
|
|
82
|
-
}
|
|
103
|
+
removeStorageSync(key)
|
|
104
|
+
return handle.success()
|
|
83
105
|
}
|
|
84
106
|
|
|
85
|
-
const getStorageSync: typeof Taro.getStorageSync = (key) => {
|
|
107
|
+
export const getStorageSync: typeof Taro.getStorageSync = (key) => {
|
|
86
108
|
if (typeof key !== 'string') {
|
|
87
109
|
console.error(getParameterError({
|
|
88
110
|
name: 'getStorageSync',
|
|
@@ -98,21 +120,7 @@ const getStorageSync: typeof Taro.getStorageSync = (key) => {
|
|
|
98
120
|
return ''
|
|
99
121
|
}
|
|
100
122
|
|
|
101
|
-
|
|
102
|
-
let item
|
|
103
|
-
try {
|
|
104
|
-
item = JSON.parse(localStorage.getItem(key) || '')
|
|
105
|
-
} catch (e) {}
|
|
106
|
-
|
|
107
|
-
// 只返回使用 Taro.setStorage API 存储的数据
|
|
108
|
-
if (item && typeof item === 'object' && item.hasOwnProperty('data')) {
|
|
109
|
-
return { result: true, data: item.data }
|
|
110
|
-
} else {
|
|
111
|
-
return { result: false }
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
const getStorageInfoSync: typeof Taro.getStorageInfoSync = () => {
|
|
123
|
+
export const getStorageInfoSync: typeof Taro.getStorageInfoSync = () => {
|
|
116
124
|
const res: Taro.getStorageInfoSync.Option = {
|
|
117
125
|
keys: Object.keys(localStorage),
|
|
118
126
|
limitSize: NaN,
|
|
@@ -121,34 +129,22 @@ const getStorageInfoSync: typeof Taro.getStorageInfoSync = () => {
|
|
|
121
129
|
return res
|
|
122
130
|
}
|
|
123
131
|
|
|
124
|
-
const getStorageInfo: typeof Taro.getStorageInfo = ({ success, fail, complete } = {}) => {
|
|
132
|
+
export const getStorageInfo: typeof Taro.getStorageInfo = ({ success, fail, complete } = {}) => {
|
|
125
133
|
const handle = new MethodHandler<Taro.getStorageInfo.SuccessCallbackOption>({ name: 'getStorageInfo', success, fail, complete })
|
|
126
134
|
return handle.success(getStorageInfoSync())
|
|
127
135
|
}
|
|
128
136
|
|
|
129
|
-
const
|
|
130
|
-
if (typeof key !== 'string') {
|
|
131
|
-
console.error(getParameterError({
|
|
132
|
-
name: 'removeStorage',
|
|
133
|
-
correct: 'String',
|
|
134
|
-
wrong: key
|
|
135
|
-
}))
|
|
136
|
-
return
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
localStorage.removeItem(key)
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
const removeStorage: typeof Taro.removeStorage = (options: Taro.removeStorage.Option) => {
|
|
137
|
+
export const getStorage: typeof Taro.getStorage = <T>(options) => {
|
|
143
138
|
// options must be an Object
|
|
144
139
|
const isObject = shouldBeObject(options)
|
|
145
140
|
if (!isObject.flag) {
|
|
146
|
-
const res = { errMsg: `
|
|
141
|
+
const res = { errMsg: `getStorage:fail ${isObject.msg}` }
|
|
147
142
|
console.error(res.errMsg)
|
|
148
143
|
return Promise.reject(res)
|
|
149
144
|
}
|
|
145
|
+
|
|
150
146
|
const { key, success, fail, complete } = options
|
|
151
|
-
const handle = new MethodHandler({ name: '
|
|
147
|
+
const handle = new MethodHandler<Taro.getStorage.SuccessCallbackResult<T>>({ name: 'getStorage', success, fail, complete })
|
|
152
148
|
|
|
153
149
|
if (typeof key !== 'string') {
|
|
154
150
|
return handle.fail({
|
|
@@ -160,34 +156,26 @@ const removeStorage: typeof Taro.removeStorage = (options: Taro.removeStorage.Op
|
|
|
160
156
|
})
|
|
161
157
|
}
|
|
162
158
|
|
|
163
|
-
|
|
164
|
-
|
|
159
|
+
const { result, data } = getItem(key)
|
|
160
|
+
if (result) {
|
|
161
|
+
return handle.success({ data })
|
|
162
|
+
} else {
|
|
163
|
+
return handle.fail({
|
|
164
|
+
errMsg: 'data not found'
|
|
165
|
+
})
|
|
166
|
+
}
|
|
165
167
|
}
|
|
166
168
|
|
|
167
|
-
const
|
|
168
|
-
const handle = new MethodHandler({ name: 'clearStorage', success, fail, complete })
|
|
169
|
-
localStorage.clear()
|
|
170
|
-
return handle.success()
|
|
171
|
-
}
|
|
169
|
+
export const createBufferURL = temporarilyNotSupport('createBufferURL')
|
|
172
170
|
|
|
173
|
-
const clearStorageSync: typeof Taro.clearStorageSync = () => {
|
|
174
|
-
|
|
171
|
+
export const clearStorageSync: typeof Taro.clearStorageSync = () => {
|
|
172
|
+
localStorage.clear()
|
|
175
173
|
}
|
|
176
174
|
|
|
177
|
-
const
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
setStorage,
|
|
182
|
-
revokeBufferURL,
|
|
183
|
-
removeStorageSync,
|
|
184
|
-
removeStorage,
|
|
185
|
-
getStorageSync,
|
|
186
|
-
getStorageInfoSync,
|
|
187
|
-
getStorageInfo,
|
|
188
|
-
getStorage,
|
|
189
|
-
clearStorageSync,
|
|
190
|
-
clearStorage
|
|
175
|
+
export const clearStorage: typeof Taro.clearStorage = ({ success, fail, complete } = {}) => {
|
|
176
|
+
const handle = new MethodHandler({ name: 'clearStorage', success, fail, complete })
|
|
177
|
+
clearStorageSync()
|
|
178
|
+
return handle.success()
|
|
191
179
|
}
|
|
192
180
|
|
|
193
181
|
export * from './background-fetch'
|
package/src/api/taro.ts
CHANGED
|
@@ -18,22 +18,7 @@ const {
|
|
|
18
18
|
options,
|
|
19
19
|
eventCenter,
|
|
20
20
|
Events,
|
|
21
|
-
preload
|
|
22
|
-
useDidShow,
|
|
23
|
-
useDidHide,
|
|
24
|
-
usePullDownRefresh,
|
|
25
|
-
useReachBottom,
|
|
26
|
-
usePageScroll,
|
|
27
|
-
useResize,
|
|
28
|
-
useShareAppMessage,
|
|
29
|
-
useTabItemTap,
|
|
30
|
-
useTitleClick,
|
|
31
|
-
useOptionMenuClick,
|
|
32
|
-
usePullIntercept,
|
|
33
|
-
useShareTimeline,
|
|
34
|
-
useAddToFavorites,
|
|
35
|
-
useReady,
|
|
36
|
-
useRouter
|
|
21
|
+
preload
|
|
37
22
|
} = Taro as any
|
|
38
23
|
|
|
39
24
|
const taro: typeof Taro = {
|
|
@@ -57,22 +42,7 @@ const taro: typeof Taro = {
|
|
|
57
42
|
reLaunch,
|
|
58
43
|
redirectTo,
|
|
59
44
|
getCurrentPages,
|
|
60
|
-
switchTab
|
|
61
|
-
useDidShow,
|
|
62
|
-
useDidHide,
|
|
63
|
-
usePullDownRefresh,
|
|
64
|
-
useReachBottom,
|
|
65
|
-
usePageScroll,
|
|
66
|
-
useResize,
|
|
67
|
-
useShareAppMessage,
|
|
68
|
-
useTabItemTap,
|
|
69
|
-
useTitleClick,
|
|
70
|
-
useOptionMenuClick,
|
|
71
|
-
usePullIntercept,
|
|
72
|
-
useShareTimeline,
|
|
73
|
-
useAddToFavorites,
|
|
74
|
-
useReady,
|
|
75
|
-
useRouter
|
|
45
|
+
switchTab
|
|
76
46
|
}
|
|
77
47
|
|
|
78
48
|
const initPxTransform = getInitPxTransform(taro)
|
|
@@ -84,6 +54,7 @@ const pxTransform = function (size) {
|
|
|
84
54
|
const { designWidth } = taro.config
|
|
85
55
|
return Math.ceil((((parseInt(size, 10) / 40) * 640) / designWidth) * 10000) / 10000 + 'rem'
|
|
86
56
|
}
|
|
57
|
+
|
|
87
58
|
const canIUseWebp = function () {
|
|
88
59
|
const canvas = document.createElement('canvas')
|
|
89
60
|
return canvas.toDataURL('image/webp').indexOf('data:image/webp') === 0
|
|
@@ -114,20 +85,5 @@ export {
|
|
|
114
85
|
pxTransform,
|
|
115
86
|
canIUseWebp,
|
|
116
87
|
history,
|
|
117
|
-
createRouter
|
|
118
|
-
useDidShow,
|
|
119
|
-
useDidHide,
|
|
120
|
-
usePullDownRefresh,
|
|
121
|
-
useReachBottom,
|
|
122
|
-
usePageScroll,
|
|
123
|
-
useResize,
|
|
124
|
-
useShareAppMessage,
|
|
125
|
-
useTabItemTap,
|
|
126
|
-
useTitleClick,
|
|
127
|
-
useOptionMenuClick,
|
|
128
|
-
usePullIntercept,
|
|
129
|
-
useShareTimeline,
|
|
130
|
-
useAddToFavorites,
|
|
131
|
-
useReady,
|
|
132
|
-
useRouter
|
|
88
|
+
createRouter
|
|
133
89
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import Taro from '@tarojs/api'
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* H5 下的 styleSheet 操作
|
|
3
5
|
* @author leeenx
|
|
@@ -48,15 +50,15 @@ if ($detect.style['animation-name'] === 'standard') {
|
|
|
48
50
|
TRANSFORM = 'transform'
|
|
49
51
|
} else if ($detect.style['-webkit-animation-name'] === 'webkit') {
|
|
50
52
|
// webkit 前缀
|
|
51
|
-
TRANSITION_END = '
|
|
53
|
+
TRANSITION_END = 'webkitTransitionEnd'
|
|
52
54
|
TRANSFORM = '-webkit-transform'
|
|
53
55
|
} else if ($detect.style['-moz-animation-name'] === 'moz') {
|
|
54
|
-
//
|
|
55
|
-
TRANSITION_END = '
|
|
56
|
+
// moz 前缀
|
|
57
|
+
TRANSITION_END = 'mozTransitionEnd'
|
|
56
58
|
TRANSFORM = '-moz-transform'
|
|
57
59
|
} else if ($detect.style['-ms-animation-name'] === 'ms') {
|
|
58
|
-
//
|
|
59
|
-
TRANSITION_END = '
|
|
60
|
+
// ms 前缀
|
|
61
|
+
TRANSITION_END = 'msTransitionEnd'
|
|
60
62
|
TRANSFORM = '-ms-transform'
|
|
61
63
|
}
|
|
62
64
|
|
|
@@ -69,8 +71,7 @@ interface IAnimationAttr {
|
|
|
69
71
|
transformOrigin: string
|
|
70
72
|
}
|
|
71
73
|
|
|
72
|
-
|
|
73
|
-
class Animation {
|
|
74
|
+
class Animation implements Taro.Animation {
|
|
74
75
|
unit: string
|
|
75
76
|
id: number
|
|
76
77
|
DEFAULT: IAnimationAttr
|
|
@@ -82,7 +83,7 @@ class Animation {
|
|
|
82
83
|
timingFunction = 'linear',
|
|
83
84
|
transformOrigin = '50% 50% 0',
|
|
84
85
|
unit = 'px'
|
|
85
|
-
} = {}
|
|
86
|
+
}: Taro.createAnimation.Option = {}
|
|
86
87
|
) {
|
|
87
88
|
// 默认值
|
|
88
89
|
this.setDefault(duration, delay, timingFunction, transformOrigin)
|
|
@@ -108,7 +109,7 @@ class Animation {
|
|
|
108
109
|
const animStepsCount = this.animationMap[`${animName}__${animIndex}`]
|
|
109
110
|
const animStepsMaxIndex = animStepsCount - 1
|
|
110
111
|
if (stepIndex < animStepsMaxIndex) {
|
|
111
|
-
// 播放下一个关键帧(因为
|
|
112
|
+
// 播放下一个关键帧(因为 nerv 和 react 有差异所以 animation & data-animation 都需要写)
|
|
112
113
|
target.setAttribute(animAttr, `${animName}__${animIndex}--${stepIndex + 1}`)
|
|
113
114
|
if (animAttr === 'animation') {
|
|
114
115
|
// Nerv 环境,animation & data-animation 双重保险
|
|
@@ -142,23 +143,28 @@ class Animation {
|
|
|
142
143
|
animationMap = {}
|
|
143
144
|
// animationMap 的长度
|
|
144
145
|
animationMapCount = 0
|
|
145
|
-
|
|
146
|
-
|
|
146
|
+
|
|
147
|
+
matrix (a: number, b: number, c: number, d: number, tx: number, ty: number) {
|
|
148
|
+
this.transform.push(`matrix(${a}, ${b}, ${c}, ${d}, ${tx}, ${ty})`)
|
|
147
149
|
return this
|
|
148
150
|
}
|
|
149
151
|
|
|
150
|
-
matrix3d (a1, b1, c1, d1, a2, b2, c2, d2, a3, b3, c3, d3, a4, b4, c4, d4) {
|
|
152
|
+
matrix3d (a1: number, b1: number, c1: number, d1: number, a2: number, b2: number, c2: number, d2: number, a3: number, b3: number, c3: number, d3: number, a4: number, b4: number, c4: number, d4: number) {
|
|
151
153
|
this.transform.push(`matrix3d(${a1}, ${b1}, ${c1}, ${d1}, ${a2}, ${b2}, ${c2}, ${d2}, ${a3}, ${b3}, ${c3}, ${d3}, ${a4}, ${b4}, ${c4}, ${d4})`)
|
|
152
154
|
return this
|
|
153
155
|
}
|
|
154
156
|
|
|
155
|
-
rotate (angle) {
|
|
157
|
+
rotate (angle: number) {
|
|
156
158
|
this.transform.push(`rotate(${angle}deg)`)
|
|
157
159
|
return this
|
|
158
160
|
}
|
|
159
161
|
|
|
160
|
-
rotate3d (x, y, z, angle) {
|
|
161
|
-
|
|
162
|
+
rotate3d (x: number, y?: number, z?: number, angle?: number) {
|
|
163
|
+
if (typeof y !== 'number') {
|
|
164
|
+
this.transform.push(`rotate3d(${x})`)
|
|
165
|
+
} else {
|
|
166
|
+
this.transform.push(`rotate3d(${x}, ${y || 0}, ${z || 0}, ${angle || 0}deg)`)
|
|
167
|
+
}
|
|
162
168
|
return this
|
|
163
169
|
}
|
|
164
170
|
|
|
@@ -318,7 +324,7 @@ class Animation {
|
|
|
318
324
|
// 清空 rules 和 transform
|
|
319
325
|
this.rules = []
|
|
320
326
|
this.transform = [`${TRANSFORM}:`]
|
|
321
|
-
return this
|
|
327
|
+
return this as Taro.Animation
|
|
322
328
|
}
|
|
323
329
|
|
|
324
330
|
// 创建底层数据
|
|
@@ -341,13 +347,11 @@ class Animation {
|
|
|
341
347
|
|
|
342
348
|
// 动画数据产出
|
|
343
349
|
export () {
|
|
344
|
-
return this.createAnimationData()
|
|
350
|
+
return this.createAnimationData() as unknown as ReturnType<Taro.Animation['export']>
|
|
345
351
|
}
|
|
346
352
|
}
|
|
347
353
|
|
|
348
354
|
// h5 的 createAnimation
|
|
349
|
-
|
|
350
|
-
return new Animation(
|
|
355
|
+
export const createAnimation: typeof Taro.createAnimation = (option) => {
|
|
356
|
+
return new Animation(option)
|
|
351
357
|
}
|
|
352
|
-
|
|
353
|
-
export { createAnimation }
|
|
@@ -24,14 +24,15 @@ const toast = new Toast()
|
|
|
24
24
|
const modal = new Modal()
|
|
25
25
|
const actionSheet = new ActionSheet()
|
|
26
26
|
|
|
27
|
-
const showToast: typeof Taro.showToast = (options = {
|
|
28
|
-
title: '',
|
|
29
|
-
icon: 'success',
|
|
30
|
-
image: '',
|
|
31
|
-
duration: 1500,
|
|
32
|
-
mask: false
|
|
33
|
-
}) => {
|
|
27
|
+
const showToast: typeof Taro.showToast = (options = { title: '' }) => {
|
|
34
28
|
init(document)
|
|
29
|
+
options = Object.assign({
|
|
30
|
+
title: '',
|
|
31
|
+
icon: 'success',
|
|
32
|
+
image: '',
|
|
33
|
+
duration: 1500,
|
|
34
|
+
mask: false
|
|
35
|
+
}, options)
|
|
35
36
|
const { success, fail, complete } = options
|
|
36
37
|
const handle = new MethodHandler({ name: 'showToast', success, fail, complete })
|
|
37
38
|
|
|
@@ -75,11 +76,12 @@ const hideToast: typeof Taro.hideToast = ({ success, fail, complete } = {}) => {
|
|
|
75
76
|
return handle.success()
|
|
76
77
|
}
|
|
77
78
|
|
|
78
|
-
const showLoading: typeof Taro.showLoading = (options = {
|
|
79
|
-
title: '',
|
|
80
|
-
mask: false
|
|
81
|
-
}) => {
|
|
79
|
+
const showLoading: typeof Taro.showLoading = (options = { title: '' }) => {
|
|
82
80
|
init(document)
|
|
81
|
+
options = Object.assign({
|
|
82
|
+
title: '',
|
|
83
|
+
mask: false
|
|
84
|
+
}, options)
|
|
83
85
|
const { success, fail, complete } = options
|
|
84
86
|
const handle = new MethodHandler({ name: 'showLoading', success, fail, complete })
|
|
85
87
|
|
|
@@ -119,16 +121,17 @@ const hideLoading: typeof Taro.hideLoading = ({ success, fail, complete } = {})
|
|
|
119
121
|
return handle.success()
|
|
120
122
|
}
|
|
121
123
|
|
|
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
|
-
}) => {
|
|
124
|
+
const showModal: typeof Taro.showModal = async (options = {}) => {
|
|
131
125
|
init(document)
|
|
126
|
+
options = Object.assign({
|
|
127
|
+
title: '',
|
|
128
|
+
content: '',
|
|
129
|
+
showCancel: true,
|
|
130
|
+
cancelText: '取消',
|
|
131
|
+
cancelColor: '#000000',
|
|
132
|
+
confirmText: '确定',
|
|
133
|
+
confirmColor: '#3CC51F'
|
|
134
|
+
}, options)
|
|
132
135
|
const { success, fail, complete } = options
|
|
133
136
|
const handle = new MethodHandler({ name: 'showModal', success, fail, complete })
|
|
134
137
|
|
|
@@ -220,11 +223,12 @@ function hideModal () {
|
|
|
220
223
|
modal.hide()
|
|
221
224
|
}
|
|
222
225
|
|
|
223
|
-
const showActionSheet: typeof Taro.showActionSheet = async (options = {
|
|
224
|
-
itemColor: '#000000',
|
|
225
|
-
itemList: []
|
|
226
|
-
}) => {
|
|
226
|
+
const showActionSheet: typeof Taro.showActionSheet = async (options = { itemList: [] }) => {
|
|
227
227
|
init(document)
|
|
228
|
+
options = Object.assign({
|
|
229
|
+
itemColor: '#000000',
|
|
230
|
+
itemList: []
|
|
231
|
+
}, options)
|
|
228
232
|
const { success, fail, complete } = options
|
|
229
233
|
const handle = new MethodHandler<Taro.showActionSheet.SuccessCallbackResult>({ name: 'showActionSheet', success, fail, complete })
|
|
230
234
|
|
|
@@ -3,7 +3,7 @@ import { MethodHandler } from '../utils/handler'
|
|
|
3
3
|
/**
|
|
4
4
|
* 开始下拉刷新。调用后触发下拉刷新动画,效果与用户手动下拉刷新一致。
|
|
5
5
|
*/
|
|
6
|
-
const startPullDownRefresh: typeof Taro.startPullDownRefresh = function ({ success, fail, complete } = {}) {
|
|
6
|
+
export const startPullDownRefresh: typeof Taro.startPullDownRefresh = function ({ success, fail, complete } = {}) {
|
|
7
7
|
const handle = new MethodHandler({ name: 'startPullDownRefresh', success, fail, complete })
|
|
8
8
|
return new Promise((resolve, reject) => {
|
|
9
9
|
Taro.eventCenter.trigger('__taroStartPullDownRefresh', {
|
|
@@ -16,7 +16,7 @@ const startPullDownRefresh: typeof Taro.startPullDownRefresh = function ({ succe
|
|
|
16
16
|
/**
|
|
17
17
|
* 停止当前页面下拉刷新。
|
|
18
18
|
*/
|
|
19
|
-
const stopPullDownRefresh: typeof Taro.stopPullDownRefresh = function ({ success, fail, complete } = {}) {
|
|
19
|
+
export const stopPullDownRefresh: typeof Taro.stopPullDownRefresh = function ({ success, fail, complete } = {}) {
|
|
20
20
|
const handle = new MethodHandler({ name: 'stopPullDownRefresh', success, fail, complete })
|
|
21
21
|
return new Promise((resolve, reject) => {
|
|
22
22
|
Taro.eventCenter.trigger('__taroStopPullDownRefresh', {
|
|
@@ -25,8 +25,3 @@ const stopPullDownRefresh: typeof Taro.stopPullDownRefresh = function ({ success
|
|
|
25
25
|
})
|
|
26
26
|
})
|
|
27
27
|
}
|
|
28
|
-
|
|
29
|
-
export {
|
|
30
|
-
startPullDownRefresh,
|
|
31
|
-
stopPullDownRefresh
|
|
32
|
-
}
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import Taro from '@tarojs/api'
|
|
2
|
+
import { Current } from '@tarojs/runtime'
|
|
2
3
|
|
|
3
4
|
import { MethodHandler } from '../../utils/handler'
|
|
4
5
|
import { getTimingFunc, easeInOut } from '../../utils'
|
|
5
6
|
|
|
6
|
-
let
|
|
7
|
-
let timer: NodeJS.Timeout
|
|
7
|
+
let timer: number
|
|
8
8
|
const FRAME_DURATION = 17
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* 将页面滚动到目标位置
|
|
12
12
|
*/
|
|
13
13
|
export const pageScrollTo: typeof Taro.pageScrollTo = ({ scrollTop, selector = '', duration = 300, success, fail, complete }) => {
|
|
14
|
+
let scrollFunc
|
|
14
15
|
const handle = new MethodHandler({ name: 'pageScrollTo', success, fail, complete })
|
|
15
16
|
return new Promise((resolve, reject) => {
|
|
16
17
|
try {
|
|
@@ -20,17 +21,14 @@ export const pageScrollTo: typeof Taro.pageScrollTo = ({ scrollTop, selector = '
|
|
|
20
21
|
}, reject)
|
|
21
22
|
}
|
|
22
23
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
// 有设置tabbar
|
|
29
|
-
el = document.querySelector('.taro-tabbar__panel') || window
|
|
30
|
-
}
|
|
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
|
|
31
29
|
|
|
32
30
|
if (!scrollFunc) {
|
|
33
|
-
if (el
|
|
31
|
+
if (!el) {
|
|
34
32
|
scrollFunc = pos => {
|
|
35
33
|
if (pos === undefined) {
|
|
36
34
|
return window.pageYOffset
|
package/src/api/utils/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* eslint-disable prefer-promise-reject-errors */
|
|
2
2
|
import { Current, container, SERVICE_IDENTIFIER, IHooks, TaroElement } from '@tarojs/runtime'
|
|
3
3
|
|
|
4
|
-
function shouldBeObject (target: unknown) {
|
|
4
|
+
export function shouldBeObject (target: unknown) {
|
|
5
5
|
if (target && typeof target === 'object') return { flag: true }
|
|
6
6
|
return {
|
|
7
7
|
flag: false,
|
|
@@ -43,7 +43,7 @@ interface IParameterErrorParam {
|
|
|
43
43
|
correct?: string
|
|
44
44
|
wrong?: unknown
|
|
45
45
|
}
|
|
46
|
-
function getParameterError ({ name = '', para, correct, wrong }: IParameterErrorParam) {
|
|
46
|
+
export function getParameterError ({ name = '', para, correct, wrong }: IParameterErrorParam) {
|
|
47
47
|
const parameter = para ? `parameter.${para}` : 'parameter'
|
|
48
48
|
const errorType = upperCaseFirstLetter(wrong === null ? 'Null' : typeof wrong)
|
|
49
49
|
if (name) {
|
|
@@ -59,7 +59,7 @@ function upperCaseFirstLetter (string) {
|
|
|
59
59
|
return string
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
function inlineStyle (style) {
|
|
62
|
+
export function inlineStyle (style) {
|
|
63
63
|
let res = ''
|
|
64
64
|
for (const attr in style) res += `${attr}: ${style[attr]};`
|
|
65
65
|
if (res.indexOf('display: flex;') >= 0) res += 'display: -webkit-box;display: -webkit-flex;'
|
|
@@ -68,16 +68,12 @@ function inlineStyle (style) {
|
|
|
68
68
|
return res
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
function setTransform (el, val) {
|
|
71
|
+
export function setTransform (el, val) {
|
|
72
72
|
el.style.webkitTransform = val
|
|
73
73
|
el.style.transform = val
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
function
|
|
77
|
-
return typeof obj === 'function'
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
function serializeParams (params) {
|
|
76
|
+
export function serializeParams (params) {
|
|
81
77
|
if (!params) {
|
|
82
78
|
return ''
|
|
83
79
|
}
|
|
@@ -89,7 +85,7 @@ function serializeParams (params) {
|
|
|
89
85
|
.join('&')
|
|
90
86
|
}
|
|
91
87
|
|
|
92
|
-
function temporarilyNotSupport (apiName) {
|
|
88
|
+
export function temporarilyNotSupport (apiName) {
|
|
93
89
|
return () => {
|
|
94
90
|
const errMsg = `暂时不支持 API ${apiName}`
|
|
95
91
|
console.error(errMsg)
|
|
@@ -99,7 +95,7 @@ function temporarilyNotSupport (apiName) {
|
|
|
99
95
|
}
|
|
100
96
|
}
|
|
101
97
|
|
|
102
|
-
function weixinCorpSupport (apiName) {
|
|
98
|
+
export function weixinCorpSupport (apiName) {
|
|
103
99
|
return () => {
|
|
104
100
|
const errMsg = `h5端仅在微信公众号中支持 API ${apiName}`
|
|
105
101
|
console.error(errMsg)
|
|
@@ -109,7 +105,7 @@ function weixinCorpSupport (apiName) {
|
|
|
109
105
|
}
|
|
110
106
|
}
|
|
111
107
|
|
|
112
|
-
function permanentlyNotSupport (apiName) {
|
|
108
|
+
export function permanentlyNotSupport (apiName) {
|
|
113
109
|
return () => {
|
|
114
110
|
const errMsg = `不支持 API ${apiName}`
|
|
115
111
|
console.error(errMsg)
|
|
@@ -119,13 +115,17 @@ function permanentlyNotSupport (apiName) {
|
|
|
119
115
|
}
|
|
120
116
|
}
|
|
121
117
|
|
|
118
|
+
export function isFunction (obj) {
|
|
119
|
+
return typeof obj === 'function'
|
|
120
|
+
}
|
|
121
|
+
|
|
122
122
|
const VALID_COLOR_REG = /^#[0-9a-fA-F]{6}$/
|
|
123
123
|
|
|
124
|
-
const isValidColor = (color) => {
|
|
124
|
+
export const isValidColor = (color) => {
|
|
125
125
|
return VALID_COLOR_REG.test(color)
|
|
126
126
|
}
|
|
127
127
|
|
|
128
|
-
function processOpenApi (apiName: string, defaultOptions?: Record<string, unknown>, formatResult = res => res, formatParams = options => options) {
|
|
128
|
+
export function processOpenApi (apiName: string, defaultOptions?: Record<string, unknown>, formatResult = res => res, formatParams = options => options) {
|
|
129
129
|
// @ts-ignore
|
|
130
130
|
if (!window.wx) {
|
|
131
131
|
return weixinCorpSupport(apiName)
|
|
@@ -154,11 +154,11 @@ function processOpenApi (apiName: string, defaultOptions?: Record<string, unknow
|
|
|
154
154
|
|
|
155
155
|
/**
|
|
156
156
|
* ease-in-out的函数
|
|
157
|
-
* @param
|
|
157
|
+
* @param t 0-1的数字
|
|
158
158
|
*/
|
|
159
|
-
const easeInOut = t => t < 0.5 ? 4 * t * t * t : (t - 1) * (2 * t - 2) * (2 * t - 2) + 1
|
|
159
|
+
export const easeInOut = (t: number) => t < 0.5 ? 4 * t * t * t : (t - 1) * (2 * t - 2) * (2 * t - 2) + 1
|
|
160
160
|
|
|
161
|
-
const getTimingFunc = (easeFunc, frameCnt) => {
|
|
161
|
+
export const getTimingFunc = (easeFunc, frameCnt) => {
|
|
162
162
|
return x => {
|
|
163
163
|
if (frameCnt <= 1) {
|
|
164
164
|
return easeFunc(1)
|
|
@@ -167,19 +167,3 @@ const getTimingFunc = (easeFunc, frameCnt) => {
|
|
|
167
167
|
return easeFunc(t)
|
|
168
168
|
}
|
|
169
169
|
}
|
|
170
|
-
|
|
171
|
-
export {
|
|
172
|
-
shouldBeObject,
|
|
173
|
-
getParameterError,
|
|
174
|
-
inlineStyle,
|
|
175
|
-
setTransform,
|
|
176
|
-
serializeParams,
|
|
177
|
-
temporarilyNotSupport,
|
|
178
|
-
weixinCorpSupport,
|
|
179
|
-
permanentlyNotSupport,
|
|
180
|
-
isValidColor,
|
|
181
|
-
isFunction,
|
|
182
|
-
processOpenApi,
|
|
183
|
-
easeInOut,
|
|
184
|
-
getTimingFunc
|
|
185
|
-
}
|