SweetAlert2.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 lang = Dcat.lang;
  27. options = $.extend({
  28. showCancelButton: true,
  29. showLoaderOnConfirm: true,
  30. confirmButtonText: lang['confirm'],
  31. cancelButtonText: lang['cancel'],
  32. confirmButtonClass: 'btn btn-primary',
  33. cancelButtonClass: 'btn btn-white ml-1',
  34. buttonsStyling: false,
  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. }, options);
  49. return this.swal.fire(options);
  50. }
  51. }