修复 toast 未传入 timeout 时不会自动关闭的问题 (#361)

This commit is contained in:
Yao 2018-07-12 22:03:09 +08:00 committed by GitHub
parent 12d7dcf7e9
commit e739520290
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,4 +1,5 @@
const TOAST_CONFIG_KEY = 'zanui.__zanToastPageConfig'; const TOAST_CONFIG_KEY = 'zanui.__zanToastPageConfig';
const DEFAULT_SHOW_TOAST_TIME = 3000;
let timeoutData = { let timeoutData = {
timeoutId: 0, timeoutId: 0,
@ -58,11 +59,13 @@ function Toast(optionsOrMsg, pageCtx) {
}); });
let timeoutId = 0; let timeoutId = 0;
// toast 计时如果小于0就不会去关闭。
if (parsedOptions.timeout >= 0) { // 如果不传,就取默认值
const timeoutOption = parsedOptions.timeout || DEFAULT_SHOW_TOAST_TIME;
if (timeoutOption >= 0) {
timeoutId = setTimeout(() => { timeoutId = setTimeout(() => {
toastCtx.clear(); toastCtx.clear();
}, parsedOptions.timeout || 3000); }, timeoutOption);
} }
@ -79,7 +82,7 @@ Toast.setDefaultOptions = function (options = {}, type = 'page') {
type: options.type || '', type: options.type || '',
icon: options.icon || '', icon: options.icon || '',
image: options.image || '', image: options.image || '',
timeout: options.timeout || 3000 timeout: options.timeout || DEFAULT_SHOW_TOAST_TIME
}; };
if (type === 'global') { if (type === 'global') {