modal.ts 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import { MessageBoxData } from 'element-plus';
  2. import { LoadingInstance } from 'element-plus/es/components/loading/src/loading';
  3. let loadingInstance: LoadingInstance;
  4. export default {
  5. // 消息提示
  6. msg(content: any) {
  7. ElMessage.info(content);
  8. },
  9. // 错误消息
  10. msgError(content: any) {
  11. ElMessage.error(content);
  12. },
  13. // 成功消息
  14. msgSuccess(content: any) {
  15. ElMessage.success(content);
  16. },
  17. // 警告消息
  18. msgWarning(content: any) {
  19. ElMessage.warning(content);
  20. },
  21. // 弹出提示
  22. alert(content: any) {
  23. ElMessageBox.alert(content, '系统提示');
  24. },
  25. // 错误提示
  26. alertError(content: any) {
  27. ElMessageBox.alert(content, '系统提示', { type: 'error' });
  28. },
  29. // 成功提示
  30. alertSuccess(content: any) {
  31. ElMessageBox.alert(content, '系统提示', { type: 'success' });
  32. },
  33. // 警告提示
  34. alertWarning(content: any) {
  35. ElMessageBox.alert(content, '系统提示', { type: 'warning' });
  36. },
  37. // 通知提示
  38. notify(content: any) {
  39. ElNotification.info(content);
  40. },
  41. // 错误通知
  42. notifyError(content: any) {
  43. ElNotification.error(content);
  44. },
  45. // 成功通知
  46. notifySuccess(content: any) {
  47. ElNotification.success(content);
  48. },
  49. // 警告通知
  50. notifyWarning(content: any) {
  51. ElNotification.warning(content);
  52. },
  53. // 确认窗体
  54. confirm(content: any): Promise<MessageBoxData> {
  55. return ElMessageBox.confirm(content, '系统提示', {
  56. confirmButtonText: '确 定',
  57. cancelButtonText: '取 消',
  58. type: 'warning',
  59. center: true,
  60. draggable: true,
  61. customClass: 'messageBoxClass',
  62. confirmButtonClass: 'btn-custom-confirm',
  63. cancelButtonClass: 'btn-custom-cancel'
  64. });
  65. },
  66. // 提交内容
  67. prompt(content: any, inputType?: any) {
  68. return ElMessageBox.prompt(content, '系统提示', {
  69. confirmButtonText: '确 定',
  70. cancelButtonText: '取 消',
  71. inputType: inputType ? inputType : 'text',
  72. inputPlaceholder: '请输入',
  73. type: 'warning',
  74. center: true,
  75. customClass: 'messageBoxClass',
  76. confirmButtonClass: 'btn-custom-confirm',
  77. cancelButtonClass: 'btn-custom-cancel',
  78. inputPattern: /[^ \f\n\r\t\v]/,
  79. inputErrorMessage: '不能为空'
  80. });
  81. },
  82. // 打开遮罩层
  83. loading(content: string) {
  84. loadingInstance = ElLoading.service({
  85. lock: true,
  86. text: content,
  87. background: 'rgba(0, 0, 0, 0.7)'
  88. });
  89. },
  90. // 关闭遮罩层
  91. closeLoading() {
  92. loadingInstance?.close();
  93. }
  94. };