scHintBox.html 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <!----------------------------------------------------------------------------------------------------------------------
  2. chenshilong, 2018-04-29
  3. 自定义对话框,通用,用于替代系统对话框。系统自带的比较简陋,最严重的是一旦被浏览器屏蔽则无法再弹出。
  4. 自定义对话框包括:
  5. 1、只有一个按钮的信息提示框。
  6. 2、有两个按钮的操作确认询问框。
  7. 3、有三个按钮的多分支选择询问框。
  8. 4、输入文本值对话框。
  9. 使用示例:ConstructionCost/test/public/test_Box.html (直接运行该文件查看效果)
  10. ----------------------------------------------------------------------------------------------------------------------->
  11. <div class="modal fade" id="hintBox_form" data-backdrop="static" style="z-index: 9999">
  12. <div class="modal-dialog" role="document">
  13. <div class="modal-content">
  14. <div class="modal-header">
  15. <h5 id="hintBox_title" class="modal-title">标题</h5>
  16. <button type="button" class="close" data-dismiss="modal" aria-label="Close" id="hintBox_btn_cross">
  17. <span aria-hidden="true">&times;</span>
  18. </button>
  19. </div>
  20. <div class="modal-body">
  21. <div id = "hintBox_caption" style="margin:5px 10px 10px 10px;">提示明细</div>
  22. <div style="margin:5px 10px 5px 10px;">
  23. <input id="hintBox_value" type="text" class="form-control" value="" />
  24. <p id="hintBox_error" style="margin-top:7px; color:red; display:none;">“xxx”已存在!</p>
  25. </div>
  26. </div>
  27. <div class="modal-footer" style="justify-content: center">
  28. <button type="button" class="btn btn-primary" data-dismiss="modal" id="hintBox_btn_yes">是</button>
  29. <button type="button" class="btn btn-primary" data-dismiss="modal" id="hintBox_btn_no">否</button>
  30. <button type="button" class="btn btn-secondary" data-dismiss="modal" id="hintBox_btn_cancel">取消</button>
  31. </div>
  32. </div>
  33. </div>
  34. </div>
  35. <div class="modal" id="waitBox_form" style="z-index: 9999; cursor: wait"></div>
  36. <script>
  37. const hintBox = {
  38. value: null,
  39. btnType: {yes: 1, yesNo: 2, yesNoCancel: 3},
  40. defalultEvent: function () {
  41. $.bootstrapLoading.end();
  42. // alert('defalultEvent');
  43. return;
  44. },
  45. init: function (){
  46. // 事件类
  47. $("#hintBox_value").unbind();
  48. $("#hintBox_btn_yes").unbind();
  49. $('#hintBox_btn_no').unbind();
  50. $('#hintBox_btn_cancel').unbind();
  51. $("#hintBox_value").keyup(
  52. function (event) {
  53. hintBox.value = $('#hintBox_value').val();
  54. if (event.keyCode === 13) {
  55. $('#hintBox_btn_yes').click();
  56. return false;
  57. }
  58. }
  59. );
  60. $('#hintBox_btn_cancel').click(
  61. hintBox.defalultEvent
  62. );
  63. // 显示类
  64. $('#hintBox_caption').hide();
  65. $('#hintBox_value').hide();
  66. $('#hintBox_error').hide();
  67. $('#hintBox_btn_yes').hide();
  68. $('#hintBox_btn_no').hide();
  69. $('#hintBox_btn_cancel').hide();
  70. $('#hintBox_btn_cross').show();
  71. },
  72. font: function(str){
  73. return `<span style='color:red;font-weight:bold;font-size:15px'> ${str} </span>`;
  74. },
  75. error: function (err) { // 注意:该方法只能用在valueBox()的doOK回调函数中。
  76. $('#hintBox_error').text(err);
  77. $('#hintBox_error').show(200);
  78. $("#hintBox_value").focus();
  79. $("#hintBox_value").select();
  80. },
  81. infoBox: function (title, caption, btnType,
  82. doYes, doNo = hintBox.defalultEvent,
  83. btnTextArr = null, showCrossBtn = true) {
  84. this.init();
  85. if (!showCrossBtn)
  86. $('#hintBox_btn_cross').hide();
  87. $('#hintBox_title').text(title);
  88. $('#hintBox_caption').html(caption);
  89. $('#hintBox_caption').show();
  90. switch (btnType) {
  91. case this.btnType.yes:
  92. if (btnTextArr){
  93. $('#hintBox_btn_yes').text(btnTextArr[0]);
  94. }else
  95. $('#hintBox_btn_yes').text('确定');
  96. $('#hintBox_btn_yes').show();
  97. break;
  98. case this.btnType.yesNo:
  99. if (btnTextArr){
  100. $('#hintBox_btn_yes').text(btnTextArr[0]);
  101. $('#hintBox_btn_no').text(btnTextArr[1]);
  102. }else{
  103. $('#hintBox_btn_yes').text('是');
  104. $('#hintBox_btn_no').text('否');
  105. }
  106. $('#hintBox_btn_yes').show();
  107. $('#hintBox_btn_no').show();
  108. break;
  109. case this.btnType.yesNoCancel:
  110. if (btnTextArr){
  111. $('#hintBox_btn_yes').text(btnTextArr[0]);
  112. $('#hintBox_btn_no').text(btnTextArr[1]);
  113. $('#hintBox_btn_cancel').text(btnTextArr[2]);
  114. }else{
  115. $('#hintBox_btn_yes').text('是');
  116. $('#hintBox_btn_no').text('否');
  117. $('#hintBox_btn_cancel').text('取消');
  118. }
  119. $('#hintBox_btn_yes').show();
  120. $('#hintBox_btn_no').show();
  121. $('#hintBox_btn_cancel').show();
  122. break;
  123. }
  124. if (doYes){
  125. $('#hintBox_btn_yes').click(doYes);
  126. }
  127. if (doNo){
  128. $('#hintBox_btn_no').click(doNo);
  129. }
  130. $("#hintBox_form").modal('show');
  131. },
  132. valueBox: function (title, value, doOK) {
  133. this.init();
  134. $('#hintBox_title').text(title);
  135. this.value = value;
  136. $('#hintBox_value').show();
  137. $('#hintBox_value').val(value);
  138. $("#hintBox_value").focus();
  139. $("#hintBox_value").select();
  140. $('#hintBox_btn_yes').text('确定');
  141. $('#hintBox_btn_yes').show();
  142. $('#hintBox_btn_yes').click(doOK); // doOK不能给参数
  143. $('#hintBox_btn_no').text('取消');
  144. $('#hintBox_btn_no').show();
  145. $('#hintBox_btn_no').click(hintBox.defalultEvent);
  146. $("#hintBox_form").modal('show');
  147. },
  148. waitBox: function () {
  149. $(`#waitBox_form`).modal({'backdrop': false});
  150. },
  151. unWaitBox: function () {
  152. $('#waitBox_form').modal('hide');
  153. }
  154. };
  155. $('#hintBox_form').on('hide.bs.modal', function() {
  156. if($.bootstrapLoading) $.bootstrapLoading.end();
  157. return;
  158. });
  159. </script>