import { Notification } from "element-ui"; interface MessageConfig { showClose?: boolean, duration?: number, onClose?: Function } const defaultMessage: MessageConfig = { showClose: true }; /** * 全局提示 * author tanxj * @param customMessage 自定义消息 * @param messageType 消息类型 {success, info, error, warning} * @param config 消息配置参数 */ export default function (customMessage: string, messageType: any = 'info', config?: MessageConfig) { config = config || {}; Object.keys(defaultMessage).forEach((key: string) => { if (config[key] === undefined) config[key] = defaultMessage[key]; }); Notification({ ...config, customClass: 'mu-message', message: customMessage, type: messageType } as any); } /** * 全局通知 * author tanxj * @param title 通知标题 * @param customMessage 通知消息 * @param messageType 通知类型 {success, info, error, warning} * @param config 通知配置参数 */ export const Notice = function (title: string, customMessage: string, messageType?: string, config?: MessageConfig) { config = config || {}; Object.keys(defaultMessage).forEach((key: string) => { if (config[key] === undefined) config[key] = defaultMessage[key]; }); Notification({ ...config, title: title, customClass: 'mu-message mu-notice', message: customMessage, type: messageType } as any); };