scHintBox.html 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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; max-height:300px; overflow: auto">提示明细</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. fontRed: function(str){
  76. return `<span style='color:red;'> ${str} </span>`;
  77. },
  78. fontBlue: function(str){
  79. return `<span style='color:blue;'> ${str} </span>`;
  80. },
  81. error: function (err) { // 注意:该方法只能用在valueBox()的doOK回调函数中。
  82. $('#hintBox_error').text(err);
  83. $('#hintBox_error').show(200);
  84. $("#hintBox_value").focus();
  85. $("#hintBox_value").select();
  86. },
  87. infoBox: function (title, caption, btnType,
  88. doYes, doNo = hintBox.defalultEvent,
  89. btnTextArr = null, showCrossBtn = true) {
  90. this.init();
  91. if (!showCrossBtn)
  92. $('#hintBox_btn_cross').hide();
  93. $('#hintBox_title').text(title);
  94. $('#hintBox_caption').html(caption);
  95. $('#hintBox_caption').show();
  96. switch (btnType) {
  97. case this.btnType.yes:
  98. if (btnTextArr){
  99. $('#hintBox_btn_yes').text(btnTextArr[0]);
  100. }else
  101. $('#hintBox_btn_yes').text('确定');
  102. $('#hintBox_btn_yes').show();
  103. break;
  104. case this.btnType.yesNo:
  105. if (btnTextArr){
  106. $('#hintBox_btn_yes').text(btnTextArr[0]);
  107. $('#hintBox_btn_no').text(btnTextArr[1]);
  108. }else{
  109. $('#hintBox_btn_yes').text('是');
  110. $('#hintBox_btn_no').text('否');
  111. }
  112. $('#hintBox_btn_yes').show();
  113. $('#hintBox_btn_no').show();
  114. break;
  115. case this.btnType.yesNoCancel:
  116. if (btnTextArr){
  117. $('#hintBox_btn_yes').text(btnTextArr[0]);
  118. $('#hintBox_btn_no').text(btnTextArr[1]);
  119. $('#hintBox_btn_cancel').text(btnTextArr[2]);
  120. }else{
  121. $('#hintBox_btn_yes').text('是');
  122. $('#hintBox_btn_no').text('否');
  123. $('#hintBox_btn_cancel').text('取消');
  124. }
  125. $('#hintBox_btn_yes').show();
  126. $('#hintBox_btn_no').show();
  127. $('#hintBox_btn_cancel').show();
  128. break;
  129. }
  130. if (doYes){
  131. $('#hintBox_btn_yes').click(doYes);
  132. }
  133. if (doNo){
  134. $('#hintBox_btn_no').click(doNo);
  135. }
  136. $("#hintBox_form").modal('show');
  137. },
  138. valueBox: function (title, value, doOK,row) {
  139. if(row && row>0){//默认为input,如果有row说明是要多行输入,把input换成textarea.
  140. $('#hintBox_value').remove();
  141. $("#hintBox_error").before(` <textarea id="hintBox_value" class="form-control" rows="${row}"></textarea>`);
  142. }
  143. this.init();
  144. $('#hintBox_title').text(title);
  145. this.value = value;
  146. $('#hintBox_value').show();
  147. $('#hintBox_value').val(value);
  148. $("#hintBox_value").focus();
  149. $("#hintBox_value").select();
  150. $('#hintBox_btn_yes').text('确定');
  151. $('#hintBox_btn_yes').show();
  152. $('#hintBox_btn_yes').click(doOK); // doOK不能给参数
  153. $('#hintBox_btn_no').text('取消');
  154. $('#hintBox_btn_no').show();
  155. $('#hintBox_btn_no').click(hintBox.defalultEvent);
  156. $("#hintBox_form").modal('show');
  157. },
  158. waitBox: function () {
  159. $(`#waitBox_form`).modal({'backdrop': false});
  160. },
  161. unWaitBox: function () {
  162. $('#waitBox_form').modal('hide');
  163. }
  164. };
  165. $('#hintBox_form').on('hide.bs.modal', function() {
  166. if($.bootstrapLoading) $.bootstrapLoading.end();
  167. return;
  168. });
  169. </script>