forked from 77media/video-flow
81 lines
2.2 KiB
TypeScript
81 lines
2.2 KiB
TypeScript
import { message } from 'antd';
|
|
import type { ArgsProps as MessageProps } from 'antd/es/message';
|
|
|
|
/**
|
|
* 全局消息提示工具
|
|
* 对 antd message 进行封装,提供更简洁的 API
|
|
*/
|
|
class MessageUtil {
|
|
/**
|
|
* 成功提示
|
|
* @param content - 提示内容
|
|
* @param duration - 显示时长(秒),默认 3 秒
|
|
* @param options - 其他配置项
|
|
*/
|
|
success(content: string, duration = 3, options?: Omit<MessageProps, 'content'>) {
|
|
message.success({ content, duration, ...options });
|
|
}
|
|
|
|
/**
|
|
* 错误提示
|
|
* @param content - 提示内容
|
|
* @param duration - 显示时长(秒),默认 3 秒
|
|
* @param options - 其他配置项
|
|
*/
|
|
error(content: string, duration = 3, options?: Omit<MessageProps, 'content'>) {
|
|
message.error({ content, duration, ...options });
|
|
}
|
|
|
|
/**
|
|
* 警告提示
|
|
* @param content - 提示内容
|
|
* @param duration - 显示时长(秒),默认 3 秒
|
|
* @param options - 其他配置项
|
|
*/
|
|
warning(content: string, duration = 3, options?: Omit<MessageProps, 'content'>) {
|
|
message.warning({ content, duration, ...options });
|
|
}
|
|
|
|
/**
|
|
* 普通提示
|
|
* @param content - 提示内容
|
|
* @param duration - 显示时长(秒),默认 3 秒
|
|
* @param options - 其他配置项
|
|
*/
|
|
info(content: string, duration = 3, options?: Omit<MessageProps, 'content'>) {
|
|
message.info({ content, duration, ...options });
|
|
}
|
|
|
|
/**
|
|
* 加载提示
|
|
* @param content - 提示内容
|
|
* @param duration - 显示时长(秒),默认 0 表示不自动关闭
|
|
* @param options - 其他配置项
|
|
* @returns - 返回一个函数,调用该函数可以手动关闭提示
|
|
*/
|
|
loading(content: string, duration = 0, options?: Omit<MessageProps, 'content'>) {
|
|
return message.loading({ content, duration, ...options });
|
|
}
|
|
|
|
/**
|
|
* 销毁所有消息提示
|
|
*/
|
|
destroy() {
|
|
message.destroy();
|
|
}
|
|
|
|
/**
|
|
* 配置全局默认值
|
|
* @param options - 全局配置项
|
|
*/
|
|
config(options: MessageProps) {
|
|
message.config(options);
|
|
}
|
|
}
|
|
|
|
// 导出单例实例
|
|
export const msg = new MessageUtil();
|
|
|
|
// 为了方便使用,也导出单独的方法
|
|
export const { success, error, warning, info, loading, destroy, config } = msg;
|