useMessage.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. delClose(content?: string, tip?: string) {
  75. return ElMessageBox.confirm(
  76. content ? content : t('common.delMessage'),
  77. tip ? tip : t('common.confirmTitle'),
  78. {
  79. confirmButtonText: t('common.ok'),
  80. cancelButtonText: t('common.cancel'),
  81. type: 'warning'
  82. }
  83. )
  84. },
  85. // 导出窗体
  86. exportConfirm(content?: string, tip?: string) {
  87. return ElMessageBox.confirm(
  88. content ? content : t('common.exportMessage'),
  89. tip ? tip : t('common.confirmTitle'),
  90. {
  91. confirmButtonText: t('common.ok'),
  92. cancelButtonText: t('common.cancel'),
  93. type: 'warning'
  94. }
  95. )
  96. },
  97. // 提交内容
  98. prompt(content: string, tip: string) {
  99. return ElMessageBox.prompt(content, tip, {
  100. confirmButtonText: t('common.ok'),
  101. cancelButtonText: t('common.cancel'),
  102. type: 'warning'
  103. })
  104. }
  105. }
  106. }