xxl-job

xxl.alert.1.js 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /**
  2. * Created by xuxueli on 16/8/12.
  3. *
  4. * dependency, jquery + bootstrap
  5. */
  6. // 通用提示
  7. var ComAlert = {
  8. html:function(){
  9. var html =
  10. '<div class="modal fade" id="ComAlert" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">' +
  11. '<div class="modal-dialog">' +
  12. '<div class="modal-content">' +
  13. '<div class="modal-header hidden"><h4 class="modal-title"><strong>提示:</strong></h4></div>' +
  14. '<div class="modal-body"><div class="alert alert-success"></div></div>' +
  15. '<div class="modal-footer">' +
  16. '<div class="text-center" >' +
  17. '<button type="button" class="btn btn-default ok" data-dismiss="modal" >确认</button>' +
  18. '</div>' +
  19. '</div>' +
  20. '</div>' +
  21. '</div>' +
  22. '</div>';
  23. return html;
  24. },
  25. show:function(type, msg, callback){
  26. // dom init
  27. if ($('#ComAlert').length == 0){
  28. $('body').append(ComAlert.html());
  29. }
  30. // 弹框初始
  31. if (type == 1) {
  32. $('#ComAlert .alert').attr('class', 'alert alert-success');
  33. } else {
  34. $('#ComAlert .alert').attr('class', 'alert alert-warning');
  35. }
  36. $('#ComAlert .alert').html(msg);
  37. $('#ComAlert').modal('show');
  38. $('#ComAlert .ok').click(function(){
  39. $('#ComAlert').modal('hide');
  40. if(typeof callback == 'function') {
  41. callback();
  42. }
  43. });
  44. // $("#ComAlert").on('hide.bs.modal', function () { }); // 监听关闭
  45. }
  46. };
  47. // 通用确认弹框
  48. var ComConfirm = {
  49. html:function(){
  50. var html =
  51. '<div class="modal fade" id="ComConfirm" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">' +
  52. '<div class="modal-dialog">' +
  53. '<div class="modal-content">' +
  54. '<div class="modal-body"><div class="alert alert-success"></div></div>' +
  55. '<div class="modal-footer">' +
  56. '<div class="text-center" >' +
  57. '<button type="button" class="btn btn-primary ok" data-dismiss="modal" >确认</button>' +
  58. '<button type="button" class="btn btn-default cancel" data-dismiss="modal" >取消</button>' +
  59. '</div>' +
  60. '</div>' +
  61. '</div>' +
  62. '</div>' +
  63. '</div>';
  64. return html;
  65. },
  66. show:function(msg, callback){
  67. // dom init
  68. if ($('#ComConfirm').length == 0){
  69. $("body").append(ComConfirm.html());
  70. }
  71. // 弹框初始
  72. $('#ComConfirm .alert').attr('class', 'alert alert-warning');
  73. $('#ComConfirm .alert').html(msg);
  74. $('#ComConfirm').modal('show');
  75. $('#ComConfirm .ok').unbind("click"); // 解绑陈旧事件
  76. $('#ComConfirm .ok').click(function(){
  77. $('#ComConfirm').modal('hide');
  78. if(typeof callback == 'function') {
  79. setTimeout(function(){
  80. callback();
  81. return;
  82. }, 315);
  83. }
  84. });
  85. $('#ComConfirm .cancel').click(function(){
  86. $('#ComConfirm').modal('hide');
  87. return;
  88. });
  89. }
  90. };