modal.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /**
  2. * Created by pc on 2016/10/21.
  3. */
  4. $.extend({
  5. modal: {
  6. /**
  7. * alert弹窗
  8. * @param message
  9. * @param type warning,error,success,info和question
  10. * @param callback
  11. */
  12. alert: function (message, type, callback) {
  13. if (type == undefined) {
  14. type = "info";
  15. }
  16. swal({
  17. title: message,
  18. type: type,
  19. showConfirmButton: true,
  20. },
  21. function(){
  22. if (callback) {
  23. callback();
  24. }
  25. });
  26. },
  27. /**
  28. * 提示弹窗
  29. * @param message
  30. */
  31. info: function (message) {
  32. swal(message);
  33. },
  34. /**
  35. * 成功弹窗
  36. * @param message
  37. */
  38. success: function (message) {
  39. this.notify(message, 'success');
  40. },
  41. /**
  42. * 失败弹窗
  43. * @param message
  44. */
  45. error: function (message) {
  46. this.notify(message, 'error');
  47. },
  48. /**
  49. * 通知弹窗
  50. * @param message
  51. * @param type
  52. * @param callback
  53. */
  54. notify: function (message, type, callback) {
  55. swal({
  56. title: message,
  57. type: type,
  58. timer: 1500,
  59. showConfirmButton: false,
  60. animation: false
  61. }, function () {
  62. if (callback) {
  63. callback();
  64. }
  65. // 没callback时候不会关闭,应该是bug
  66. swal.close();
  67. });
  68. },
  69. /**
  70. * 确认弹窗
  71. * @param message
  72. * @param ok 确认回调函数
  73. * @param cancel
  74. */
  75. confirm: function (message, ok, cancel) {
  76. swal({
  77. title: message,
  78. type: "warning",
  79. showCancelButton: true,
  80. cancelButtonText:"取消",
  81. confirmButtonColor: "#DD6B55",
  82. confirmButtonText: "确定",
  83. closeOnConfirm: false,
  84. animation: false,
  85. showLoaderOnConfirm: true
  86. },
  87. function(){
  88. ok();
  89. });
  90. },
  91. /**
  92. * 打开加载
  93. */
  94. loading:function () {
  95. $("<div>", {id:"loading-global", class:"loading-global"}).appendTo('body');
  96. },
  97. /**
  98. * 关闭加载
  99. */
  100. unloading:function () {
  101. $("#loading-global").remove();
  102. },
  103. /**
  104. * 关闭弹窗
  105. * @param index
  106. */
  107. close: function (index) {
  108. swal.close();
  109. }
  110. }
  111. });
  112. window.alert = $.modal.alert;