/**
* 通知工具组件
* å°è£… Element Plus çš„ ElNotification 组件
*/
import { ElNotification } from 'element-plus'
import type { NotificationParams } from '../types/notification'
/**
* 显示信æ¯é€šçŸ¥
* @param {Object} params - é€šçŸ¥å‚æ•°
* @param {string} params.message - 通知消æ¯å†…容
* @param {string} [params.title] - é€šçŸ¥æ ‡é¢˜
* @param {number} [params.duration] - 显示时间,å•使¯«ç§’
*/
const info = (params: NotificationParams) => {
ElNotification({
type: 'info',
message: params.message,
title: params.title || 'ä¿¡æ¯',
duration: params.duration || 3000,
})
}
/**
* 显示æˆåŠŸé€šçŸ¥
* @param {Object} params - é€šçŸ¥å‚æ•°
* @param {string} params.message - 通知消æ¯å†…容
* @param {string} [params.title] - é€šçŸ¥æ ‡é¢˜
* @param {number} [params.duration] - 显示时间,å•使¯«ç§’
*/
const success = (params: NotificationParams) => {
ElNotification({
type: 'success',
message: params.message,
title: params.title || 'æˆåŠŸ',
duration: params.duration || 3000,
})
}
/**
* 显示错误通知
* @param {Object} params - é€šçŸ¥å‚æ•°
* @param {string} params.message - 通知消æ¯å†…容
* @param {string} [params.title] - é€šçŸ¥æ ‡é¢˜
* @param {number} [params.duration] - 显示时间,å•使¯«ç§’
*/
const error = (params: NotificationParams) => {
ElNotification({
type: 'error',
message: params.message,
title: params.title || '错误',
duration: params.duration || 5000,
})
}
/**
* 显示è¦å‘Šé€šçŸ¥
* @param {Object} params - é€šçŸ¥å‚æ•°
* @param {string} params.message - 通知消æ¯å†…容
* @param {string} [params.title] - é€šçŸ¥æ ‡é¢˜
* @param {number} [params.duration] - 显示时间,å•使¯«ç§’
*/
const warning = (params: NotificationParams) => {
ElNotification({
type: 'warning',
message: params.message,
title: params.title || 'è¦å‘Š',
duration: params.duration || 4000,
})
}
/**
* æ ¹æ®ç±»åž‹è‡ªåŠ¨æ˜¾ç¤ºå¯¹åº”çš„é€šçŸ¥
* @param {string} type - 通知类型:info, success, error, warning
* @param {string} message - 通知消æ¯å†…容
* @param {string} [title] - é€šçŸ¥æ ‡é¢˜
* @param {number} [duration] - 显示时间,å•使¯«ç§’
*/
const autoNotification = (type: string, message: string, title?: string, duration?: number) => {
const params = { message, title, duration }
switch (type) {
case 'success':
success(params)
break
case 'error':
error(params)
break
case 'warning':
warning(params)
break
case 'info':
default:
info(params)
break
}
}
// 导出通知函数
const Notification = {
info,
success,
error,
warning,
autoNotification,
}
export default Notification
|