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 btnClass = 'btn btn-outline-dark',
  27. lang = Dcat.lang;
  28. options = $.extend({
  29. showCancelButton: true,
  30. confirmButtonText: lang['confirm'],
  31. cancelButtonText: lang['cancel'],
  32. confirmButtonClass: btnClass,
  33. cancelButtonClass: btnClass + 'ml-1',
  34. }, options);
  35. this.warning(title, message, options).then(function (result) {
  36. if (result.value) {
  37. return success && success()
  38. }
  39. fail && fail()
  40. })
  41. }
  42. fire(title, message, type, options) {
  43. options = $.extend({
  44. title: title,
  45. text: message,
  46. type: type,
  47. // buttonsStyling: false,
  48. }, options);
  49. return this.swal.fire(options);
  50. }
  51. }