import './toast.css';
class Toast {
}
Toast.install = function (Vue, options) {
let opt = {
defaultType: 'bottom',
duration: '2500'
};
for (let property in options) {
opt[property] = options[property];
}
Vue.prototype.$toast = function (tips, type) {
let curType;
if (type) {
curType = type;
} else {
curType = opt.defaultType;
}
if (document.querySelector('.lx-toast')) {
// 如果toast还在,则不再执行
return;
}
const ToastTpl = Vue.extend({
template: '
' + tips + '
'
});
const tpl = new ToastTpl().$mount().$el;
document.body.appendChild(tpl);
setTimeout(function () {
document.body.removeChild(tpl);
}, opt.duration);
};
['bottom', 'center', 'top'].forEach(function (type) {
Vue.prototype.$toast[type] = function (tips) {
return Vue.prototype.$toast(tips, type);
};
});
Vue.prototype.$loading = function (tips, type = '') {
let load = document.querySelector('.lx-load-mark');
if (type === 'close') {
load && document.body.removeChild(load);
} else {
if (load) {
// 如果loading还在,则不再执行
return;
}
const LoadTpl = Vue.extend({
template: ''
});
const tpl = new LoadTpl().$mount().$el;
document.body.appendChild(tpl);
}
};
['open', 'close'].forEach(function (type) {
Vue.prototype.$loading[type] = function (tips) {
return Vue.prototype.$loading(tips, type);
};
});
};
export default Toast;