import {Message, MessageBox} from 'element-ui' import i18n from '../i18n' /** * 提示与加载工具类 */ export default class Tips { static toast(text) { Message(text) } /** * 警告框 */ static alert(text) { Message({ message: text, type: 'warning', duration: 1500 }) } static alertTo(text, title = i18n.t('prompt.title'), confirmText = i18n.t('confirm')) { return new Promise((resolve, reject) => { MessageBox.alert(text, title, { confirmButtonText: confirmText, callback: action => { resolve() } }) }) } /** * 弹出确认窗口 */ static confirm(text, title = i18n.t('prompt.title'), confirmText = i18n.t('confirm'), cancelText = i18n.t('cancel')) { return new Promise((resolve) => { MessageBox.confirm(text, title, { confirmButtonText: confirmText, cancelButtonText: cancelText, type: 'warning' }).then(() => { resolve(true) }).catch(() => { resolve(false) }) }) } static success(text = i18n.t('prompt.success'), duration = 500) { Message({ message: text, type: 'success', duration: 1000, onClose: () => { return new Promise((resolve) => { setTimeout(() => { resolve() }, duration) }) } }) } /** * 错误框 */ static error(text) { Message({ message: text, type: 'error', duration: 1500 }) } }