useMessage.ts 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import { ElMessage, ElMessageBox, ElNotification } from 'element-plus'
  2. import { useI18n } from './useI18n'
  3. export const useMessage = () => {
  4. const { t } = useI18n()
  5. return {
  6. // 消息提示
  7. info(content: string) {
  8. ElMessage.info(content)
  9. },
  10. // 错误消息
  11. error(content: string) {
  12. ElMessage.error(content)
  13. },
  14. // 成功消息
  15. success(content: string) {
  16. ElMessage.success(content)
  17. },
  18. // 警告消息
  19. warning(content: string) {
  20. ElMessage.warning(content)
  21. },
  22. // 弹出提示
  23. alert(content: string) {
  24. ElMessageBox.alert(content, t('common.confirmTitle'))
  25. },
  26. // 错误提示
  27. alertError(content: string) {
  28. ElMessageBox.alert(content, t('common.confirmTitle'), { type: 'error' })
  29. },
  30. // 成功提示
  31. alertSuccess(content: string) {
  32. ElMessageBox.alert(content, t('common.confirmTitle'), { type: 'success' })
  33. },
  34. // 警告提示
  35. alertWarning(content: string) {
  36. ElMessageBox.alert(content, t('common.confirmTitle'), { type: 'warning' })
  37. },
  38. // 通知提示
  39. notify(content: string) {
  40. ElNotification.info(content)
  41. },
  42. // 错误通知
  43. notifyError(content: string) {
  44. ElNotification.error(content)
  45. },
  46. // 成功通知
  47. notifySuccess(content: string) {
  48. ElNotification.success(content)
  49. },
  50. // 警告通知
  51. notifyWarning(content: string) {
  52. ElNotification.warning(content)
  53. },
  54. // 确认窗体
  55. confirm(content: string, tip?: string) {
  56. return ElMessageBox.confirm(content, tip ? tip : t('common.confirmTitle'), {
  57. confirmButtonText: t('common.ok'),
  58. cancelButtonText: t('common.cancel'),
  59. type: 'warning'
  60. })
  61. },
  62. // 删除窗体
  63. delConfirm(content?: string, tip?: string) {
  64. return ElMessageBox.confirm(
  65. content ? content : t('common.delMessage'),
  66. tip ? tip : t('common.confirmTitle'),
  67. {
  68. confirmButtonText: t('common.ok'),
  69. cancelButtonText: t('common.cancel'),
  70. type: 'warning'
  71. }
  72. )
  73. },
  74. // 导出窗体
  75. exportConfirm(content?: string, tip?: string) {
  76. return ElMessageBox.confirm(
  77. content ? content : t('common.exportMessage'),
  78. tip ? tip : t('common.confirmTitle'),
  79. {
  80. confirmButtonText: t('common.ok'),
  81. cancelButtonText: t('common.cancel'),
  82. type: 'warning'
  83. }
  84. )
  85. },
  86. // 提交内容
  87. prompt(content: string, tip: string) {
  88. return ElMessageBox.prompt(content, tip, {
  89. confirmButtonText: t('common.ok'),
  90. cancelButtonText: t('common.cancel'),
  91. type: 'warning'
  92. })
  93. }
  94. }
  95. }