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()
});
window.setInterval(() => {
if (leftSec <= 0) {
window.clearInterval();
toast.clear();
return;
}
if (leftSec <= 1) {
window.clearInterval();
toast.message = '跳转中...'

View File

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

View File

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