| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- /*
- * @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()
- })
- }
- }
|