SweetAlert2.js 1.8 KB

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