message.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import {ElMessage, ElMessageBox, ElLoading, ElNotification} from 'element-plus'
  2. // @ts-ignore
  3. let loading: ElLoading = null;
  4. /**
  5. * 弹出消息
  6. */
  7. export const Msg = {
  8. message(msg: string='', type: any = 'success') {
  9. this.hideLoading();
  10. // @ts-ignore
  11. ElMessage({
  12. showClose: true,
  13. message: msg,
  14. type: type
  15. })
  16. },
  17. confirm(message: string, title: string = '提示', options?: any,type='warning'): Promise<any> {
  18. // @ts-ignore
  19. return ElMessageBox.confirm(
  20. message,
  21. title,
  22. {
  23. distinguishCancelAndClose: true,
  24. confirmButtonText: options?.ok || '确认',
  25. cancelButtonText: options?.cancel || '取消',
  26. type: type,
  27. buttonSize:'default'
  28. }
  29. ).then((v) => {
  30. console.log(v)
  31. return Promise.resolve();
  32. }).catch(e => {
  33. console.error(e)
  34. return Promise.reject(e);
  35. })
  36. },
  37. prompt(message: string, title: string = '提醒', options?: any): Promise<any> {
  38. return ElMessageBox.prompt(message, title, {
  39. confirmButtonText: '确认',
  40. cancelButtonText: '取消',
  41. inputPattern: options?.pattern,
  42. inputErrorMessage: options?.error,
  43. })
  44. },
  45. showLoading(text: string = '加载中') {
  46. loading = ElLoading.service({text: text});
  47. },
  48. hideLoading() {
  49. if (loading) {
  50. loading.close();
  51. }
  52. },
  53. notify(message: string, title: string = '通知', options?: any) {
  54. ElNotification({
  55. title: title,
  56. message: message,
  57. duration: options?.duration || 3000,
  58. type: options?.type || 'info',
  59. position: options?.position || 'top-right'
  60. })
  61. }
  62. };