@tarojs/taro-h5 3.4.0-beta.2 → 3.4.0-beta.3
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 +4 -0
- package/dist/api/ai/facial.js +5 -0
- package/dist/api/ai/index.js +2 -0
- package/dist/api/ai/visual.js +3 -0
- package/dist/api/alipay/index.js +3 -0
- package/dist/api/base/crypto.js +3 -0
- package/dist/api/base/debug.js +4 -0
- package/dist/api/base/index.js +17 -0
- package/dist/api/base/performance.js +4 -0
- package/dist/api/base/system/index.js +2 -0
- package/dist/api/base/system/info.js +57 -0
- package/dist/api/base/system/network.js +63 -0
- package/dist/api/base/update.js +4 -0
- package/dist/api/base/weapp/app-event.js +18 -0
- package/dist/api/base/weapp/life-cycle.js +4 -0
- package/dist/api/canvas/CanvasContext.js +191 -0
- package/dist/api/canvas/canvasGetImageData.js +25 -0
- package/dist/api/canvas/canvasPutImageData.js +22 -0
- package/dist/api/canvas/canvasToTempFilePath.js +22 -0
- package/dist/api/canvas/createCanvasContext.js +16 -0
- package/dist/api/canvas/index.js +8 -0
- package/dist/api/cloud/index.js +17 -0
- package/dist/api/data-analysis/index.js +5 -0
- package/dist/api/device/accelerometer.js +83 -0
- package/dist/api/device/accessibility.js +3 -0
- package/dist/api/device/battery.js +4 -0
- package/dist/api/device/bluetooth-ble.js +18 -0
- package/dist/api/device/bluetooth-peripheral.js +5 -0
- package/dist/api/device/bluetooth.js +15 -0
- package/dist/api/device/calendar.js +4 -0
- package/dist/api/device/clipboard.js +65 -0
- package/dist/api/device/compass.js +64 -0
- package/dist/api/device/contact.js +4 -0
- package/dist/api/device/crypto.js +3 -0
- package/dist/api/device/gyroscope.js +6 -0
- package/dist/api/device/iBeacon.js +9 -0
- package/dist/api/device/index.js +22 -0
- package/dist/api/device/keyboard.js +6 -0
- package/dist/api/device/memory.js +4 -0
- package/dist/api/device/motion.js +81 -0
- package/dist/api/device/nfc.js +9 -0
- package/dist/api/device/phone.js +24 -0
- package/dist/api/device/scan.js +6 -0
- package/dist/api/device/screen.js +8 -0
- package/dist/api/device/vibrate.js +35 -0
- package/dist/api/device/wifi.js +12 -0
- package/dist/api/ext/index.js +4 -0
- package/dist/api/files/index.js +10 -0
- package/dist/api/framework/index.js +7 -0
- package/dist/api/index.js +24 -0
- package/dist/api/location/chooseLocation.js +93 -0
- package/dist/api/location/index.js +13 -0
- package/dist/api/location/style.css +79 -0
- package/dist/api/media/audio/index.js +88 -0
- package/dist/api/media/background-audio.js +11 -0
- package/dist/api/media/camera.js +3 -0
- package/dist/api/media/editor.js +18 -0
- package/dist/api/media/image/chooseImage.js +74 -0
- package/dist/api/media/image/getImageInfo.js +31 -0
- package/dist/api/media/image/index.js +9 -0
- package/dist/api/media/image/previewImage.js +67 -0
- package/dist/api/media/index.js +13 -0
- package/dist/api/media/live.js +4 -0
- package/dist/api/media/map.js +3 -0
- package/dist/api/media/media-recorder.js +3 -0
- package/dist/api/media/recorder.js +5 -0
- package/dist/api/media/video/index.js +74 -0
- package/dist/api/media/video-decoder.js +3 -0
- package/dist/api/media/video-processing.js +3 -0
- package/dist/api/media/voip.js +16 -0
- package/dist/api/navigate/index.js +6 -0
- package/dist/api/network/download.js +124 -0
- package/dist/api/network/index.js +7 -0
- package/dist/api/network/mdns.js +12 -0
- package/dist/api/network/request/index.js +125 -0
- package/dist/api/network/tcp.js +3 -0
- package/dist/api/network/udp.js +3 -0
- package/dist/api/network/upload.js +151 -0
- package/dist/api/network/utils.js +65 -0
- package/dist/api/network/websocket/index.js +70 -0
- package/dist/api/network/websocket/socketTask.js +63 -0
- package/dist/api/open-api/account.js +3 -0
- package/dist/api/open-api/address.js +3 -0
- package/dist/api/open-api/authorize.js +4 -0
- package/dist/api/open-api/card.js +4 -0
- package/dist/api/open-api/channels-live.js +8 -0
- package/dist/api/open-api/customer-service.js +3 -0
- package/dist/api/open-api/facial.js +6 -0
- package/dist/api/open-api/favorites.js +4 -0
- package/dist/api/open-api/group.js +3 -0
- package/dist/api/open-api/index.js +18 -0
- package/dist/api/open-api/invoice.js +4 -0
- package/dist/api/open-api/license-plate.js +3 -0
- package/dist/api/open-api/login.js +5 -0
- package/dist/api/open-api/red-package.js +3 -0
- package/dist/api/open-api/settings.js +4 -0
- package/dist/api/open-api/soter.js +5 -0
- package/dist/api/open-api/subscribe-message.js +3 -0
- package/dist/api/open-api/user-info.js +4 -0
- package/dist/api/open-api/werun.js +4 -0
- package/dist/api/payment/index.js +4 -0
- package/dist/api/route/index.js +3 -0
- package/dist/api/share/index.js +12 -0
- package/dist/api/storage/background-fetch.js +6 -0
- package/dist/api/storage/index.js +157 -0
- package/dist/api/swan/index.js +26 -0
- package/dist/api/taro.js +47 -0
- package/dist/api/ui/animation/index.js +284 -0
- package/dist/api/ui/background.js +4 -0
- package/dist/api/ui/custom-component.js +3 -0
- package/dist/api/ui/fonts.js +3 -0
- package/dist/api/ui/index.js +12 -0
- package/dist/api/ui/interaction/actionSheet.js +188 -0
- package/dist/api/ui/interaction/index.js +268 -0
- package/dist/api/ui/interaction/modal.js +207 -0
- package/dist/api/ui/interaction/toast.js +195 -0
- package/dist/api/ui/menu.js +3 -0
- package/dist/api/ui/navigation-bar/index.js +42 -0
- package/dist/api/ui/pull-down-refresh.js +26 -0
- package/dist/api/ui/scroll/index.js +83 -0
- package/dist/api/ui/sticky.js +3 -0
- package/dist/api/ui/tab-bar.js +282 -0
- package/dist/api/ui/window.js +31 -0
- package/dist/api/utils/handler.js +80 -0
- package/dist/api/utils/index.js +148 -0
- package/dist/api/worker/index.js +3 -0
- package/dist/api/wxml/index.js +6 -0
- package/dist/api/wxml/nodesRef.js +42 -0
- package/dist/api/wxml/selectorQuery.js +201 -0
- package/dist/index.cjs.js +4626 -6915
- package/dist/index.js +4 -10767
- package/dist/types/type.js +2 -0
- package/package.json +10 -13
- package/src/api/canvas/CanvasContext.ts +35 -32
- package/src/api/canvas/createCanvasContext.ts +2 -2
- package/src/api/location/chooseLocation.ts +2 -2
- package/src/api/media/audio/index.ts +16 -16
- package/src/api/media/image/previewImage.ts +4 -25
- 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
- package/src/api/ui/animation/index.ts +1 -6
- package/src/api/ui/interaction/index.ts +6 -4
- package/src/api/ui/navigation-bar/index.ts +1 -1
- package/src/api/wxml/nodesRef.ts +10 -3
- package/src/api/wxml/selectorQuery.ts +68 -23
- package/src/index.ts +2 -2
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { inlineStyle } from '../../utils';
|
|
2
|
+
export default class Toast {
|
|
3
|
+
constructor() {
|
|
4
|
+
this.options = {
|
|
5
|
+
title: '',
|
|
6
|
+
icon: 'none',
|
|
7
|
+
image: '',
|
|
8
|
+
duration: 1500,
|
|
9
|
+
mask: false
|
|
10
|
+
};
|
|
11
|
+
this.style = {
|
|
12
|
+
maskStyle: {
|
|
13
|
+
position: 'fixed',
|
|
14
|
+
'z-index': '1000',
|
|
15
|
+
top: '0',
|
|
16
|
+
right: '0',
|
|
17
|
+
left: '0',
|
|
18
|
+
bottom: '0'
|
|
19
|
+
},
|
|
20
|
+
toastStyle: {
|
|
21
|
+
'z-index': '5000',
|
|
22
|
+
'box-sizing': 'border-box',
|
|
23
|
+
display: 'flex',
|
|
24
|
+
'flex-direction': 'column',
|
|
25
|
+
'justify-content': 'center',
|
|
26
|
+
'-webkit-justify-content': 'center',
|
|
27
|
+
position: 'fixed',
|
|
28
|
+
top: '50%',
|
|
29
|
+
left: '50%',
|
|
30
|
+
'min-width': '120px',
|
|
31
|
+
'max-width': '200px',
|
|
32
|
+
'min-height': '120px',
|
|
33
|
+
padding: '15px',
|
|
34
|
+
transform: 'translate(-50%, -50%)',
|
|
35
|
+
'border-radius': '5px',
|
|
36
|
+
'text-align': 'center',
|
|
37
|
+
'line-height': '1.6',
|
|
38
|
+
color: '#FFFFFF',
|
|
39
|
+
background: 'rgba(17, 17, 17, 0.7)'
|
|
40
|
+
},
|
|
41
|
+
successStyle: {
|
|
42
|
+
margin: '6px auto',
|
|
43
|
+
width: '38px',
|
|
44
|
+
height: '38px',
|
|
45
|
+
background: 'transparent url(data:image/svg+xml;base64,PHN2ZyB0PSIxNjM5NTQ4OTYzMjA0IiBjbGFzcz0iaWNvbiIgdmlld0JveD0iMCAwIDEwMjQgMTAyNCIgdmVyc2lvbj0iMS4xIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHAtaWQ9IjQzNDgiIHdpZHRoPSIyMDAiIGhlaWdodD0iMjAwIj48cGF0aCBkPSJNMjE5Ljk1MiA1MTIuNTc2bDIxMC40MzIgMjEwLjQzMi00NS4yNDggNDUuMjU2LTIxMC40MzItMjEwLjQzMnoiIHAtaWQ9IjQzNDkiIGZpbGw9IiNmZmZmZmYiPjwvcGF0aD48cGF0aCBkPSJNNzk5LjY3MiAyNjIuMjY0bDQ1LjI1NiA0NS4yNTYtNDYwLjQ2NCA0NjAuNDY0LTQ1LjI1Ni00NS4yNTZ6IiBwLWlkPSI0MzUwIiBmaWxsPSIjZmZmZmZmIj48L3BhdGg+PC9zdmc+) no-repeat',
|
|
46
|
+
'background-size': '100%'
|
|
47
|
+
},
|
|
48
|
+
errrorStyle: {
|
|
49
|
+
margin: '6px auto',
|
|
50
|
+
width: '38px',
|
|
51
|
+
height: '38px',
|
|
52
|
+
background: 'transparent url(data:image/svg+xml;base64,PHN2ZyB0PSIxNjM5NTUxMDU1MTgzIiBjbGFzcz0iaWNvbiIgdmlld0JveD0iMCAwIDEwMjQgMTAyNCIgdmVyc2lvbj0iMS4xIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHAtaWQ9IjE0MDc2IiB3aWR0aD0iMjAwIiBoZWlnaHQ9IjIwMCI+PHBhdGggZD0iTTUxMiA2NEMyNjQuNTggNjQgNjQgMjY0LjU4IDY0IDUxMnMyMDAuNTggNDQ4IDQ0OCA0NDggNDQ4LTIwMC41OCA0NDgtNDQ4Uzc1OS40MiA2NCA1MTIgNjR6IG0wIDc1MmEzNiAzNiAwIDEgMSAzNi0zNiAzNiAzNiAwIDAgMS0zNiAzNnogbTUxLjgzLTU1MS45NUw1NDggNjM2YTM2IDM2IDAgMCAxLTcyIDBsLTE1LjgzLTM3MS45NWMtMC4xLTEuMzMtMC4xNy0yLjY4LTAuMTctNC4wNWE1MiA1MiAwIDAgMSAxMDQgMGMwIDEuMzctMC4wNyAyLjcyLTAuMTcgNC4wNXoiIHAtaWQ9IjE0MDc3IiBmaWxsPSIjZmZmZmZmIj48L3BhdGg+PC9zdmc+) no-repeat',
|
|
53
|
+
'background-size': '100%'
|
|
54
|
+
},
|
|
55
|
+
loadingStyle: {
|
|
56
|
+
margin: '6px auto',
|
|
57
|
+
width: '38px',
|
|
58
|
+
height: '38px',
|
|
59
|
+
'-webkit-animation': 'taroLoading 1s steps(12, end) infinite',
|
|
60
|
+
animation: 'taroLoading 1s steps(12, end) infinite',
|
|
61
|
+
background: 'transparent url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxMjAiIGhlaWdodD0iMTIwIiB2aWV3Qm94PSIwIDAgMTAwIDEwMCI+PHBhdGggZmlsbD0ibm9uZSIgZD0iTTAgMGgxMDB2MTAwSDB6Ii8+PHJlY3Qgd2lkdGg9IjciIGhlaWdodD0iMjAiIHg9IjQ2LjUiIHk9IjQwIiBmaWxsPSIjRTlFOUU5IiByeD0iNSIgcnk9IjUiIHRyYW5zZm9ybT0idHJhbnNsYXRlKDAgLTMwKSIvPjxyZWN0IHdpZHRoPSI3IiBoZWlnaHQ9IjIwIiB4PSI0Ni41IiB5PSI0MCIgZmlsbD0iIzk4OTY5NyIgcng9IjUiIHJ5PSI1IiB0cmFuc2Zvcm09InJvdGF0ZSgzMCAxMDUuOTggNjUpIi8+PHJlY3Qgd2lkdGg9IjciIGhlaWdodD0iMjAiIHg9IjQ2LjUiIHk9IjQwIiBmaWxsPSIjOUI5OTlBIiByeD0iNSIgcnk9IjUiIHRyYW5zZm9ybT0icm90YXRlKDYwIDc1Ljk4IDY1KSIvPjxyZWN0IHdpZHRoPSI3IiBoZWlnaHQ9IjIwIiB4PSI0Ni41IiB5PSI0MCIgZmlsbD0iI0EzQTFBMiIgcng9IjUiIHJ5PSI1IiB0cmFuc2Zvcm09InJvdGF0ZSg5MCA2NSA2NSkiLz48cmVjdCB3aWR0aD0iNyIgaGVpZ2h0PSIyMCIgeD0iNDYuNSIgeT0iNDAiIGZpbGw9IiNBQkE5QUEiIHJ4PSI1IiByeT0iNSIgdHJhbnNmb3JtPSJyb3RhdGUoMTIwIDU4LjY2IDY1KSIvPjxyZWN0IHdpZHRoPSI3IiBoZWlnaHQ9IjIwIiB4PSI0Ni41IiB5PSI0MCIgZmlsbD0iI0IyQjJCMiIgcng9IjUiIHJ5PSI1IiB0cmFuc2Zvcm09InJvdGF0ZSgxNTAgNTQuMDIgNjUpIi8+PHJlY3Qgd2lkdGg9IjciIGhlaWdodD0iMjAiIHg9IjQ2LjUiIHk9IjQwIiBmaWxsPSIjQkFCOEI5IiByeD0iNSIgcnk9IjUiIHRyYW5zZm9ybT0icm90YXRlKDE4MCA1MCA2NSkiLz48cmVjdCB3aWR0aD0iNyIgaGVpZ2h0PSIyMCIgeD0iNDYuNSIgeT0iNDAiIGZpbGw9IiNDMkMwQzEiIHJ4PSI1IiByeT0iNSIgdHJhbnNmb3JtPSJyb3RhdGUoLTE1MCA0NS45OCA2NSkiLz48cmVjdCB3aWR0aD0iNyIgaGVpZ2h0PSIyMCIgeD0iNDYuNSIgeT0iNDAiIGZpbGw9IiNDQkNCQ0IiIHJ4PSI1IiByeT0iNSIgdHJhbnNmb3JtPSJyb3RhdGUoLTEyMCA0MS4zNCA2NSkiLz48cmVjdCB3aWR0aD0iNyIgaGVpZ2h0PSIyMCIgeD0iNDYuNSIgeT0iNDAiIGZpbGw9IiNEMkQyRDIiIHJ4PSI1IiByeT0iNSIgdHJhbnNmb3JtPSJyb3RhdGUoLTkwIDM1IDY1KSIvPjxyZWN0IHdpZHRoPSI3IiBoZWlnaHQ9IjIwIiB4PSI0Ni41IiB5PSI0MCIgZmlsbD0iI0RBREFEQSIgcng9IjUiIHJ5PSI1IiB0cmFuc2Zvcm09InJvdGF0ZSgtNjAgMjQuMDIgNjUpIi8+PHJlY3Qgd2lkdGg9IjciIGhlaWdodD0iMjAiIHg9IjQ2LjUiIHk9IjQwIiBmaWxsPSIjRTJFMkUyIiByeD0iNSIgcnk9IjUiIHRyYW5zZm9ybT0icm90YXRlKC0zMCAtNS45OCA2NSkiLz48L3N2Zz4=) no-repeat',
|
|
62
|
+
'background-size': '100%'
|
|
63
|
+
},
|
|
64
|
+
imageStyle: {
|
|
65
|
+
margin: '6px auto',
|
|
66
|
+
width: '40px',
|
|
67
|
+
height: '40px',
|
|
68
|
+
background: 'transparent no-repeat',
|
|
69
|
+
'background-size': '100%'
|
|
70
|
+
},
|
|
71
|
+
textStyle: {
|
|
72
|
+
margin: '0',
|
|
73
|
+
'font-size': '16px'
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
create(options = {}, _type = 'toast') {
|
|
78
|
+
// style
|
|
79
|
+
const { maskStyle, toastStyle, successStyle, errrorStyle, loadingStyle, imageStyle, textStyle } = this.style;
|
|
80
|
+
// configuration
|
|
81
|
+
const config = {
|
|
82
|
+
...this.options,
|
|
83
|
+
...options,
|
|
84
|
+
_type
|
|
85
|
+
};
|
|
86
|
+
// wrapper
|
|
87
|
+
this.el = document.createElement('div');
|
|
88
|
+
this.el.className = 'taro__toast';
|
|
89
|
+
this.el.style.opacity = '0';
|
|
90
|
+
this.el.style.transition = 'opacity 0.1s linear';
|
|
91
|
+
// mask
|
|
92
|
+
this.mask = document.createElement('div');
|
|
93
|
+
this.mask.setAttribute('style', inlineStyle(maskStyle));
|
|
94
|
+
this.mask.style.display = config.mask ? 'block' : 'none';
|
|
95
|
+
// icon
|
|
96
|
+
this.icon = document.createElement('p');
|
|
97
|
+
if (config.image) {
|
|
98
|
+
this.icon.setAttribute('style', inlineStyle({
|
|
99
|
+
...imageStyle,
|
|
100
|
+
'background-image': `url(${config.image})`
|
|
101
|
+
}));
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
const iconStyle = config.icon === 'loading' ? loadingStyle : config.icon === 'error' ? errrorStyle : successStyle;
|
|
105
|
+
this.icon.setAttribute('style', inlineStyle({
|
|
106
|
+
...iconStyle,
|
|
107
|
+
...(config.icon === 'none' ? { display: 'none' } : {})
|
|
108
|
+
}));
|
|
109
|
+
}
|
|
110
|
+
// toast
|
|
111
|
+
this.toast = document.createElement('div');
|
|
112
|
+
this.toast.setAttribute('style', inlineStyle({
|
|
113
|
+
...toastStyle,
|
|
114
|
+
...(config.icon === 'none' ? {
|
|
115
|
+
'min-height': '0',
|
|
116
|
+
padding: '10px 15px'
|
|
117
|
+
} : {})
|
|
118
|
+
}));
|
|
119
|
+
// title
|
|
120
|
+
this.title = document.createElement('p');
|
|
121
|
+
this.title.setAttribute('style', inlineStyle(textStyle));
|
|
122
|
+
this.title.textContent = config.title;
|
|
123
|
+
// result
|
|
124
|
+
this.toast.appendChild(this.icon);
|
|
125
|
+
this.toast.appendChild(this.title);
|
|
126
|
+
this.el.appendChild(this.mask);
|
|
127
|
+
this.el.appendChild(this.toast);
|
|
128
|
+
// show immediately
|
|
129
|
+
document.body.appendChild(this.el);
|
|
130
|
+
setTimeout(() => { this.el.style.opacity = '1'; }, 0);
|
|
131
|
+
this.type = config._type;
|
|
132
|
+
// disappear after duration
|
|
133
|
+
config.duration >= 0 && this.hide(config.duration, this.type);
|
|
134
|
+
return '';
|
|
135
|
+
}
|
|
136
|
+
show(options = {}, _type = 'toast') {
|
|
137
|
+
const config = {
|
|
138
|
+
...this.options,
|
|
139
|
+
...options,
|
|
140
|
+
_type
|
|
141
|
+
};
|
|
142
|
+
if (this.hideOpacityTimer)
|
|
143
|
+
clearTimeout(this.hideOpacityTimer);
|
|
144
|
+
if (this.hideDisplayTimer)
|
|
145
|
+
clearTimeout(this.hideDisplayTimer);
|
|
146
|
+
// title
|
|
147
|
+
this.title.textContent = config.title || '';
|
|
148
|
+
// mask
|
|
149
|
+
this.mask.style.display = config.mask ? 'block' : 'none';
|
|
150
|
+
// image
|
|
151
|
+
const { toastStyle, successStyle, errrorStyle, loadingStyle, imageStyle } = this.style;
|
|
152
|
+
if (config.image) {
|
|
153
|
+
this.icon.setAttribute('style', inlineStyle({
|
|
154
|
+
...imageStyle,
|
|
155
|
+
'background-image': `url(${config.image})`
|
|
156
|
+
}));
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
if (!config.image && config.icon) {
|
|
160
|
+
const iconStyle = config.icon === 'loading' ? loadingStyle : config.icon === 'error' ? errrorStyle : successStyle;
|
|
161
|
+
this.icon.setAttribute('style', inlineStyle({
|
|
162
|
+
...iconStyle,
|
|
163
|
+
...(config.icon === 'none' ? { display: 'none' } : {})
|
|
164
|
+
}));
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
// toast
|
|
168
|
+
this.toast.setAttribute('style', inlineStyle({
|
|
169
|
+
...toastStyle,
|
|
170
|
+
...(config.icon === 'none' ? {
|
|
171
|
+
'min-height': '0',
|
|
172
|
+
padding: '10px 15px'
|
|
173
|
+
} : {})
|
|
174
|
+
}));
|
|
175
|
+
// show
|
|
176
|
+
this.el.style.display = 'block';
|
|
177
|
+
setTimeout(() => { this.el.style.opacity = '1'; }, 0);
|
|
178
|
+
this.type = config._type;
|
|
179
|
+
// disappear after duration
|
|
180
|
+
config.duration >= 0 && this.hide(config.duration, this.type);
|
|
181
|
+
return '';
|
|
182
|
+
}
|
|
183
|
+
hide(duration = 0, type) {
|
|
184
|
+
if (this.type !== type)
|
|
185
|
+
return;
|
|
186
|
+
if (this.hideOpacityTimer)
|
|
187
|
+
clearTimeout(this.hideOpacityTimer);
|
|
188
|
+
if (this.hideDisplayTimer)
|
|
189
|
+
clearTimeout(this.hideDisplayTimer);
|
|
190
|
+
this.hideOpacityTimer = setTimeout(() => {
|
|
191
|
+
this.el.style.opacity = '0';
|
|
192
|
+
this.hideDisplayTimer = setTimeout(() => { this.el.style.display = 'none'; }, 100);
|
|
193
|
+
}, duration);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { MethodHandler } from '../../utils/handler';
|
|
2
|
+
import { getParameterError, shouldBeObject, temporarilyNotSupport } from '../../utils';
|
|
3
|
+
// 导航栏
|
|
4
|
+
export const showNavigationBarLoading = temporarilyNotSupport('showNavigationBarLoading');
|
|
5
|
+
export function setNavigationBarTitle(options) {
|
|
6
|
+
// options must be an Object
|
|
7
|
+
const isObject = shouldBeObject(options);
|
|
8
|
+
if (!isObject.flag) {
|
|
9
|
+
const res = { errMsg: `setNavigationBarTitle:fail ${isObject.msg}` };
|
|
10
|
+
console.error(res.errMsg);
|
|
11
|
+
return Promise.reject(res);
|
|
12
|
+
}
|
|
13
|
+
const { title, success, fail, complete } = options;
|
|
14
|
+
const handle = new MethodHandler({ name: 'makePhoneCall', success, fail, complete });
|
|
15
|
+
if (!title || typeof title !== 'string') {
|
|
16
|
+
return handle.fail({
|
|
17
|
+
errMsg: getParameterError({
|
|
18
|
+
para: 'title',
|
|
19
|
+
correct: 'String',
|
|
20
|
+
wrong: title
|
|
21
|
+
})
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
if (document.title !== title) {
|
|
25
|
+
document.title = title;
|
|
26
|
+
}
|
|
27
|
+
return handle.success();
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* 设置页面导航条颜色
|
|
31
|
+
*/
|
|
32
|
+
export const setNavigationBarColor = (options) => {
|
|
33
|
+
const { backgroundColor, success, fail, complete } = options;
|
|
34
|
+
const handle = new MethodHandler({ name: 'setNavigationBarColor', success, fail, complete });
|
|
35
|
+
const meta = document.createElement('meta');
|
|
36
|
+
meta.setAttribute('name', 'theme-color');
|
|
37
|
+
meta.setAttribute('content', backgroundColor);
|
|
38
|
+
document.head.appendChild(meta);
|
|
39
|
+
return handle.success();
|
|
40
|
+
};
|
|
41
|
+
export const hideNavigationBarLoading = temporarilyNotSupport('hideNavigationBarLoading');
|
|
42
|
+
export const hideHomeButton = temporarilyNotSupport('hideHomeButton');
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import Taro from '@tarojs/api';
|
|
2
|
+
import { MethodHandler } from '../utils/handler';
|
|
3
|
+
/**
|
|
4
|
+
* 开始下拉刷新。调用后触发下拉刷新动画,效果与用户手动下拉刷新一致。
|
|
5
|
+
*/
|
|
6
|
+
export const 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),
|
|
11
|
+
errorHandler: (res = {}) => handle.fail(res, reject)
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* 停止当前页面下拉刷新。
|
|
17
|
+
*/
|
|
18
|
+
export const stopPullDownRefresh = function ({ success, fail, complete } = {}) {
|
|
19
|
+
const handle = new MethodHandler({ name: 'stopPullDownRefresh', success, fail, complete });
|
|
20
|
+
return new Promise((resolve, reject) => {
|
|
21
|
+
Taro.eventCenter.trigger('__taroStopPullDownRefresh', {
|
|
22
|
+
successHandler: (res = {}) => handle.success(res, resolve),
|
|
23
|
+
errorHandler: (res = {}) => handle.fail(res, reject)
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
};
|
|
@@ -0,0 +1,83 @@
|
|
|
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
|
+
/**
|
|
7
|
+
* 将页面滚动到目标位置
|
|
8
|
+
*/
|
|
9
|
+
export const pageScrollTo = ({ scrollTop, selector = '', duration = 300, success, fail, complete }) => {
|
|
10
|
+
let scrollFunc;
|
|
11
|
+
const handle = new MethodHandler({ name: 'pageScrollTo', success, fail, complete });
|
|
12
|
+
return new Promise((resolve, reject) => {
|
|
13
|
+
var _a;
|
|
14
|
+
try {
|
|
15
|
+
if (scrollTop === undefined && !selector) {
|
|
16
|
+
return handle.fail({
|
|
17
|
+
errMsg: 'scrollTop" 或 "selector" 需要其之一'
|
|
18
|
+
}, reject);
|
|
19
|
+
}
|
|
20
|
+
const id = (_a = Current.page) === null || _a === void 0 ? void 0 : _a.path;
|
|
21
|
+
const el = (id
|
|
22
|
+
? document.getElementById(id)
|
|
23
|
+
: document.querySelector('.taro_page') ||
|
|
24
|
+
document.querySelector('.taro_router'));
|
|
25
|
+
if (!scrollFunc) {
|
|
26
|
+
if (!el) {
|
|
27
|
+
scrollFunc = pos => {
|
|
28
|
+
if (pos === undefined) {
|
|
29
|
+
return window.pageYOffset;
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
window.scrollTo(0, pos);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
scrollFunc = pos => {
|
|
38
|
+
if (pos === undefined) {
|
|
39
|
+
return el.scrollTop;
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
el.scrollTop = pos;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (scrollTop && selector) {
|
|
48
|
+
console.warn('"scrollTop" 或 "selector" 建议只设一个值,全部设置会忽略selector');
|
|
49
|
+
}
|
|
50
|
+
const from = scrollFunc();
|
|
51
|
+
let to;
|
|
52
|
+
if (typeof scrollTop === 'number') {
|
|
53
|
+
to = scrollTop;
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
const el = document.querySelector(selector);
|
|
57
|
+
to = (el === null || el === void 0 ? void 0 : el.offsetTop) || 0;
|
|
58
|
+
}
|
|
59
|
+
const delta = to - from;
|
|
60
|
+
const frameCnt = duration / FRAME_DURATION;
|
|
61
|
+
const easeFunc = getTimingFunc(easeInOut, frameCnt);
|
|
62
|
+
const scroll = (frame = 0) => {
|
|
63
|
+
const dest = from + delta * easeFunc(frame);
|
|
64
|
+
scrollFunc(dest);
|
|
65
|
+
if (frame < frameCnt) {
|
|
66
|
+
timer && clearTimeout(timer);
|
|
67
|
+
timer = setTimeout(() => {
|
|
68
|
+
scroll(frame + 1);
|
|
69
|
+
}, FRAME_DURATION);
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
return handle.success({}, resolve);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
scroll();
|
|
76
|
+
}
|
|
77
|
+
catch (e) {
|
|
78
|
+
return handle.fail({
|
|
79
|
+
errMsg: e.message
|
|
80
|
+
}, reject);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
};
|
|
@@ -0,0 +1,282 @@
|
|
|
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
|
+
/**
|
|
9
|
+
* 显示 tabBar 某一项的右上角的红点
|
|
10
|
+
*/
|
|
11
|
+
export const showTabBarRedDot = (options) => {
|
|
12
|
+
// options must be an Object
|
|
13
|
+
const isObject = shouldBeObject(options);
|
|
14
|
+
if (!isObject.flag) {
|
|
15
|
+
const res = { errMsg: `showTabBarRedDot:fail ${isObject.msg}` };
|
|
16
|
+
console.error(res.errMsg);
|
|
17
|
+
return Promise.reject(res);
|
|
18
|
+
}
|
|
19
|
+
const { index, success, fail, complete } = options;
|
|
20
|
+
const handle = new MethodHandler({ name: 'showTabBarRedDot', success, fail, complete });
|
|
21
|
+
if (typeof index !== 'number') {
|
|
22
|
+
return handle.fail({
|
|
23
|
+
errMsg: getParameterError({
|
|
24
|
+
para: 'index',
|
|
25
|
+
correct: 'Number',
|
|
26
|
+
wrong: index
|
|
27
|
+
})
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
return new Promise((resolve, reject) => {
|
|
31
|
+
Taro.eventCenter.trigger('__taroShowTabBarRedDotHandler', {
|
|
32
|
+
index,
|
|
33
|
+
successHandler: (res = {}) => handle.success(res, resolve),
|
|
34
|
+
errorHandler: (res = {}) => handle.fail(res, reject)
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* 显示 tabBar
|
|
40
|
+
*/
|
|
41
|
+
export const showTabBar = (options = {}) => {
|
|
42
|
+
// options must be an Object
|
|
43
|
+
const isObject = shouldBeObject(options);
|
|
44
|
+
if (!isObject.flag) {
|
|
45
|
+
const res = { errMsg: `showTabBar:fail ${isObject.msg}` };
|
|
46
|
+
console.error(res.errMsg);
|
|
47
|
+
return Promise.reject(res);
|
|
48
|
+
}
|
|
49
|
+
const { animation, success, fail, complete } = options;
|
|
50
|
+
const handle = new MethodHandler({ name: 'showTabBar', success, fail, complete });
|
|
51
|
+
if (options.hasOwnProperty('animation') && typeof animation !== 'boolean') {
|
|
52
|
+
return handle.fail({
|
|
53
|
+
errMsg: getParameterError({
|
|
54
|
+
para: 'animation',
|
|
55
|
+
correct: 'Boolean',
|
|
56
|
+
wrong: animation
|
|
57
|
+
})
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
return new Promise((resolve, reject) => {
|
|
61
|
+
Taro.eventCenter.trigger('__taroShowTabBar', {
|
|
62
|
+
animation,
|
|
63
|
+
successHandler: (res = {}) => handle.success(res, resolve),
|
|
64
|
+
errorHandler: (res = {}) => handle.fail(res, reject)
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* 动态设置 tabBar 的整体样式
|
|
70
|
+
*/
|
|
71
|
+
export const setTabBarStyle = (options = {}) => {
|
|
72
|
+
// options must be an Object
|
|
73
|
+
const isObject = shouldBeObject(options);
|
|
74
|
+
if (!isObject.flag) {
|
|
75
|
+
const res = { errMsg: `setTabBarStyle:fail ${isObject.msg}` };
|
|
76
|
+
console.error(res.errMsg);
|
|
77
|
+
return Promise.reject(res);
|
|
78
|
+
}
|
|
79
|
+
const { color, selectedColor, backgroundColor, borderStyle, success, fail, complete } = options;
|
|
80
|
+
const handle = new MethodHandler({ name: 'setTabBarStyle', success, fail, complete });
|
|
81
|
+
let errMsg;
|
|
82
|
+
if (color && !isValidColor(color)) {
|
|
83
|
+
errMsg = 'color';
|
|
84
|
+
}
|
|
85
|
+
else if (selectedColor && !isValidColor(selectedColor)) {
|
|
86
|
+
errMsg = 'selectedColor';
|
|
87
|
+
}
|
|
88
|
+
else if (backgroundColor && !isValidColor(backgroundColor)) {
|
|
89
|
+
errMsg = 'backgroundColor';
|
|
90
|
+
}
|
|
91
|
+
else if (borderStyle && !/^(black|white)$/.test(borderStyle)) {
|
|
92
|
+
errMsg = 'borderStyle';
|
|
93
|
+
}
|
|
94
|
+
if (errMsg) {
|
|
95
|
+
return handle.fail({ errMsg: `invalid ${errMsg}` });
|
|
96
|
+
}
|
|
97
|
+
if (!tabConf) {
|
|
98
|
+
return handle.fail();
|
|
99
|
+
}
|
|
100
|
+
const obj = {};
|
|
101
|
+
if (color)
|
|
102
|
+
obj.color = color;
|
|
103
|
+
if (selectedColor)
|
|
104
|
+
obj.selectedColor = selectedColor;
|
|
105
|
+
if (backgroundColor)
|
|
106
|
+
obj.backgroundColor = backgroundColor;
|
|
107
|
+
if (borderStyle)
|
|
108
|
+
obj.borderStyle = borderStyle;
|
|
109
|
+
return new Promise((resolve, reject) => {
|
|
110
|
+
Taro.eventCenter.trigger('__taroSetTabBarStyle', {
|
|
111
|
+
color,
|
|
112
|
+
selectedColor,
|
|
113
|
+
backgroundColor,
|
|
114
|
+
borderStyle,
|
|
115
|
+
successHandler: (res = {}) => handle.success(res, resolve),
|
|
116
|
+
errorHandler: (res = {}) => handle.fail(res, reject)
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
};
|
|
120
|
+
/**
|
|
121
|
+
* 动态设置 tabBar 某一项的内容
|
|
122
|
+
*/
|
|
123
|
+
export const setTabBarItem = (options) => {
|
|
124
|
+
// options must be an Object
|
|
125
|
+
const isObject = shouldBeObject(options);
|
|
126
|
+
if (!isObject.flag) {
|
|
127
|
+
const res = { errMsg: `setTabBarItem:fail ${isObject.msg}` };
|
|
128
|
+
console.error(res.errMsg);
|
|
129
|
+
return Promise.reject(res);
|
|
130
|
+
}
|
|
131
|
+
const { index, text, iconPath, selectedIconPath, success, fail, complete } = options;
|
|
132
|
+
const handle = new MethodHandler({ name: 'setTabBarItem', success, fail, complete });
|
|
133
|
+
if (typeof index !== 'number') {
|
|
134
|
+
return handle.fail({
|
|
135
|
+
errMsg: getParameterError({
|
|
136
|
+
para: 'index',
|
|
137
|
+
correct: 'Number',
|
|
138
|
+
wrong: index
|
|
139
|
+
})
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
return new Promise((resolve, reject) => {
|
|
143
|
+
Taro.eventCenter.trigger('__taroSetTabBarItem', {
|
|
144
|
+
index,
|
|
145
|
+
text,
|
|
146
|
+
iconPath,
|
|
147
|
+
selectedIconPath,
|
|
148
|
+
successHandler: (res = {}) => handle.success(res, resolve),
|
|
149
|
+
errorHandler: (res = {}) => handle.fail(res, reject)
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
};
|
|
153
|
+
/**
|
|
154
|
+
* 为 tabBar 某一项的右上角添加文本
|
|
155
|
+
*/
|
|
156
|
+
export const setTabBarBadge = (options) => {
|
|
157
|
+
// options must be an Object
|
|
158
|
+
const isObject = shouldBeObject(options);
|
|
159
|
+
if (!isObject.flag) {
|
|
160
|
+
const res = { errMsg: `setTabBarBadge:fail ${isObject.msg}` };
|
|
161
|
+
console.error(res.errMsg);
|
|
162
|
+
return Promise.reject(res);
|
|
163
|
+
}
|
|
164
|
+
const { index, text, success, fail, complete } = options;
|
|
165
|
+
const handle = new MethodHandler({ name: 'setTabBarBadge', success, fail, complete });
|
|
166
|
+
if (typeof index !== 'number') {
|
|
167
|
+
return handle.fail({
|
|
168
|
+
errMsg: getParameterError({
|
|
169
|
+
para: 'index',
|
|
170
|
+
correct: 'Number',
|
|
171
|
+
wrong: index
|
|
172
|
+
})
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
if (typeof text !== 'string') {
|
|
176
|
+
return handle.fail({
|
|
177
|
+
errMsg: getParameterError({
|
|
178
|
+
para: 'text',
|
|
179
|
+
correct: 'String',
|
|
180
|
+
wrong: text
|
|
181
|
+
})
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
return new Promise((resolve, reject) => {
|
|
185
|
+
Taro.eventCenter.trigger('__taroSetTabBarBadge', {
|
|
186
|
+
index,
|
|
187
|
+
text,
|
|
188
|
+
successHandler: (res = {}) => handle.success(res, resolve),
|
|
189
|
+
errorHandler: (res = {}) => handle.fail(res, reject)
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
};
|
|
193
|
+
/**
|
|
194
|
+
* 移除 tabBar 某一项右上角的文本
|
|
195
|
+
*/
|
|
196
|
+
export const removeTabBarBadge = (options) => {
|
|
197
|
+
// options must be an Object
|
|
198
|
+
const isObject = shouldBeObject(options);
|
|
199
|
+
if (!isObject.flag) {
|
|
200
|
+
const res = { errMsg: `removeTabBarBadge:fail ${isObject.msg}` };
|
|
201
|
+
console.error(res.errMsg);
|
|
202
|
+
return Promise.reject(res);
|
|
203
|
+
}
|
|
204
|
+
const { index, success, fail, complete } = options;
|
|
205
|
+
const handle = new MethodHandler({ name: 'removeTabBarBadge', success, fail, complete });
|
|
206
|
+
if (typeof index !== 'number') {
|
|
207
|
+
return handle.fail({
|
|
208
|
+
errMsg: getParameterError({
|
|
209
|
+
para: 'index',
|
|
210
|
+
correct: 'Number',
|
|
211
|
+
wrong: index
|
|
212
|
+
})
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
return new Promise((resolve, reject) => {
|
|
216
|
+
Taro.eventCenter.trigger('__taroRemoveTabBarBadge', {
|
|
217
|
+
index,
|
|
218
|
+
successHandler: (res = {}) => handle.success(res, resolve),
|
|
219
|
+
errorHandler: (res = {}) => handle.fail(res, reject)
|
|
220
|
+
});
|
|
221
|
+
});
|
|
222
|
+
};
|
|
223
|
+
/**
|
|
224
|
+
* 隐藏 tabBar 某一项的右上角的红点
|
|
225
|
+
*/
|
|
226
|
+
export const hideTabBarRedDot = (options) => {
|
|
227
|
+
// options must be an Object
|
|
228
|
+
const isObject = shouldBeObject(options);
|
|
229
|
+
if (!isObject.flag) {
|
|
230
|
+
const res = { errMsg: `hideTabBarRedDot:fail ${isObject.msg}` };
|
|
231
|
+
console.error(res.errMsg);
|
|
232
|
+
return Promise.reject(res);
|
|
233
|
+
}
|
|
234
|
+
const { index, success, fail, complete } = options;
|
|
235
|
+
const handle = new MethodHandler({ name: 'hideTabBarRedDot', success, fail, complete });
|
|
236
|
+
if (typeof index !== 'number') {
|
|
237
|
+
return handle.fail({
|
|
238
|
+
errMsg: getParameterError({
|
|
239
|
+
para: 'index',
|
|
240
|
+
correct: 'Number',
|
|
241
|
+
wrong: index
|
|
242
|
+
})
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
return new Promise((resolve, reject) => {
|
|
246
|
+
Taro.eventCenter.trigger('__taroHideTabBarRedDotHandler', {
|
|
247
|
+
index,
|
|
248
|
+
successHandler: (res = {}) => handle.success(res, resolve),
|
|
249
|
+
errorHandler: (res = {}) => handle.fail(res, reject)
|
|
250
|
+
});
|
|
251
|
+
});
|
|
252
|
+
};
|
|
253
|
+
/**
|
|
254
|
+
* 隐藏 tabBar
|
|
255
|
+
*/
|
|
256
|
+
export const hideTabBar = (options = {}) => {
|
|
257
|
+
// options must be an Object
|
|
258
|
+
const isObject = shouldBeObject(options);
|
|
259
|
+
if (!isObject.flag) {
|
|
260
|
+
const res = { errMsg: `hideTabBar:fail ${isObject.msg}` };
|
|
261
|
+
console.error(res.errMsg);
|
|
262
|
+
return Promise.reject(res);
|
|
263
|
+
}
|
|
264
|
+
const { animation, success, fail, complete } = options;
|
|
265
|
+
const handle = new MethodHandler({ name: 'hideTabBar', success, fail, complete });
|
|
266
|
+
if (options.hasOwnProperty('animation') && typeof animation !== 'boolean') {
|
|
267
|
+
return handle.fail({
|
|
268
|
+
errMsg: getParameterError({
|
|
269
|
+
para: 'animation',
|
|
270
|
+
correct: 'Boolean',
|
|
271
|
+
wrong: animation
|
|
272
|
+
})
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
return new Promise((resolve, reject) => {
|
|
276
|
+
Taro.eventCenter.trigger('__taroHideTabBar', {
|
|
277
|
+
animation,
|
|
278
|
+
successHandler: (res = {}) => handle.success(res, resolve),
|
|
279
|
+
errorHandler: (res = {}) => handle.fail(res, reject)
|
|
280
|
+
});
|
|
281
|
+
});
|
|
282
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
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
|
+
/**
|
|
11
|
+
* 设置窗口大小,该接口仅适用于 PC 平台,使用细则请参见指南
|
|
12
|
+
*/
|
|
13
|
+
export const setWindowSize = temporarilyNotSupport('setWindowSize');
|
|
14
|
+
/**
|
|
15
|
+
* 监听窗口尺寸变化事件
|
|
16
|
+
*/
|
|
17
|
+
export const onWindowResize = callback => {
|
|
18
|
+
callbackManager.add(callback);
|
|
19
|
+
if (callbackManager.count() === 1) {
|
|
20
|
+
window.addEventListener('resize', resizeListener);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* 取消监听窗口尺寸变化事件
|
|
25
|
+
*/
|
|
26
|
+
export const offWindowResize = callback => {
|
|
27
|
+
callbackManager.remove(callback);
|
|
28
|
+
if (callbackManager.count() === 0) {
|
|
29
|
+
window.removeEventListener('resize', resizeListener);
|
|
30
|
+
}
|
|
31
|
+
};
|