import { ElLoading, ElMessage, ElNotification, ElMessageBox, Action } from 'element-plus'; let curMsg; let count = 0; let instance; import { i18n } from '../i18n'; const t = i18n.t; export function loading() { if (count === 0) { instance = ElLoading.service({ lock: true, text: t('base.loading'), spinner: 'el-icon-loading', background: 'rgba(0, 0, 0, 0.3)', }); } count++; } export function close() { if (count <= 0) { return; } if (--count === 0) { instance.close(); } } export function showMessage(type, info, unClose?) { if (curMsg != null) { curMsg.close(); } const tmp = ElMessage({ type: type, showClose: true, message: info, duration: 3000, offset: 50, }); if (!unClose) { curMsg = tmp; } } export function showNotify(type, title, message, position) { if (position == null) { position = 'top-right'; } ElNotification({ title: title, type: type, message: message, position: position, duration: 0, }); } export function warning(msg) { showMessage('warning', msg, false); } export function error(msg) { showMessage('error', msg, false); } export function success(msg) { showMessage('success', msg, false); } export const confirm = (msg: string, title: string) => { return new Promise((resolve, reject) => { ElMessageBox.confirm(msg, title, { confirmButtonText: t('base.confirm'), cancelButtonText: t('base.cancel'), buttonSize: 'default', confirmButtonClass: 'el-button--info', type: 'warning', }) .then(resolve) .catch((error) => { if (reject != null) { reject(error); } }); }); }; export const prompt = (msg: string, title: string, pattern: RegExp, errorMsg: string) => { return new Promise((resolve, reject) => { ElMessageBox.confirm(msg, title, { confirmButtonText: t('base.confirm'), cancelButtonText: t('base.cancel'), buttonSize: 'default', confirmButtonClass: 'el-button--info', inputPattern: pattern, inputErrorMessage: errorMsg, }) .then(resolve) .catch((error) => { if (reject != null) { reject(error); } }); }); };