dialog.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // +---------------------------------------------------------------------
  2. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  3. // +---------------------------------------------------------------------
  4. // | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
  5. // +---------------------------------------------------------------------
  6. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  7. // +---------------------------------------------------------------------
  8. // | Author: CRMEB Team <admin@crmeb.com>
  9. // +---------------------------------------------------------------------
  10. import {
  11. Confirm as confirm,
  12. Alert as alert,
  13. Toast as toast,
  14. Notify as notify,
  15. Loading as loading,
  16. } from 'vue-ydui/dist/lib.rem/dialog';
  17. const dialog = {
  18. confirm,
  19. alert,
  20. toast,
  21. notify,
  22. loading,
  23. };
  24. const icons = { error: '操作失败', success: '操作成功' };
  25. Object.keys(icons).reduce((dialog, key) => {
  26. dialog[key] = (mes, obj = {}) => {
  27. return new Promise(function (resolve) {
  28. toast({
  29. mes: mes || icons[key],
  30. timeout: 1000,
  31. icon: key,
  32. callback: () => {
  33. resolve();
  34. },
  35. ...obj,
  36. });
  37. });
  38. };
  39. return dialog;
  40. }, dialog);
  41. dialog.message = (mes = '操作失败', obj = {}) => {
  42. return new Promise(function (resolve) {
  43. toast({
  44. mes,
  45. timeout: 1000,
  46. callback: () => {
  47. resolve();
  48. },
  49. ...obj,
  50. });
  51. });
  52. };
  53. dialog.validateError = (...args) => {
  54. validatorDefaultCatch(...args);
  55. };
  56. export function validatorDefaultCatch(err, type = 'message') {
  57. return dialog[type](err.errors[0].message);
  58. }
  59. export default dialog;