From c1db5886ffa7961ef76eb4a64ee42cd2fd98e964 Mon Sep 17 00:00:00 2001 From: huailei <31801270+huailei000@users.noreply.github.com> Date: Fri, 18 Aug 2023 17:22:32 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E9=98=B2=E6=AD=A2message=E9=87=8D?= =?UTF-8?q?=E5=A4=8D=E5=BC=B9=E5=87=BA=20(#1996)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/utils/message.ts | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/frontend/src/utils/message.ts b/frontend/src/utils/message.ts index 4601aa7be..c675dca32 100644 --- a/frontend/src/utils/message.ts +++ b/frontend/src/utils/message.ts @@ -1,7 +1,21 @@ import { ElMessage } from 'element-plus'; +let messageDom: any = null; +const messageTypes: Array = ['success', 'error', 'warning', 'info']; +const Message: any = (options) => { + if (messageDom) messageDom.close(); + messageDom = ElMessage(options); +}; +messageTypes.forEach((type) => { + Message[type] = (options) => { + if (typeof options === 'string') options = { message: options }; + options.type = type; + return Message(options); + }; +}); + export const MsgSuccess = (message) => { - ElMessage.success({ + Message.success({ message: message, type: 'success', showClose: true, @@ -10,7 +24,7 @@ export const MsgSuccess = (message) => { }; export const MsgInfo = (message) => { - ElMessage.info({ + Message.info({ message: message, type: 'info', showClose: true, @@ -19,7 +33,7 @@ export const MsgInfo = (message) => { }; export const MsgWarning = (message) => { - ElMessage.warning({ + Message.warning({ message: message, type: 'warning', showClose: true, @@ -28,7 +42,7 @@ export const MsgWarning = (message) => { }; export const MsgError = (message) => { - ElMessage.error({ + Message.error({ message: message, type: 'error', showClose: true,