SweetAlert2.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import Swal from '../sweetalert/sweetalert2'
  2. let w = window;
  3. export default class SweetAlert2 {
  4. constructor(Dcat) {
  5. let _this = this;
  6. Swal.success = _this.success.bind(_this);
  7. Swal.error = _this.error.bind(_this);
  8. Swal.info = _this.info.bind(_this);
  9. Swal.warning = _this.warning.bind(_this);
  10. Swal.confirm = _this.confirm.bind(_this);
  11. w.swal = w.Swal = _this.swal = Dcat.swal = Swal;
  12. Dcat.confirm = Swal.confirm;
  13. }
  14. success(title, message, options) {
  15. return this.fire(title, message, 'success', options)
  16. }
  17. error(title, message, options) {
  18. return this.fire(title, message, 'error', options)
  19. }
  20. info(title, message, options) {
  21. return this.fire(title, message, 'info', options)
  22. }
  23. warning(title, message, options) {
  24. return this.fire(title, message, 'warning', options)
  25. }
  26. confirm(title, message, success, fail, options) {
  27. let lang = Dcat.lang;
  28. options = $.extend({
  29. showCancelButton: true,
  30. showLoaderOnConfirm: true,
  31. confirmButtonText: lang['confirm'],
  32. cancelButtonText: lang['cancel'],
  33. confirmButtonClass: 'btn btn-primary',
  34. cancelButtonClass: 'btn btn-white ml-1',
  35. buttonsStyling: false,
  36. }, options);
  37. this.fire(title, message, 'question', options).then(function (result) {
  38. if (result.value) {
  39. return success && success()
  40. }
  41. fail && fail()
  42. })
  43. }
  44. fire(title, message, type, options) {
  45. options = $.extend({
  46. title: title,
  47. type: type,
  48. html: message,
  49. }, options);
  50. return this.swal.fire(options);
  51. }
  52. }