From 10f78b7cff5770aedfa6a7ac15b71c30e9e518ae Mon Sep 17 00:00:00 2001 From: qianpw <2233607957@qq.com> Date: Thu, 25 Sep 2025 17:51:05 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E6=8F=90=E7=A4=BAhooks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/antd/useMessage.ts | 131 +++++++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 src/hooks/antd/useMessage.ts diff --git a/src/hooks/antd/useMessage.ts b/src/hooks/antd/useMessage.ts new file mode 100644 index 0000000..c32335f --- /dev/null +++ b/src/hooks/antd/useMessage.ts @@ -0,0 +1,131 @@ +// src/hooks/antd/useMessage.ts +import { Modal, message, notification } from 'antd'; + +export const useMessage = () => { + return { + // 消息提示 + info(content: string) { + message.info(content); + }, + // 错误消息 + error(content: string) { + message.error(content); + }, + // 成功消息 + success(content: string) { + message.success(content); + }, + // 警告消息 + warning(content: string) { + message.warning(content); + }, + // 弹出提示 + alert(content: string) { + Modal.info({ + title: '提示', + content: content, + okText: '确定', + }); + }, + // 错误提示 + alertError(content: string) { + Modal.error({ + title: '提示', + content: content, + okText: '确定', + }); + }, + // 成功提示 + alertSuccess(content: string) { + Modal.success({ + title: '提示', + content: content, + okText: '确定', + }); + }, + // 警告提示 + alertWarning(content: string) { + Modal.warning({ + title: '提示', + content: content, + okText: '确定', + }); + }, + // 通知提示 + notify(content: string) { + notification.info({ + message: content, + }); + }, + // 错误通知 + notifyError(content: string) { + notification.error({ + message: content, + }); + }, + // 成功通知 + notifySuccess(content: string) { + notification.success({ + message: content, + }); + }, + // 警告通知 + notifyWarning(content: string) { + notification.warning({ + message: content, + }); + }, + // 确认窗体 + confirm(content: string, tip?: string) { + return new Promise((resolve) => { + Modal.confirm({ + title: tip ? tip : '提示', + content: content, + okText: '确定', + cancelText: '取消', + onOk: () => resolve(true), + onCancel: () => resolve(false), + }); + }); + }, + // 删除窗体 + delConfirm(content?: string, tip?: string) { + return new Promise((resolve) => { + Modal.confirm({ + title: tip ? tip : '提示', + content: content ? content : '是否确认删除?', + okText: '确定', + cancelText: '取消', + onOk: () => resolve(true), + onCancel: () => resolve(false), + }); + }); + }, + // 导出窗体 + exportConfirm(content?: string, tip?: string) { + return new Promise((resolve) => { + Modal.confirm({ + title: tip ? tip : '提示', + content: content ? content : '是否确认导出?', + okText: '确定', + cancelText: '取消', + onOk: () => resolve(true), + onCancel: () => resolve(false), + }); + }); + }, + // 提交内容 + prompt(content: string, tip: string) { + return new Promise((resolve) => { + Modal.confirm({ + title: tip, + content: content, + okText: '确定', + cancelText: '取消', + onOk: () => resolve(true), + onCancel: () => resolve(false), + }); + }); + }, + }; +};