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), + }); + }); + }, + }; +};