scHintBox.html 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. <script>
  36. const hintBox = {
  37. value: null,
  38. btnType: {yes: 1, yesNo: 2, yesNoCancel: 3},
  39. defalultEvent: function () {
  40. $.bootstrapLoading.end();
  41. // alert('defalultEvent');
  42. return;
  43. },
  44. init: function (){
  45. // 事件类
  46. $("#hintBox_value").unbind();
  47. $("#hintBox_btn_yes").unbind();
  48. $('#hintBox_btn_no').unbind();
  49. $('#hintBox_btn_cancel').unbind();
  50. $("#hintBox_value").keyup(
  51. function (event) {
  52. hintBox.value = $('#hintBox_value').val();
  53. if (event.keyCode === 13) {
  54. $('#hintBox_btn_yes').click();
  55. return false;
  56. }
  57. }
  58. );
  59. $('#hintBox_btn_cancel').click(
  60. hintBox.defalultEvent
  61. );
  62. // 显示类
  63. $('#hintBox_caption').hide();
  64. $('#hintBox_value').hide();
  65. $('#hintBox_error').hide();
  66. $('#hintBox_btn_yes').hide();
  67. $('#hintBox_btn_no').hide();
  68. $('#hintBox_btn_cancel').hide();
  69. $('#hintBox_btn_cross').show();
  70. },
  71. font: function(str){
  72. return `<span style='color:red;font-weight:bold;font-size:15px'> ${str} </span>`;
  73. },
  74. error: function (err) { // 注意:该方法只能用在valueBox()的doOK回调函数中。
  75. $('#hintBox_error').text(err);
  76. $('#hintBox_error').show(200);
  77. $("#hintBox_value").focus();
  78. $("#hintBox_value").select();
  79. },
  80. infoBox: function (title, caption, btnType,
  81. doYes, doNo = hintBox.defalultEvent,
  82. btnTextArr = null, showCrossBtn = true) {
  83. this.init();
  84. if (!showCrossBtn)
  85. $('#hintBox_btn_cross').hide();
  86. $('#hintBox_title').text(title);
  87. $('#hintBox_caption').html(caption);
  88. $('#hintBox_caption').show();
  89. switch (btnType) {
  90. case this.btnType.yes:
  91. if (btnTextArr){
  92. $('#hintBox_btn_yes').text(btnTextArr[0]);
  93. }else
  94. $('#hintBox_btn_yes').text('确定');
  95. $('#hintBox_btn_yes').show();
  96. break;
  97. case this.btnType.yesNo:
  98. if (btnTextArr){
  99. $('#hintBox_btn_yes').text(btnTextArr[0]);
  100. $('#hintBox_btn_no').text(btnTextArr[1]);
  101. }else{
  102. $('#hintBox_btn_yes').text('是');
  103. $('#hintBox_btn_no').text('否');
  104. }
  105. $('#hintBox_btn_yes').show();
  106. $('#hintBox_btn_no').show();
  107. break;
  108. case this.btnType.yesNoCancel:
  109. if (btnTextArr){
  110. $('#hintBox_btn_yes').text(btnTextArr[0]);
  111. $('#hintBox_btn_no').text(btnTextArr[1]);
  112. $('#hintBox_btn_cancel').text(btnTextArr[2]);
  113. }else{
  114. $('#hintBox_btn_yes').text('是');
  115. $('#hintBox_btn_no').text('否');
  116. $('#hintBox_btn_cancel').text('取消');
  117. }
  118. $('#hintBox_btn_yes').show();
  119. $('#hintBox_btn_no').show();
  120. $('#hintBox_btn_cancel').show();
  121. break;
  122. }
  123. if (doYes){
  124. $('#hintBox_btn_yes').click(doYes);
  125. }
  126. if (doNo){
  127. $('#hintBox_btn_no').click(doNo);
  128. }
  129. $("#hintBox_form").modal('show');
  130. },
  131. valueBox: function (title, value, doOK) {
  132. this.init();
  133. $('#hintBox_title').text(title);
  134. this.value = value;
  135. $('#hintBox_value').show();
  136. $('#hintBox_value').val(value);
  137. $("#hintBox_value").focus();
  138. $("#hintBox_value").select();
  139. $('#hintBox_btn_yes').text('确定');
  140. $('#hintBox_btn_yes').show();
  141. $('#hintBox_btn_yes').click(doOK); // doOK不能给参数
  142. $('#hintBox_btn_no').text('取消');
  143. $('#hintBox_btn_no').show();
  144. $('#hintBox_btn_no').click(hintBox.defalultEvent);
  145. $("#hintBox_form").modal('show');
  146. }
  147. };
  148. $('#hintBox_form').on('hide.bs.modal', function() {
  149. $.bootstrapLoading.end();
  150. return;
  151. });
  152. </script>