/* * @Description: 消息系统 * @Author: sql * @Date: 2018-11-26 11:06:55 * @LastEditTime: 2018-11-30 11:25:43 */ import { ElMessage, ElMessageBox } from 'element-plus' const base = { placement: 'top-right', } export default class Pigeon { /** * 系统提醒 * @param {string} msg 提醒信息 * @param {int} type 0 信息, 1 成功, 2警告, 3 错误 */ message(msg, type = 0) { if (msg == '' || msg == null) { ElMessage.error('msg不能为空!!!') return false } switch (type) { case 0: ElMessage({ customClass: 'crm_message crm_msg_info', message: msg }) break case 1: ElMessage.success({ customClass: 'crm_message crm_msg_suc', message: msg }) break case 2: ElMessage.warning({ customClass: 'crm_message crm_msg_war', message: msg, }) break case 3: ElMessage.error({ customClass: 'crm_message crm_msg_err', message: msg }) break default: ElMessage({ customClass: 'crm_message crm_msg_info', message: msg }) break } } /** * 成功的系统提醒 * @param {string} msg */ MessageOK(msg) { this.message(msg, 1) } /** * 成功的系统提醒 * @param {string} msg */ success(msg) { this.message(msg, 1) } /** * 错误的系统提醒 * @param {string} msg */ MessageError(msg) { this.message(msg, 3) } /** * 错误的系统提醒 * @param {string} msg */ error(msg) { this.message(msg, 3) } /** * 警告的系统提醒 * @param {string} msg */ MessageWarning(msg) { this.message(msg, 2) } /** * 警告的系统提醒 * @param {string} msg */ warning(msg) { this.message(msg, 2) } /** * 普通的系统提醒 * @param {string} msg */ MessageInfo(msg) { this.message(msg, 0) } /** * 普通的系统提醒 * @param {string} msg */ info(msg) { this.message(msg, 0) } /** * 确认消息 * @param {string} msg 提示信息 * @param {string} title 头部 * @param {function} confirmHandle 确认回调函数 * @param {function} cancelHandle 取消回调函数 * @param {string} confirmText 确认按钮文字 * @param {string} cancelText 取消按钮文字 * @param {string} settings 其他配置项 */ static MessageConfirm( msg, title, confirmText, cancelText, confirmHandle, cancelHandle, settings = {} ) { ElMessageBox.confirm(msg, title, { confirmButtonText: confirmText, cancelButtonText: cancelText, customClass: 'crm_message_box', ...settings, }) .then(({ value }) => { confirmHandle(value) }) .catch(() => { cancelHandle() }) } /** * 提交内容 * @param {string} msg 提示信息 * @param {function} confirmHandle 确认回调函数 * @param {function} cancelHandle 取消回调函数 * @param settings */ static MessagePrompt( msg, confirmHandle, cancelHandle, settings = { inputType: 'text', inputPattern: null, inputErrorMessage: null, } ) { ElMessageBox.prompt(msg, '系统提示', { confirmButtonText: settings.confirmButtonText || '确定', cancelButtonText: settings.cancelButtonText || '取消', ...settings, beforeClose: (action, instance, done) => { if (action === 'confirm') { instance.confirmButtonLoading = true instance.confirmButtonText = '执行中...' setTimeout(() => { done() setTimeout(() => { instance.confirmButtonLoading = false }, 100) }, 500) } else { instance.cancelButtonLoading = true instance.cancelButtonText = '执行中...' setTimeout(() => { done() setTimeout(() => { instance.cancelButtonLoading = false }, 100) }, 500) } }, }) .then(({ value }) => { confirmHandle(value) }) .catch(() => { cancelHandle() }) } }