@tarojs/taro-h5 3.4.0-beta.2 → 3.4.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/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 +5 -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.js +187 -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 +12 -0
- package/dist/api/cloud/index.js +21 -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 +21 -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 +23 -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/network.js +78 -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 +13 -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/EditorContext.js +19 -0
- package/dist/api/media/audio/InnerAudioContext.js +84 -0
- package/dist/api/media/audio/index.js +15 -0
- package/dist/api/media/background-audio/BackgroundAudioManager.js +86 -0
- package/dist/api/media/background-audio/index.js +15 -0
- package/dist/api/media/camera.js +3 -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 +12 -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 +146 -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 +288 -0
- package/dist/api/ui/background.js +4 -0
- package/dist/api/ui/custom-component.js +3 -0
- package/dist/api/ui/fonts.js +51 -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 +172 -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 +5028 -6988
- package/dist/index.js +4 -10767
- package/dist/taroApis.js +1 -1
- package/dist/types/type.js +2 -0
- package/package.json +11 -13
- package/src/api/ai/visual.ts +3 -0
- package/src/api/base/system.ts +207 -0
- package/src/api/canvas/CanvasContext.ts +42 -39
- package/src/api/canvas/createCanvasContext.ts +2 -2
- package/src/api/canvas/index.ts +10 -2
- package/src/api/cloud/index.ts +4 -0
- package/src/api/device/battery.ts +18 -1
- package/src/api/device/index.ts +1 -0
- package/src/api/{base/system → device}/network.ts +35 -15
- package/src/api/device/wifi.ts +1 -0
- package/src/api/location/chooseLocation.ts +2 -2
- package/src/api/media/{editor.ts → EditorContext.ts} +2 -0
- package/src/api/media/audio/InnerAudioContext.ts +98 -0
- package/src/api/media/audio/index.ts +1 -86
- package/src/api/media/background-audio/BackgroundAudioManager.ts +103 -0
- package/src/api/media/{background-audio.ts → background-audio/index.ts} +7 -2
- package/src/api/media/image/previewImage.ts +4 -25
- package/src/api/media/index.ts +0 -1
- package/src/api/network/download.ts +5 -5
- package/src/api/network/upload.ts +7 -13
- package/src/api/network/websocket/index.ts +1 -1
- package/src/api/ui/animation/index.ts +11 -12
- package/src/api/ui/fonts.ts +61 -2
- package/src/api/ui/interaction/index.ts +12 -10
- package/src/api/ui/navigation-bar/index.ts +2 -2
- package/src/api/ui/scroll/index.ts +3 -3
- package/src/api/utils/handler.ts +4 -4
- package/src/api/utils/index.ts +34 -13
- package/src/api/wxml/nodesRef.ts +10 -3
- package/src/api/wxml/selectorQuery.ts +68 -23
- package/src/index.ts +2 -2
- package/src/api/base/system/index.ts +0 -2
- package/src/api/base/system/info.ts +0 -64
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
import Taro from '@tarojs/api';
|
|
2
|
+
import { getParameterError, temporarilyNotSupport } from '../../utils';
|
|
3
|
+
import { MethodHandler } from '../../utils/handler';
|
|
4
|
+
import Toast from './toast';
|
|
5
|
+
import Modal from './modal';
|
|
6
|
+
import ActionSheet from './actionSheet';
|
|
7
|
+
// 交互
|
|
8
|
+
let status = 'default';
|
|
9
|
+
// inject necessary style
|
|
10
|
+
function init(doc) {
|
|
11
|
+
if (status === 'ready')
|
|
12
|
+
return;
|
|
13
|
+
const taroStyle = doc.createElement('style');
|
|
14
|
+
taroStyle.textContent = '@font-face{font-weight:normal;font-style:normal;font-family:"taro";src:url("data:application/x-font-ttf;charset=utf-8;base64, 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") format("truetype");}@-webkit-keyframes taroLoading{0%{-webkit-transform:rotate3d(0, 0, 1, 0deg);}100%{-webkit-transform:rotate3d(0, 0, 1, 360deg);transform:rotate3d(0, 0, 1, 360deg);}}@keyframes taroLoading{0%{-webkit-transform:rotate3d(0, 0, 1, 0deg);}100%{-webkit-transform:rotate3d(0, 0, 1, 360deg);transform:rotate3d(0, 0, 1, 360deg);}}.taro-modal__foot:after {content: "";position: absolute;left: 0;top: 0;right: 0;height: 1px;border-top: 1px solid #D5D5D6;color: #D5D5D6;-webkit-transform-origin: 0 0;transform-origin: 0 0;-webkit-transform: scaleY(0.5);transform: scaleY(0.5);} .taro-model__btn:active {background-color: #EEEEEE}.taro-model__btn:not(:first-child):after {content: "";position: absolute;left: 0;top: 0;width: 1px;bottom: 0;border-left: 1px solid #D5D5D6;color: #D5D5D6;-webkit-transform-origin: 0 0;transform-origin: 0 0;-webkit-transform: scaleX(0.5);transform: scaleX(0.5);}.taro-actionsheet__cell:not(:first-child):after {content: "";position: absolute;left: 0;top: 0;right: 0;height: 1px;border-top: 1px solid #e5e5e5;color: #e5e5e5;-webkit-transform-origin: 0 0;transform-origin: 0 0;-webkit-transform: scaleY(0.5);transform: scaleY(0.5);}';
|
|
15
|
+
doc.querySelector('head').appendChild(taroStyle);
|
|
16
|
+
status = 'ready';
|
|
17
|
+
}
|
|
18
|
+
const toast = new Toast();
|
|
19
|
+
const modal = new Modal();
|
|
20
|
+
const actionSheet = new ActionSheet();
|
|
21
|
+
const showToast = (options = { title: '' }) => {
|
|
22
|
+
init(document);
|
|
23
|
+
options = Object.assign({
|
|
24
|
+
title: '',
|
|
25
|
+
icon: 'success',
|
|
26
|
+
image: '',
|
|
27
|
+
duration: 1500,
|
|
28
|
+
mask: false
|
|
29
|
+
}, options);
|
|
30
|
+
const { success, fail, complete } = options;
|
|
31
|
+
const handle = new MethodHandler({ name: 'showToast', success, fail, complete });
|
|
32
|
+
if (typeof options.title !== 'string') {
|
|
33
|
+
return handle.fail({
|
|
34
|
+
errMsg: getParameterError({
|
|
35
|
+
para: 'title',
|
|
36
|
+
correct: 'String',
|
|
37
|
+
wrong: options.title
|
|
38
|
+
})
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
if (typeof options.duration !== 'number') {
|
|
42
|
+
return handle.fail({
|
|
43
|
+
errMsg: getParameterError({
|
|
44
|
+
para: 'duration',
|
|
45
|
+
correct: 'Number',
|
|
46
|
+
wrong: options.duration
|
|
47
|
+
})
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
if (options.image && typeof options.image !== 'string')
|
|
51
|
+
options.image = '';
|
|
52
|
+
options.mask = !!options.mask;
|
|
53
|
+
let errMsg = '';
|
|
54
|
+
if (!toast.el) {
|
|
55
|
+
errMsg = toast.create(options, 'toast');
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
errMsg = toast.show(options, 'toast');
|
|
59
|
+
}
|
|
60
|
+
return handle.success({ errMsg });
|
|
61
|
+
};
|
|
62
|
+
const hideToast = ({ success, fail, complete } = {}) => {
|
|
63
|
+
const handle = new MethodHandler({ name: 'hideToast', success, fail, complete });
|
|
64
|
+
if (!toast.el)
|
|
65
|
+
return handle.success();
|
|
66
|
+
toast.hide(0, 'toast');
|
|
67
|
+
return handle.success();
|
|
68
|
+
};
|
|
69
|
+
const showLoading = (options = { title: '' }) => {
|
|
70
|
+
init(document);
|
|
71
|
+
options = Object.assign({
|
|
72
|
+
title: '',
|
|
73
|
+
mask: false
|
|
74
|
+
}, options);
|
|
75
|
+
const { success, fail, complete } = options;
|
|
76
|
+
const handle = new MethodHandler({ name: 'showLoading', success, fail, complete });
|
|
77
|
+
const config = {
|
|
78
|
+
icon: 'loading',
|
|
79
|
+
image: '',
|
|
80
|
+
duration: -1
|
|
81
|
+
};
|
|
82
|
+
options = Object.assign({}, options, config);
|
|
83
|
+
if (typeof options.title !== 'string') {
|
|
84
|
+
return handle.fail({
|
|
85
|
+
errMsg: getParameterError({
|
|
86
|
+
para: 'title',
|
|
87
|
+
correct: 'String',
|
|
88
|
+
wrong: options.title
|
|
89
|
+
})
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
options.mask = !!options.mask;
|
|
93
|
+
let errMsg = '';
|
|
94
|
+
if (!toast.el) {
|
|
95
|
+
errMsg = toast.create(options, 'loading');
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
errMsg = toast.show(options, 'loading');
|
|
99
|
+
}
|
|
100
|
+
return handle.success({ errMsg });
|
|
101
|
+
};
|
|
102
|
+
const hideLoading = ({ success, fail, complete } = {}) => {
|
|
103
|
+
const handle = new MethodHandler({ name: 'hideLoading', success, fail, complete });
|
|
104
|
+
if (!toast.el)
|
|
105
|
+
return handle.success();
|
|
106
|
+
toast.hide(0, 'loading');
|
|
107
|
+
return handle.success();
|
|
108
|
+
};
|
|
109
|
+
const showModal = async (options = {}) => {
|
|
110
|
+
init(document);
|
|
111
|
+
options = Object.assign({
|
|
112
|
+
title: '',
|
|
113
|
+
content: '',
|
|
114
|
+
showCancel: true,
|
|
115
|
+
cancelText: '取消',
|
|
116
|
+
cancelColor: '#000000',
|
|
117
|
+
confirmText: '确定',
|
|
118
|
+
confirmColor: '#3CC51F'
|
|
119
|
+
}, options);
|
|
120
|
+
const { success, fail, complete } = options;
|
|
121
|
+
const handle = new MethodHandler({ name: 'showModal', success, fail, complete });
|
|
122
|
+
if (typeof options.title !== 'string') {
|
|
123
|
+
return handle.fail({
|
|
124
|
+
errMsg: getParameterError({
|
|
125
|
+
para: 'title',
|
|
126
|
+
correct: 'String',
|
|
127
|
+
wrong: options.title
|
|
128
|
+
})
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
if (typeof options.content !== 'string') {
|
|
132
|
+
return handle.fail({
|
|
133
|
+
errMsg: getParameterError({
|
|
134
|
+
para: 'content',
|
|
135
|
+
correct: 'String',
|
|
136
|
+
wrong: options.content
|
|
137
|
+
})
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
if (typeof options.cancelText !== 'string') {
|
|
141
|
+
return handle.fail({
|
|
142
|
+
errMsg: getParameterError({
|
|
143
|
+
para: 'cancelText',
|
|
144
|
+
correct: 'String',
|
|
145
|
+
wrong: options.cancelText
|
|
146
|
+
})
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
if (options.cancelText.replace(/[\u0391-\uFFE5]/g, 'aa').length > 8) {
|
|
150
|
+
return handle.fail({
|
|
151
|
+
errMsg: 'cancelText length should not larger then 4 Chinese characters'
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
if (typeof options.confirmText !== 'string') {
|
|
155
|
+
return handle.fail({
|
|
156
|
+
errMsg: getParameterError({
|
|
157
|
+
para: 'confirmText',
|
|
158
|
+
correct: 'String',
|
|
159
|
+
wrong: options.confirmText
|
|
160
|
+
})
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
if (options.confirmText.replace(/[\u0391-\uFFE5]/g, 'aa').length > 8) {
|
|
164
|
+
return handle.fail({
|
|
165
|
+
errMsg: 'confirmText length should not larger then 4 Chinese characters'
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
if (typeof options.cancelColor !== 'string') {
|
|
169
|
+
return handle.fail({
|
|
170
|
+
errMsg: getParameterError({
|
|
171
|
+
para: 'cancelColor',
|
|
172
|
+
correct: 'String',
|
|
173
|
+
wrong: options.cancelColor
|
|
174
|
+
})
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
if (typeof options.confirmColor !== 'string') {
|
|
178
|
+
return handle.fail({
|
|
179
|
+
errMsg: getParameterError({
|
|
180
|
+
para: 'confirmColor',
|
|
181
|
+
correct: 'String',
|
|
182
|
+
wrong: options.confirmColor
|
|
183
|
+
})
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
options.showCancel = !!options.showCancel;
|
|
187
|
+
let result = '';
|
|
188
|
+
if (!modal.el) {
|
|
189
|
+
result = await modal.create(options);
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
result = await modal.show(options);
|
|
193
|
+
}
|
|
194
|
+
const res = { cancel: !1, confirm: !1 };
|
|
195
|
+
res[result] = !0;
|
|
196
|
+
return handle.success(res);
|
|
197
|
+
};
|
|
198
|
+
function hideModal() {
|
|
199
|
+
if (!modal.el)
|
|
200
|
+
return;
|
|
201
|
+
modal.hide();
|
|
202
|
+
}
|
|
203
|
+
const showActionSheet = async (options = { itemList: [] }) => {
|
|
204
|
+
init(document);
|
|
205
|
+
options = Object.assign({
|
|
206
|
+
itemColor: '#000000',
|
|
207
|
+
itemList: []
|
|
208
|
+
}, options);
|
|
209
|
+
const { success, fail, complete } = options;
|
|
210
|
+
const handle = new MethodHandler({ name: 'showActionSheet', success, fail, complete });
|
|
211
|
+
// list item String
|
|
212
|
+
if (!Array.isArray(options.itemList)) {
|
|
213
|
+
return handle.fail({
|
|
214
|
+
errMsg: getParameterError({
|
|
215
|
+
para: 'itemList',
|
|
216
|
+
correct: 'Array',
|
|
217
|
+
wrong: options.itemList
|
|
218
|
+
})
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
if (options.itemList.length < 1) {
|
|
222
|
+
return handle.fail({ errMsg: 'parameter error: parameter.itemList should have at least 1 item' });
|
|
223
|
+
}
|
|
224
|
+
if (options.itemList.length > 6) {
|
|
225
|
+
return handle.fail({ errMsg: 'parameter error: parameter.itemList should not be large than 6' });
|
|
226
|
+
}
|
|
227
|
+
for (let i = 0; i < options.itemList.length; i++) {
|
|
228
|
+
if (typeof options.itemList[i] !== 'string') {
|
|
229
|
+
return handle.fail({
|
|
230
|
+
errMsg: getParameterError({
|
|
231
|
+
para: `itemList[${i}]`,
|
|
232
|
+
correct: 'String',
|
|
233
|
+
wrong: options.itemList[i]
|
|
234
|
+
})
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
if (typeof options.itemColor !== 'string') {
|
|
239
|
+
return handle.fail({
|
|
240
|
+
errMsg: getParameterError({
|
|
241
|
+
para: 'itemColor',
|
|
242
|
+
correct: 'String',
|
|
243
|
+
wrong: options.itemColor
|
|
244
|
+
})
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
let result = '';
|
|
248
|
+
if (!actionSheet.el) {
|
|
249
|
+
result = await actionSheet.create(options);
|
|
250
|
+
}
|
|
251
|
+
else {
|
|
252
|
+
result = await actionSheet.show(options);
|
|
253
|
+
}
|
|
254
|
+
if (typeof result === 'string') {
|
|
255
|
+
return handle.fail(({ errMsg: result }));
|
|
256
|
+
}
|
|
257
|
+
else {
|
|
258
|
+
return handle.success(({ tapIndex: result }));
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
Taro.eventCenter.on('__taroRouterChange', () => {
|
|
262
|
+
hideToast();
|
|
263
|
+
hideLoading();
|
|
264
|
+
hideModal();
|
|
265
|
+
});
|
|
266
|
+
const enableAlertBeforeUnload = temporarilyNotSupport('enableAlertBeforeUnload');
|
|
267
|
+
const disableAlertBeforeUnload = temporarilyNotSupport('disableAlertBeforeUnload');
|
|
268
|
+
export { showToast, showModal, showLoading, showActionSheet, hideToast, hideLoading, enableAlertBeforeUnload, disableAlertBeforeUnload };
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { inlineStyle } from '../../utils';
|
|
2
|
+
export default class Modal {
|
|
3
|
+
constructor() {
|
|
4
|
+
this.options = {
|
|
5
|
+
title: '',
|
|
6
|
+
content: '',
|
|
7
|
+
showCancel: true,
|
|
8
|
+
cancelText: '取消',
|
|
9
|
+
cancelColor: '#000000',
|
|
10
|
+
confirmText: '确定',
|
|
11
|
+
confirmColor: '#3CC51F'
|
|
12
|
+
};
|
|
13
|
+
this.style = {
|
|
14
|
+
maskStyle: {
|
|
15
|
+
position: 'fixed',
|
|
16
|
+
'z-index': '1000',
|
|
17
|
+
top: '0',
|
|
18
|
+
right: '0',
|
|
19
|
+
left: '0',
|
|
20
|
+
bottom: '0',
|
|
21
|
+
background: 'rgba(0,0,0,0.6)'
|
|
22
|
+
},
|
|
23
|
+
modalStyle: {
|
|
24
|
+
'z-index': '4999',
|
|
25
|
+
position: 'fixed',
|
|
26
|
+
top: '50%',
|
|
27
|
+
left: '50%',
|
|
28
|
+
transform: 'translate(-50%, -50%)',
|
|
29
|
+
width: '80%',
|
|
30
|
+
'max-width': '300px',
|
|
31
|
+
'border-radius': '3px',
|
|
32
|
+
'text-align': 'center',
|
|
33
|
+
'line-height': '1.6',
|
|
34
|
+
overflow: 'hidden',
|
|
35
|
+
background: '#FFFFFF'
|
|
36
|
+
},
|
|
37
|
+
titleStyle: {
|
|
38
|
+
padding: '20px 24px 9px',
|
|
39
|
+
'font-size': '18px'
|
|
40
|
+
},
|
|
41
|
+
textStyle: {
|
|
42
|
+
padding: '0 24px 12px',
|
|
43
|
+
'min-height': '40px',
|
|
44
|
+
'font-size': '15px',
|
|
45
|
+
'line-height': '1.3',
|
|
46
|
+
color: '#808080'
|
|
47
|
+
},
|
|
48
|
+
footStyle: {
|
|
49
|
+
position: 'relative',
|
|
50
|
+
'line-height': '48px',
|
|
51
|
+
'font-size': '18px',
|
|
52
|
+
display: 'flex'
|
|
53
|
+
},
|
|
54
|
+
btnStyle: {
|
|
55
|
+
position: 'relative',
|
|
56
|
+
'-webkit-box-flex': '1',
|
|
57
|
+
'-webkit-flex': '1',
|
|
58
|
+
flex: '1'
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
create(options = {}) {
|
|
63
|
+
return new Promise((resolve) => {
|
|
64
|
+
// style
|
|
65
|
+
const { maskStyle, modalStyle, titleStyle, textStyle, footStyle, btnStyle } = this.style;
|
|
66
|
+
// configuration
|
|
67
|
+
const config = {
|
|
68
|
+
...this.options,
|
|
69
|
+
...options
|
|
70
|
+
};
|
|
71
|
+
// wrapper
|
|
72
|
+
this.el = document.createElement('div');
|
|
73
|
+
this.el.className = 'taro__modal';
|
|
74
|
+
this.el.style.opacity = '0';
|
|
75
|
+
this.el.style.transition = 'opacity 0.2s linear';
|
|
76
|
+
// mask
|
|
77
|
+
const mask = document.createElement('div');
|
|
78
|
+
mask.className = 'taro-modal__mask';
|
|
79
|
+
mask.setAttribute('style', inlineStyle(maskStyle));
|
|
80
|
+
// modal
|
|
81
|
+
const modal = document.createElement('div');
|
|
82
|
+
modal.className = 'taro-modal__content';
|
|
83
|
+
modal.setAttribute('style', inlineStyle(modalStyle));
|
|
84
|
+
// title
|
|
85
|
+
const titleCSS = config.title ? titleStyle : {
|
|
86
|
+
...titleStyle,
|
|
87
|
+
display: 'none'
|
|
88
|
+
};
|
|
89
|
+
this.title = document.createElement('div');
|
|
90
|
+
this.title.className = 'taro-modal__title';
|
|
91
|
+
this.title.setAttribute('style', inlineStyle(titleCSS));
|
|
92
|
+
this.title.textContent = config.title;
|
|
93
|
+
// text
|
|
94
|
+
const textCSS = config.title ? textStyle : {
|
|
95
|
+
...textStyle,
|
|
96
|
+
padding: '40px 20px 26px',
|
|
97
|
+
color: '#353535'
|
|
98
|
+
};
|
|
99
|
+
this.text = document.createElement('div');
|
|
100
|
+
this.text.className = 'taro-modal__text';
|
|
101
|
+
this.text.setAttribute('style', inlineStyle(textCSS));
|
|
102
|
+
this.text.textContent = config.content;
|
|
103
|
+
// foot
|
|
104
|
+
const foot = document.createElement('div');
|
|
105
|
+
foot.className = 'taro-modal__foot';
|
|
106
|
+
foot.setAttribute('style', inlineStyle(footStyle));
|
|
107
|
+
// cancel button
|
|
108
|
+
const cancelCSS = {
|
|
109
|
+
...btnStyle,
|
|
110
|
+
color: config.cancelColor,
|
|
111
|
+
display: config.showCancel ? 'block' : 'none'
|
|
112
|
+
};
|
|
113
|
+
this.cancel = document.createElement('div');
|
|
114
|
+
this.cancel.className = 'taro-model__btn taro-model__cancel';
|
|
115
|
+
this.cancel.setAttribute('style', inlineStyle(cancelCSS));
|
|
116
|
+
this.cancel.textContent = config.cancelText;
|
|
117
|
+
this.cancel.onclick = () => {
|
|
118
|
+
this.hide();
|
|
119
|
+
resolve('cancel');
|
|
120
|
+
};
|
|
121
|
+
// confirm button
|
|
122
|
+
this.confirm = document.createElement('div');
|
|
123
|
+
this.confirm.className = 'taro-model__btn taro-model__confirm';
|
|
124
|
+
this.confirm.setAttribute('style', inlineStyle(btnStyle));
|
|
125
|
+
this.confirm.style.color = config.confirmColor;
|
|
126
|
+
this.confirm.textContent = config.confirmText;
|
|
127
|
+
this.confirm.onclick = () => {
|
|
128
|
+
this.hide();
|
|
129
|
+
resolve('confirm');
|
|
130
|
+
};
|
|
131
|
+
// result
|
|
132
|
+
foot.appendChild(this.cancel);
|
|
133
|
+
foot.appendChild(this.confirm);
|
|
134
|
+
modal.appendChild(this.title);
|
|
135
|
+
modal.appendChild(this.text);
|
|
136
|
+
modal.appendChild(foot);
|
|
137
|
+
this.el.appendChild(mask);
|
|
138
|
+
this.el.appendChild(modal);
|
|
139
|
+
// show immediately
|
|
140
|
+
document.body.appendChild(this.el);
|
|
141
|
+
setTimeout(() => { this.el.style.opacity = '1'; }, 0);
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
show(options = {}) {
|
|
145
|
+
return new Promise((resolve) => {
|
|
146
|
+
const config = {
|
|
147
|
+
...this.options,
|
|
148
|
+
...options
|
|
149
|
+
};
|
|
150
|
+
if (this.hideOpacityTimer)
|
|
151
|
+
clearTimeout(this.hideOpacityTimer);
|
|
152
|
+
if (this.hideDisplayTimer)
|
|
153
|
+
clearTimeout(this.hideDisplayTimer);
|
|
154
|
+
// title & text
|
|
155
|
+
const { textStyle } = this.style;
|
|
156
|
+
if (config.title) {
|
|
157
|
+
this.title.textContent = config.title;
|
|
158
|
+
// none => block
|
|
159
|
+
this.title.style.display = 'block';
|
|
160
|
+
this.text.setAttribute('style', inlineStyle(textStyle));
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
// block => none
|
|
164
|
+
this.title.style.display = 'none';
|
|
165
|
+
const textCSS = {
|
|
166
|
+
...textStyle,
|
|
167
|
+
padding: '40px 20px 26px',
|
|
168
|
+
color: '#353535'
|
|
169
|
+
};
|
|
170
|
+
this.text.setAttribute('style', inlineStyle(textCSS));
|
|
171
|
+
}
|
|
172
|
+
this.text.textContent = config.content || '';
|
|
173
|
+
// showCancel
|
|
174
|
+
this.cancel.style.display = config.showCancel ? 'block' : 'none';
|
|
175
|
+
// cancelText
|
|
176
|
+
this.cancel.textContent = config.cancelText || '';
|
|
177
|
+
// cancelColor
|
|
178
|
+
this.cancel.style.color = config.cancelColor || '';
|
|
179
|
+
// confirmText
|
|
180
|
+
this.confirm.textContent = config.confirmText || '';
|
|
181
|
+
// confirmColor
|
|
182
|
+
this.confirm.style.color = config.confirmColor || '';
|
|
183
|
+
// cbs
|
|
184
|
+
this.cancel.onclick = () => {
|
|
185
|
+
this.hide();
|
|
186
|
+
resolve('cancel');
|
|
187
|
+
};
|
|
188
|
+
this.confirm.onclick = () => {
|
|
189
|
+
this.hide();
|
|
190
|
+
resolve('confirm');
|
|
191
|
+
};
|
|
192
|
+
// show
|
|
193
|
+
this.el.style.display = 'block';
|
|
194
|
+
setTimeout(() => { this.el.style.opacity = '1'; }, 0);
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
hide() {
|
|
198
|
+
if (this.hideOpacityTimer)
|
|
199
|
+
clearTimeout(this.hideOpacityTimer);
|
|
200
|
+
if (this.hideDisplayTimer)
|
|
201
|
+
clearTimeout(this.hideDisplayTimer);
|
|
202
|
+
this.hideOpacityTimer = setTimeout(() => {
|
|
203
|
+
this.el.style.opacity = '0';
|
|
204
|
+
this.hideDisplayTimer = setTimeout(() => { this.el.style.display = 'none'; }, 200);
|
|
205
|
+
}, 0);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
@@ -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
|
+
}
|