feat: 简化toast为单个intance

This commit is contained in:
jiangruowei 2017-03-30 17:23:38 +08:00
parent 50d87fa634
commit 9e0a6bb984
3 changed files with 11 additions and 13 deletions

View File

@ -39,6 +39,11 @@ export default {
message: leftSec.toString() message: leftSec.toString()
}); });
window.setInterval(() => { window.setInterval(() => {
if (leftSec <= 0) {
window.clearInterval();
toast.clear();
return;
}
if (leftSec <= 1) { if (leftSec <= 1) {
window.clearInterval(); window.clearInterval();
toast.message = '跳转中...' toast.message = '跳转中...'

View File

@ -2,24 +2,18 @@ import Vue from 'vue';
import merge from 'src/utils/merge'; import merge from 'src/utils/merge';
const ToastConstructor = Vue.extend(require('./toast.vue')); const ToastConstructor = Vue.extend(require('./toast.vue'));
let toastQueue = []; let instance;
const getInstance = () => { const getInstance = () => {
if (toastQueue.length > 0) { if (instance) {
const instance = toastQueue[0]; instance.clear();
toastQueue.splice(0, 1);
return instance;
} }
return new ToastConstructor({ instance = new ToastConstructor({
el: document.createElement('div') el: document.createElement('div')
}); });
return instance;
}; };
const returnInstance = instance => {
if (instance) {
toastQueue.push(instance);
}
};
const removeDom = event => { const removeDom = event => {
if (event.target.parentNode) { if (event.target.parentNode) {
@ -31,7 +25,6 @@ var Toast = (options = {}) => {
const duration = options.duration || 3000; const duration = options.duration || 3000;
let instance = getInstance(); let instance = getInstance();
returnInstance(instance);
instance.closed = false; instance.closed = false;
clearTimeout(instance.timer); clearTimeout(instance.timer);
instance.type = options.type ? options.type : 'text'; instance.type = options.type ? options.type : 'text';

View File

@ -44,7 +44,7 @@
} }
.zan-toast__text { .zan-toast__text {
padding-bottom: 20px; padding: 15px 0 20px;
font-size: 14px; font-size: 14px;
} }
} }