@tarojs/taro-h5 3.3.18 → 3.3.19
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/api/ad/index.js +3 -0
- package/dist/api/ai/facial.js +4 -0
- package/dist/api/ai/index.js +2 -0
- package/dist/api/ai/visual.js +2 -0
- package/dist/api/alipay/index.js +2 -0
- package/dist/api/base/crypto.js +2 -0
- package/dist/api/base/debug.js +4 -0
- package/dist/api/base/index.js +16 -0
- package/dist/api/base/performance.js +3 -0
- package/dist/api/base/system/index.js +2 -0
- package/dist/api/base/system/info.js +56 -0
- package/dist/api/base/system/network.js +52 -0
- package/dist/api/base/update.js +3 -0
- package/dist/api/base/weapp/app-event.js +17 -0
- package/dist/api/base/weapp/life-cycle.js +3 -0
- package/dist/api/canvas/CanvasContext.js +182 -0
- package/dist/api/canvas/canvasGetImageData.js +21 -0
- package/dist/api/canvas/canvasPutImageData.js +17 -0
- package/dist/api/canvas/canvasToTempFilePath.js +18 -0
- package/dist/api/canvas/createCanvasContext.js +13 -0
- package/dist/api/canvas/index.js +7 -0
- package/dist/api/cloud/index.js +14 -0
- package/dist/api/data-analysis/index.js +5 -0
- package/dist/api/device/accelerometer.js +71 -0
- package/dist/api/device/accessibility.js +2 -0
- package/dist/api/device/battery.js +3 -0
- package/dist/api/device/bluetooth-ble.js +17 -0
- package/dist/api/device/bluetooth-peripheral.js +4 -0
- package/dist/api/device/bluetooth.js +14 -0
- package/dist/api/device/calendar.js +3 -0
- package/dist/api/device/clipboard.js +48 -0
- package/dist/api/device/compass.js +52 -0
- package/dist/api/device/contact.js +3 -0
- package/dist/api/device/crypto.js +2 -0
- package/dist/api/device/gyroscope.js +5 -0
- package/dist/api/device/iBeacon.js +8 -0
- package/dist/api/device/index.js +22 -0
- package/dist/api/device/keyboard.js +5 -0
- package/dist/api/device/memory.js +3 -0
- package/dist/api/device/motion.js +69 -0
- package/dist/api/device/nfc.js +8 -0
- package/dist/api/device/phone.js +23 -0
- package/dist/api/device/scan.js +5 -0
- package/dist/api/device/screen.js +7 -0
- package/dist/api/device/vibrate.js +29 -0
- package/dist/api/device/wifi.js +11 -0
- package/dist/api/ext/index.js +3 -0
- package/dist/api/files/index.js +9 -0
- package/dist/api/framework/index.js +6 -0
- package/dist/api/index.js +24 -0
- package/dist/api/location/chooseLocation.js +88 -0
- package/dist/api/location/index.js +12 -0
- package/dist/api/location/style.css +79 -0
- package/dist/api/media/audio/index.js +81 -0
- package/dist/api/media/background-audio.js +10 -0
- package/dist/api/media/camera.js +2 -0
- package/dist/api/media/editor.js +17 -0
- package/dist/api/media/image/chooseImage.js +70 -0
- package/dist/api/media/image/getImageInfo.js +27 -0
- package/dist/api/media/image/index.js +8 -0
- package/dist/api/media/image/previewImage.js +78 -0
- package/dist/api/media/index.js +13 -0
- package/dist/api/media/live.js +3 -0
- package/dist/api/media/map.js +2 -0
- package/dist/api/media/media-recorder.js +2 -0
- package/dist/api/media/recorder.js +4 -0
- package/dist/api/media/video/index.js +65 -0
- package/dist/api/media/video-decoder.js +2 -0
- package/dist/api/media/video-processing.js +2 -0
- package/dist/api/media/voip.js +15 -0
- package/dist/api/navigate/index.js +5 -0
- package/dist/api/network/download.js +101 -0
- package/dist/api/network/index.js +7 -0
- package/dist/api/network/mdns.js +11 -0
- package/dist/api/network/request/index.js +123 -0
- package/dist/api/network/tcp.js +2 -0
- package/dist/api/network/udp.js +2 -0
- package/dist/api/network/upload.js +129 -0
- package/dist/api/network/utils.js +30 -0
- package/dist/api/network/websocket/index.js +65 -0
- package/dist/api/network/websocket/socketTask.js +61 -0
- package/dist/api/open-api/account.js +2 -0
- package/dist/api/open-api/address.js +2 -0
- package/dist/api/open-api/authorize.js +3 -0
- package/dist/api/open-api/card.js +3 -0
- package/dist/api/open-api/channels-live.js +7 -0
- package/dist/api/open-api/customer-service.js +2 -0
- package/dist/api/open-api/facial.js +5 -0
- package/dist/api/open-api/favorites.js +3 -0
- package/dist/api/open-api/group.js +2 -0
- package/dist/api/open-api/index.js +18 -0
- package/dist/api/open-api/invoice.js +3 -0
- package/dist/api/open-api/license-plate.js +2 -0
- package/dist/api/open-api/login.js +4 -0
- package/dist/api/open-api/red-package.js +2 -0
- package/dist/api/open-api/settings.js +3 -0
- package/dist/api/open-api/soter.js +4 -0
- package/dist/api/open-api/subscribe-message.js +2 -0
- package/dist/api/open-api/user-info.js +3 -0
- package/dist/api/open-api/werun.js +3 -0
- package/dist/api/payment/index.js +3 -0
- package/dist/api/route/index.js +1 -0
- package/dist/api/share/index.js +11 -0
- package/dist/api/storage/background-fetch.js +5 -0
- package/dist/api/storage/index.js +152 -0
- package/dist/api/swan/index.js +22 -0
- package/dist/api/taro.js +59 -0
- package/dist/api/ui/animation/index.js +255 -0
- package/dist/api/ui/background.js +3 -0
- package/dist/api/ui/custom-component.js +2 -0
- package/dist/api/ui/fonts.js +2 -0
- package/dist/api/ui/index.js +12 -0
- package/dist/api/ui/interaction/actionSheet.js +172 -0
- package/dist/api/ui/interaction/index.js +263 -0
- package/dist/api/ui/interaction/modal.js +185 -0
- package/dist/api/ui/interaction/toast.js +179 -0
- package/dist/api/ui/menu.js +2 -0
- package/dist/api/ui/navigation-bar/index.js +37 -0
- package/dist/api/ui/pull-down-refresh.js +20 -0
- package/dist/api/ui/scroll/index.js +80 -0
- package/dist/api/ui/sticky.js +2 -0
- package/dist/api/ui/tab-bar.js +250 -0
- package/dist/api/ui/window.js +22 -0
- package/dist/api/utils/handler.js +64 -0
- package/dist/api/utils/index.js +141 -0
- package/dist/api/worker/index.js +2 -0
- package/dist/api/wxml/index.js +6 -0
- package/dist/api/wxml/nodesRef.js +35 -0
- package/dist/api/wxml/selectorQuery.js +140 -0
- package/dist/index.cjs.js +4261 -5796
- package/dist/index.js +4 -9493
- package/dist/types/type.js +2 -0
- package/package.json +8 -11
- package/src/api/network/download.ts +5 -5
- package/src/api/network/upload.ts +5 -5
- package/src/api/network/websocket/index.ts +1 -1
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import Taro from '@tarojs/api';
|
|
2
|
+
import { MethodHandler } from '../utils/handler';
|
|
3
|
+
export const startPullDownRefresh = function ({ success, fail, complete } = {}) {
|
|
4
|
+
const handle = new MethodHandler({ name: 'startPullDownRefresh', success, fail, complete });
|
|
5
|
+
return new Promise((resolve, reject) => {
|
|
6
|
+
Taro.eventCenter.trigger('__taroStartPullDownRefresh', {
|
|
7
|
+
successHandler: (res = {}) => handle.success(res, resolve),
|
|
8
|
+
errorHandler: (res = {}) => handle.fail(res, reject)
|
|
9
|
+
});
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
export const stopPullDownRefresh = function ({ success, fail, complete } = {}) {
|
|
13
|
+
const handle = new MethodHandler({ name: 'stopPullDownRefresh', success, fail, complete });
|
|
14
|
+
return new Promise((resolve, reject) => {
|
|
15
|
+
Taro.eventCenter.trigger('__taroStopPullDownRefresh', {
|
|
16
|
+
successHandler: (res = {}) => handle.success(res, resolve),
|
|
17
|
+
errorHandler: (res = {}) => handle.fail(res, reject)
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { Current } from '@tarojs/runtime';
|
|
2
|
+
import { MethodHandler } from '../../utils/handler';
|
|
3
|
+
import { getTimingFunc, easeInOut } from '../../utils';
|
|
4
|
+
let timer;
|
|
5
|
+
const FRAME_DURATION = 17;
|
|
6
|
+
export const pageScrollTo = ({ scrollTop, selector = '', duration = 300, success, fail, complete }) => {
|
|
7
|
+
let scrollFunc;
|
|
8
|
+
const handle = new MethodHandler({ name: 'pageScrollTo', success, fail, complete });
|
|
9
|
+
return new Promise((resolve, reject) => {
|
|
10
|
+
var _a;
|
|
11
|
+
try {
|
|
12
|
+
if (scrollTop === undefined && !selector) {
|
|
13
|
+
return handle.fail({
|
|
14
|
+
errMsg: 'scrollTop" 或 "selector" 需要其之一'
|
|
15
|
+
}, reject);
|
|
16
|
+
}
|
|
17
|
+
const id = (_a = Current.page) === null || _a === void 0 ? void 0 : _a.path;
|
|
18
|
+
const el = (id
|
|
19
|
+
? document.getElementById(id)
|
|
20
|
+
: document.querySelector('.taro_page') ||
|
|
21
|
+
document.querySelector('.taro_router'));
|
|
22
|
+
if (!scrollFunc) {
|
|
23
|
+
if (!el) {
|
|
24
|
+
scrollFunc = pos => {
|
|
25
|
+
if (pos === undefined) {
|
|
26
|
+
return window.pageYOffset;
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
window.scrollTo(0, pos);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
scrollFunc = pos => {
|
|
35
|
+
if (pos === undefined) {
|
|
36
|
+
return el.scrollTop;
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
el.scrollTop = pos;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (scrollTop && selector) {
|
|
45
|
+
console.warn('"scrollTop" 或 "selector" 建议只设一个值,全部设置会忽略selector');
|
|
46
|
+
}
|
|
47
|
+
const from = scrollFunc();
|
|
48
|
+
let to;
|
|
49
|
+
if (typeof scrollTop === 'number') {
|
|
50
|
+
to = scrollTop;
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
const el = document.querySelector(selector);
|
|
54
|
+
to = (el === null || el === void 0 ? void 0 : el.offsetTop) || 0;
|
|
55
|
+
}
|
|
56
|
+
const delta = to - from;
|
|
57
|
+
const frameCnt = duration / FRAME_DURATION;
|
|
58
|
+
const easeFunc = getTimingFunc(easeInOut, frameCnt);
|
|
59
|
+
const scroll = (frame = 0) => {
|
|
60
|
+
const dest = from + delta * easeFunc(frame);
|
|
61
|
+
scrollFunc(dest);
|
|
62
|
+
if (frame < frameCnt) {
|
|
63
|
+
timer && clearTimeout(timer);
|
|
64
|
+
timer = setTimeout(() => {
|
|
65
|
+
scroll(frame + 1);
|
|
66
|
+
}, FRAME_DURATION);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
return handle.success({}, resolve);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
scroll();
|
|
73
|
+
}
|
|
74
|
+
catch (e) {
|
|
75
|
+
return handle.fail({
|
|
76
|
+
errMsg: e.message
|
|
77
|
+
}, reject);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
};
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import Taro from '@tarojs/api';
|
|
2
|
+
import { shouldBeObject, getParameterError, isValidColor } from '../utils';
|
|
3
|
+
import { MethodHandler } from '../utils/handler';
|
|
4
|
+
let tabConf;
|
|
5
|
+
export function initTabBarApis(config = {}) {
|
|
6
|
+
tabConf = config.tabBar;
|
|
7
|
+
}
|
|
8
|
+
export const showTabBarRedDot = (options) => {
|
|
9
|
+
const isObject = shouldBeObject(options);
|
|
10
|
+
if (!isObject.flag) {
|
|
11
|
+
const res = { errMsg: `showTabBarRedDot:fail ${isObject.msg}` };
|
|
12
|
+
console.error(res.errMsg);
|
|
13
|
+
return Promise.reject(res);
|
|
14
|
+
}
|
|
15
|
+
const { index, success, fail, complete } = options;
|
|
16
|
+
const handle = new MethodHandler({ name: 'showTabBarRedDot', success, fail, complete });
|
|
17
|
+
if (typeof index !== 'number') {
|
|
18
|
+
return handle.fail({
|
|
19
|
+
errMsg: getParameterError({
|
|
20
|
+
para: 'index',
|
|
21
|
+
correct: 'Number',
|
|
22
|
+
wrong: index
|
|
23
|
+
})
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
return new Promise((resolve, reject) => {
|
|
27
|
+
Taro.eventCenter.trigger('__taroShowTabBarRedDotHandler', {
|
|
28
|
+
index,
|
|
29
|
+
successHandler: (res = {}) => handle.success(res, resolve),
|
|
30
|
+
errorHandler: (res = {}) => handle.fail(res, reject)
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
export const showTabBar = (options = {}) => {
|
|
35
|
+
const isObject = shouldBeObject(options);
|
|
36
|
+
if (!isObject.flag) {
|
|
37
|
+
const res = { errMsg: `showTabBar:fail ${isObject.msg}` };
|
|
38
|
+
console.error(res.errMsg);
|
|
39
|
+
return Promise.reject(res);
|
|
40
|
+
}
|
|
41
|
+
const { animation, success, fail, complete } = options;
|
|
42
|
+
const handle = new MethodHandler({ name: 'showTabBar', success, fail, complete });
|
|
43
|
+
if (options.hasOwnProperty('animation') && typeof animation !== 'boolean') {
|
|
44
|
+
return handle.fail({
|
|
45
|
+
errMsg: getParameterError({
|
|
46
|
+
para: 'animation',
|
|
47
|
+
correct: 'Boolean',
|
|
48
|
+
wrong: animation
|
|
49
|
+
})
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
return new Promise((resolve, reject) => {
|
|
53
|
+
Taro.eventCenter.trigger('__taroShowTabBar', {
|
|
54
|
+
animation,
|
|
55
|
+
successHandler: (res = {}) => handle.success(res, resolve),
|
|
56
|
+
errorHandler: (res = {}) => handle.fail(res, reject)
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
export const setTabBarStyle = (options = {}) => {
|
|
61
|
+
const isObject = shouldBeObject(options);
|
|
62
|
+
if (!isObject.flag) {
|
|
63
|
+
const res = { errMsg: `setTabBarStyle:fail ${isObject.msg}` };
|
|
64
|
+
console.error(res.errMsg);
|
|
65
|
+
return Promise.reject(res);
|
|
66
|
+
}
|
|
67
|
+
const { color, selectedColor, backgroundColor, borderStyle, success, fail, complete } = options;
|
|
68
|
+
const handle = new MethodHandler({ name: 'setTabBarStyle', success, fail, complete });
|
|
69
|
+
let errMsg;
|
|
70
|
+
if (color && !isValidColor(color)) {
|
|
71
|
+
errMsg = 'color';
|
|
72
|
+
}
|
|
73
|
+
else if (selectedColor && !isValidColor(selectedColor)) {
|
|
74
|
+
errMsg = 'selectedColor';
|
|
75
|
+
}
|
|
76
|
+
else if (backgroundColor && !isValidColor(backgroundColor)) {
|
|
77
|
+
errMsg = 'backgroundColor';
|
|
78
|
+
}
|
|
79
|
+
else if (borderStyle && !/^(black|white)$/.test(borderStyle)) {
|
|
80
|
+
errMsg = 'borderStyle';
|
|
81
|
+
}
|
|
82
|
+
if (errMsg) {
|
|
83
|
+
return handle.fail({ errMsg: `invalid ${errMsg}` });
|
|
84
|
+
}
|
|
85
|
+
if (!tabConf) {
|
|
86
|
+
return handle.fail();
|
|
87
|
+
}
|
|
88
|
+
const obj = {};
|
|
89
|
+
if (color)
|
|
90
|
+
obj.color = color;
|
|
91
|
+
if (selectedColor)
|
|
92
|
+
obj.selectedColor = selectedColor;
|
|
93
|
+
if (backgroundColor)
|
|
94
|
+
obj.backgroundColor = backgroundColor;
|
|
95
|
+
if (borderStyle)
|
|
96
|
+
obj.borderStyle = borderStyle;
|
|
97
|
+
return new Promise((resolve, reject) => {
|
|
98
|
+
Taro.eventCenter.trigger('__taroSetTabBarStyle', {
|
|
99
|
+
color,
|
|
100
|
+
selectedColor,
|
|
101
|
+
backgroundColor,
|
|
102
|
+
borderStyle,
|
|
103
|
+
successHandler: (res = {}) => handle.success(res, resolve),
|
|
104
|
+
errorHandler: (res = {}) => handle.fail(res, reject)
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
};
|
|
108
|
+
export const setTabBarItem = (options) => {
|
|
109
|
+
const isObject = shouldBeObject(options);
|
|
110
|
+
if (!isObject.flag) {
|
|
111
|
+
const res = { errMsg: `setTabBarItem:fail ${isObject.msg}` };
|
|
112
|
+
console.error(res.errMsg);
|
|
113
|
+
return Promise.reject(res);
|
|
114
|
+
}
|
|
115
|
+
const { index, text, iconPath, selectedIconPath, success, fail, complete } = options;
|
|
116
|
+
const handle = new MethodHandler({ name: 'setTabBarItem', success, fail, complete });
|
|
117
|
+
if (typeof index !== 'number') {
|
|
118
|
+
return handle.fail({
|
|
119
|
+
errMsg: getParameterError({
|
|
120
|
+
para: 'index',
|
|
121
|
+
correct: 'Number',
|
|
122
|
+
wrong: index
|
|
123
|
+
})
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
return new Promise((resolve, reject) => {
|
|
127
|
+
Taro.eventCenter.trigger('__taroSetTabBarItem', {
|
|
128
|
+
index,
|
|
129
|
+
text,
|
|
130
|
+
iconPath,
|
|
131
|
+
selectedIconPath,
|
|
132
|
+
successHandler: (res = {}) => handle.success(res, resolve),
|
|
133
|
+
errorHandler: (res = {}) => handle.fail(res, reject)
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
};
|
|
137
|
+
export const setTabBarBadge = (options) => {
|
|
138
|
+
const isObject = shouldBeObject(options);
|
|
139
|
+
if (!isObject.flag) {
|
|
140
|
+
const res = { errMsg: `setTabBarBadge:fail ${isObject.msg}` };
|
|
141
|
+
console.error(res.errMsg);
|
|
142
|
+
return Promise.reject(res);
|
|
143
|
+
}
|
|
144
|
+
const { index, text, success, fail, complete } = options;
|
|
145
|
+
const handle = new MethodHandler({ name: 'setTabBarBadge', success, fail, complete });
|
|
146
|
+
if (typeof index !== 'number') {
|
|
147
|
+
return handle.fail({
|
|
148
|
+
errMsg: getParameterError({
|
|
149
|
+
para: 'index',
|
|
150
|
+
correct: 'Number',
|
|
151
|
+
wrong: index
|
|
152
|
+
})
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
if (typeof text !== 'string') {
|
|
156
|
+
return handle.fail({
|
|
157
|
+
errMsg: getParameterError({
|
|
158
|
+
para: 'text',
|
|
159
|
+
correct: 'String',
|
|
160
|
+
wrong: text
|
|
161
|
+
})
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
return new Promise((resolve, reject) => {
|
|
165
|
+
Taro.eventCenter.trigger('__taroSetTabBarBadge', {
|
|
166
|
+
index,
|
|
167
|
+
text,
|
|
168
|
+
successHandler: (res = {}) => handle.success(res, resolve),
|
|
169
|
+
errorHandler: (res = {}) => handle.fail(res, reject)
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
};
|
|
173
|
+
export const removeTabBarBadge = (options) => {
|
|
174
|
+
const isObject = shouldBeObject(options);
|
|
175
|
+
if (!isObject.flag) {
|
|
176
|
+
const res = { errMsg: `removeTabBarBadge:fail ${isObject.msg}` };
|
|
177
|
+
console.error(res.errMsg);
|
|
178
|
+
return Promise.reject(res);
|
|
179
|
+
}
|
|
180
|
+
const { index, success, fail, complete } = options;
|
|
181
|
+
const handle = new MethodHandler({ name: 'removeTabBarBadge', success, fail, complete });
|
|
182
|
+
if (typeof index !== 'number') {
|
|
183
|
+
return handle.fail({
|
|
184
|
+
errMsg: getParameterError({
|
|
185
|
+
para: 'index',
|
|
186
|
+
correct: 'Number',
|
|
187
|
+
wrong: index
|
|
188
|
+
})
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
return new Promise((resolve, reject) => {
|
|
192
|
+
Taro.eventCenter.trigger('__taroRemoveTabBarBadge', {
|
|
193
|
+
index,
|
|
194
|
+
successHandler: (res = {}) => handle.success(res, resolve),
|
|
195
|
+
errorHandler: (res = {}) => handle.fail(res, reject)
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
};
|
|
199
|
+
export const hideTabBarRedDot = (options) => {
|
|
200
|
+
const isObject = shouldBeObject(options);
|
|
201
|
+
if (!isObject.flag) {
|
|
202
|
+
const res = { errMsg: `hideTabBarRedDot:fail ${isObject.msg}` };
|
|
203
|
+
console.error(res.errMsg);
|
|
204
|
+
return Promise.reject(res);
|
|
205
|
+
}
|
|
206
|
+
const { index, success, fail, complete } = options;
|
|
207
|
+
const handle = new MethodHandler({ name: 'hideTabBarRedDot', success, fail, complete });
|
|
208
|
+
if (typeof index !== 'number') {
|
|
209
|
+
return handle.fail({
|
|
210
|
+
errMsg: getParameterError({
|
|
211
|
+
para: 'index',
|
|
212
|
+
correct: 'Number',
|
|
213
|
+
wrong: index
|
|
214
|
+
})
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
return new Promise((resolve, reject) => {
|
|
218
|
+
Taro.eventCenter.trigger('__taroHideTabBarRedDotHandler', {
|
|
219
|
+
index,
|
|
220
|
+
successHandler: (res = {}) => handle.success(res, resolve),
|
|
221
|
+
errorHandler: (res = {}) => handle.fail(res, reject)
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
};
|
|
225
|
+
export const hideTabBar = (options = {}) => {
|
|
226
|
+
const isObject = shouldBeObject(options);
|
|
227
|
+
if (!isObject.flag) {
|
|
228
|
+
const res = { errMsg: `hideTabBar:fail ${isObject.msg}` };
|
|
229
|
+
console.error(res.errMsg);
|
|
230
|
+
return Promise.reject(res);
|
|
231
|
+
}
|
|
232
|
+
const { animation, success, fail, complete } = options;
|
|
233
|
+
const handle = new MethodHandler({ name: 'hideTabBar', success, fail, complete });
|
|
234
|
+
if (options.hasOwnProperty('animation') && typeof animation !== 'boolean') {
|
|
235
|
+
return handle.fail({
|
|
236
|
+
errMsg: getParameterError({
|
|
237
|
+
para: 'animation',
|
|
238
|
+
correct: 'Boolean',
|
|
239
|
+
wrong: animation
|
|
240
|
+
})
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
return new Promise((resolve, reject) => {
|
|
244
|
+
Taro.eventCenter.trigger('__taroHideTabBar', {
|
|
245
|
+
animation,
|
|
246
|
+
successHandler: (res = {}) => handle.success(res, resolve),
|
|
247
|
+
errorHandler: (res = {}) => handle.fail(res, reject)
|
|
248
|
+
});
|
|
249
|
+
});
|
|
250
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { temporarilyNotSupport } from '../utils';
|
|
2
|
+
import { CallbackManager } from '../utils/handler';
|
|
3
|
+
const callbackManager = new CallbackManager();
|
|
4
|
+
const resizeListener = () => {
|
|
5
|
+
callbackManager.trigger({
|
|
6
|
+
windowWidth: window.screen.width,
|
|
7
|
+
windowHeight: window.screen.height
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
export const setWindowSize = temporarilyNotSupport('setWindowSize');
|
|
11
|
+
export const onWindowResize = callback => {
|
|
12
|
+
callbackManager.add(callback);
|
|
13
|
+
if (callbackManager.count() === 1) {
|
|
14
|
+
window.addEventListener('resize', resizeListener);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
export const offWindowResize = callback => {
|
|
18
|
+
callbackManager.remove(callback);
|
|
19
|
+
if (callbackManager.count() === 0) {
|
|
20
|
+
window.removeEventListener('resize', resizeListener);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
export class MethodHandler {
|
|
2
|
+
constructor({ name, success, fail, complete }) {
|
|
3
|
+
this.methodName = name;
|
|
4
|
+
this.__success = success;
|
|
5
|
+
this.__fail = fail;
|
|
6
|
+
this.__complete = complete;
|
|
7
|
+
}
|
|
8
|
+
success(res = {}, resolve = Promise.resolve.bind(Promise)) {
|
|
9
|
+
if (!res.errMsg) {
|
|
10
|
+
res.errMsg = `${this.methodName}:ok`;
|
|
11
|
+
}
|
|
12
|
+
typeof this.__success === 'function' && this.__success(res);
|
|
13
|
+
typeof this.__complete === 'function' && this.__complete(res);
|
|
14
|
+
return resolve(res);
|
|
15
|
+
}
|
|
16
|
+
fail(res = {}, reject = Promise.reject.bind(Promise)) {
|
|
17
|
+
if (!res.errMsg) {
|
|
18
|
+
res.errMsg = `${this.methodName}:fail`;
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
res.errMsg = `${this.methodName}:fail ${res.errMsg}`;
|
|
22
|
+
}
|
|
23
|
+
console.error(res.errMsg);
|
|
24
|
+
typeof this.__fail === 'function' && this.__fail(res);
|
|
25
|
+
typeof this.__complete === 'function' && this.__complete(res);
|
|
26
|
+
return reject(res);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export class CallbackManager {
|
|
30
|
+
constructor() {
|
|
31
|
+
this.callbacks = [];
|
|
32
|
+
}
|
|
33
|
+
add(opt) {
|
|
34
|
+
if (opt)
|
|
35
|
+
this.callbacks.push(opt);
|
|
36
|
+
}
|
|
37
|
+
remove(opt) {
|
|
38
|
+
if (opt) {
|
|
39
|
+
let pos = -1;
|
|
40
|
+
this.callbacks.forEach((callback, k) => {
|
|
41
|
+
if (callback === opt) {
|
|
42
|
+
pos = k;
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
if (pos > -1) {
|
|
46
|
+
this.callbacks.splice(pos, 1);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
count() {
|
|
51
|
+
return this.callbacks.length;
|
|
52
|
+
}
|
|
53
|
+
trigger(...args) {
|
|
54
|
+
this.callbacks.forEach(opt => {
|
|
55
|
+
if (typeof opt === 'function') {
|
|
56
|
+
opt(...args);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
const { callback, ctx } = opt;
|
|
60
|
+
typeof callback === 'function' && callback.call(ctx, ...args);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { Current, container, SERVICE_IDENTIFIER } from '@tarojs/runtime';
|
|
2
|
+
export function shouldBeObject(target) {
|
|
3
|
+
if (target && typeof target === 'object')
|
|
4
|
+
return { flag: true };
|
|
5
|
+
return {
|
|
6
|
+
flag: false,
|
|
7
|
+
msg: getParameterError({
|
|
8
|
+
correct: 'Object',
|
|
9
|
+
wrong: target
|
|
10
|
+
})
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export function findDOM(inst) {
|
|
14
|
+
const runtimeHooks = container.get(SERVICE_IDENTIFIER.Hooks);
|
|
15
|
+
if (inst) {
|
|
16
|
+
const find = runtimeHooks.getDOMNode;
|
|
17
|
+
if (typeof find === 'function') {
|
|
18
|
+
return find(inst);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
const page = Current.page;
|
|
22
|
+
const path = page === null || page === void 0 ? void 0 : page.path;
|
|
23
|
+
const msg = '没有找到已经加载了的页面,请在页面加载完成后时候此 API。';
|
|
24
|
+
if (path == null) {
|
|
25
|
+
throw new Error(msg);
|
|
26
|
+
}
|
|
27
|
+
const el = document.getElementById(path);
|
|
28
|
+
if (el == null) {
|
|
29
|
+
throw new Error('在已加载页面中没有找到对应的容器元素。');
|
|
30
|
+
}
|
|
31
|
+
return el;
|
|
32
|
+
}
|
|
33
|
+
export function getParameterError({ name = '', para, correct, wrong }) {
|
|
34
|
+
const parameter = para ? `parameter.${para}` : 'parameter';
|
|
35
|
+
const errorType = upperCaseFirstLetter(wrong === null ? 'Null' : typeof wrong);
|
|
36
|
+
if (name) {
|
|
37
|
+
return `${name}:fail parameter error: ${parameter} should be ${correct} instead of ${errorType}`;
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
return `parameter error: ${parameter} should be ${correct} instead of ${errorType}`;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function upperCaseFirstLetter(string) {
|
|
44
|
+
if (typeof string !== 'string')
|
|
45
|
+
return string;
|
|
46
|
+
string = string.replace(/^./, match => match.toUpperCase());
|
|
47
|
+
return string;
|
|
48
|
+
}
|
|
49
|
+
export function inlineStyle(style) {
|
|
50
|
+
let res = '';
|
|
51
|
+
for (const attr in style)
|
|
52
|
+
res += `${attr}: ${style[attr]};`;
|
|
53
|
+
if (res.indexOf('display: flex;') >= 0)
|
|
54
|
+
res += 'display: -webkit-box;display: -webkit-flex;';
|
|
55
|
+
res = res.replace(/transform:(.+?);/g, (s, $1) => `${s}-webkit-transform:${$1};`);
|
|
56
|
+
res = res.replace(/flex-direction:(.+?);/g, (s, $1) => `${s}-webkit-flex-direction:${$1};`);
|
|
57
|
+
return res;
|
|
58
|
+
}
|
|
59
|
+
export function setTransform(el, val) {
|
|
60
|
+
el.style.webkitTransform = val;
|
|
61
|
+
el.style.transform = val;
|
|
62
|
+
}
|
|
63
|
+
export function serializeParams(params) {
|
|
64
|
+
if (!params) {
|
|
65
|
+
return '';
|
|
66
|
+
}
|
|
67
|
+
return Object.keys(params)
|
|
68
|
+
.map(key => (`${encodeURIComponent(key)}=${typeof (params[key]) === 'object'
|
|
69
|
+
? encodeURIComponent(JSON.stringify(params[key]))
|
|
70
|
+
: encodeURIComponent(params[key])}`))
|
|
71
|
+
.join('&');
|
|
72
|
+
}
|
|
73
|
+
export function temporarilyNotSupport(apiName) {
|
|
74
|
+
return () => {
|
|
75
|
+
const errMsg = `暂时不支持 API ${apiName}`;
|
|
76
|
+
console.error(errMsg);
|
|
77
|
+
return Promise.reject({
|
|
78
|
+
errMsg
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
export function weixinCorpSupport(apiName) {
|
|
83
|
+
return () => {
|
|
84
|
+
const errMsg = `h5端仅在微信公众号中支持 API ${apiName}`;
|
|
85
|
+
console.error(errMsg);
|
|
86
|
+
return Promise.reject({
|
|
87
|
+
errMsg
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
export function permanentlyNotSupport(apiName) {
|
|
92
|
+
return () => {
|
|
93
|
+
const errMsg = `不支持 API ${apiName}`;
|
|
94
|
+
console.error(errMsg);
|
|
95
|
+
return Promise.reject({
|
|
96
|
+
errMsg
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
export function isFunction(obj) {
|
|
101
|
+
return typeof obj === 'function';
|
|
102
|
+
}
|
|
103
|
+
const VALID_COLOR_REG = /^#[0-9a-fA-F]{6}$/;
|
|
104
|
+
export const isValidColor = (color) => {
|
|
105
|
+
return VALID_COLOR_REG.test(color);
|
|
106
|
+
};
|
|
107
|
+
export function processOpenApi(apiName, defaultOptions, formatResult = res => res, formatParams = options => options) {
|
|
108
|
+
if (!window.wx) {
|
|
109
|
+
return weixinCorpSupport(apiName);
|
|
110
|
+
}
|
|
111
|
+
return options => {
|
|
112
|
+
options = options || {};
|
|
113
|
+
const obj = Object.assign({}, defaultOptions, options);
|
|
114
|
+
const p = new Promise((resolve, reject) => {
|
|
115
|
+
['fail', 'success', 'complete'].forEach(k => {
|
|
116
|
+
obj[k] = oriRes => {
|
|
117
|
+
const res = formatResult(oriRes);
|
|
118
|
+
options[k] && options[k](res);
|
|
119
|
+
if (k === 'success') {
|
|
120
|
+
resolve(res);
|
|
121
|
+
}
|
|
122
|
+
else if (k === 'fail') {
|
|
123
|
+
reject(res);
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
});
|
|
127
|
+
wx[apiName](formatParams(obj));
|
|
128
|
+
});
|
|
129
|
+
return p;
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
export const easeInOut = (t) => t < 0.5 ? 4 * t * t * t : (t - 1) * (2 * t - 2) * (2 * t - 2) + 1;
|
|
133
|
+
export const getTimingFunc = (easeFunc, frameCnt) => {
|
|
134
|
+
return x => {
|
|
135
|
+
if (frameCnt <= 1) {
|
|
136
|
+
return easeFunc(1);
|
|
137
|
+
}
|
|
138
|
+
const t = x / (frameCnt - 1);
|
|
139
|
+
return easeFunc(t);
|
|
140
|
+
};
|
|
141
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { temporarilyNotSupport } from '../utils';
|
|
2
|
+
import { SelectorQuery } from './selectorQuery';
|
|
3
|
+
export const createSelectorQuery = () => {
|
|
4
|
+
return new SelectorQuery();
|
|
5
|
+
};
|
|
6
|
+
export const createIntersectionObserver = temporarilyNotSupport('createIntersectionObserver');
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { temporarilyNotSupport } from '../utils';
|
|
2
|
+
export class NodesRef {
|
|
3
|
+
constructor(selector, querySelectorQuery, single) {
|
|
4
|
+
this.context = temporarilyNotSupport('NodesRef.context');
|
|
5
|
+
this.node = temporarilyNotSupport('NodesRef.node');
|
|
6
|
+
this._component = querySelectorQuery._component;
|
|
7
|
+
this._selector = selector;
|
|
8
|
+
this._selectorQuery = querySelectorQuery;
|
|
9
|
+
this._single = single;
|
|
10
|
+
}
|
|
11
|
+
boundingClientRect(cb) {
|
|
12
|
+
const { _selector, _component, _single, _selectorQuery } = this;
|
|
13
|
+
_selectorQuery._push(_selector, _component, _single, { id: !0, dataset: !0, rect: !0, size: !0 }, cb);
|
|
14
|
+
return _selectorQuery;
|
|
15
|
+
}
|
|
16
|
+
scrollOffset(cb) {
|
|
17
|
+
const { _selector, _component, _single, _selectorQuery } = this;
|
|
18
|
+
_selectorQuery._push(_selector, _component, _single, { id: !0, dataset: !0, scrollOffset: !0 }, cb);
|
|
19
|
+
return _selectorQuery;
|
|
20
|
+
}
|
|
21
|
+
fields(fields, cb) {
|
|
22
|
+
const { _selector, _component, _single, _selectorQuery } = this;
|
|
23
|
+
const { id, dataset, rect, size, scrollOffset, properties = [], computedStyle = [] } = fields;
|
|
24
|
+
_selectorQuery._push(_selector, _component, _single, {
|
|
25
|
+
id,
|
|
26
|
+
dataset,
|
|
27
|
+
rect,
|
|
28
|
+
size,
|
|
29
|
+
scrollOffset,
|
|
30
|
+
properties,
|
|
31
|
+
computedStyle
|
|
32
|
+
}, cb);
|
|
33
|
+
return _selectorQuery;
|
|
34
|
+
}
|
|
35
|
+
}
|