| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- import { ElMessage, ElNotification } from 'element-plus'
- // 存储当前活动的消息或通知实例
- let activeInstance = null
- export const Message = () => {
- // 显示弹框的通用方法
- const show = (type, cover, content, showFn) => {
- // 如果有活动实例,先关闭它
- if (activeInstance && cover) {
- activeInstance.close()
- }
- // 显示新的弹框
- activeInstance = showFn(content)
- activeInstance.onClose = () => {
- activeInstance = null
- }
- }
- return {
- // 消息提示
- info(content, cover = false) {
- show('info', cover, content, (msg) => ElMessage.info(msg))
- },
- // 错误消息
- error(content, cover = false) {
- show('error', cover, content, (msg) => ElMessage.error(msg))
- },
- // 成功消息
- success(content, cover = false) {
- show('success', cover, content, (msg) => ElMessage.success(msg))
- },
- // 警告消息
- warning(content, cover = false) {
- show('warning', cover, content, (msg) => ElMessage.warning(msg))
- },
- // 通知提示
- notify(content, cover = false) {
- show('notify', cover, content, (msg) => ElNotification.info(msg))
- },
- // 错误通知
- notifyError(content, cover = false) {
- show('notifyError', cover, content, (msg) => ElNotification.error(msg))
- },
- // 成功通知
- notifySuccess(content, cover = false) {
- show('notifySuccess', cover, content, (msg) => ElNotification.success(msg))
- },
- // 警告通知
- notifyWarning(content, cover = false) {
- show('notifyWarning', cover, content, (msg) => ElNotification({
- title: '系统提示',
- message: msg,
- type: 'warning',
- }))
- },
- }
- }
|