build.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <!DOCTYPE html>
  2. <html lang="zh">
  3. <head>
  4. <th:block th:include="include :: header('表单构建器')" />
  5. <th:block th:include="include :: datetimepicker-css" />
  6. </head>
  7. <style>
  8. .droppable-active{background-color:#ffe!important}.tools a{cursor:pointer;font-size:80%}.form-body .col-md-6,.form-body .col-md-12{min-height:400px}.draggable{cursor:move}
  9. </style>
  10. <body class="gray-bg">
  11. <div class="wrapper wrapper-content">
  12. <div class="row">
  13. <div class="col-sm-5">
  14. <div class="ibox float-e-margins">
  15. <div class="ibox-title">
  16. <h5>元素</h5>
  17. <div class="ibox-tools">
  18. <a class="collapse-link">
  19. <i class="fa fa-chevron-up"></i>
  20. </a>
  21. <a class="dropdown-toggle" data-toggle="dropdown" href="#">
  22. <i class="fa fa-wrench"></i>
  23. </a>
  24. <ul class="dropdown-menu dropdown-user">
  25. <li><a href="#">基本</a>
  26. </li>
  27. <li><a href="#">其他</a>
  28. </li>
  29. </ul>
  30. <a class="close-link">
  31. <i class="fa fa-times"></i>
  32. </a>
  33. </div>
  34. </div>
  35. <div class="ibox-content">
  36. <div class="alert alert-info">
  37. 拖拽左侧的表单元素到右侧区域,即可生成相应的HTML代码,表单代码,轻松搞定!
  38. </div>
  39. <form role="form" class="form-horizontal m-t">
  40. <div class="form-group draggable">
  41. <label class="col-sm-3 control-label">文本框:</label>
  42. <div class="col-sm-9">
  43. <input type="text" name="" class="form-control" placeholder="请输入文本">
  44. </div>
  45. </div>
  46. <div class="form-group draggable">
  47. <label class="col-sm-3 control-label">多行文本框:</label>
  48. <div class="col-sm-9">
  49. <textarea type="text" name="" class="form-control" placeholder="请输入文本"></textarea>
  50. </div>
  51. </div>
  52. <div class="form-group draggable">
  53. <label class="col-sm-3 control-label">密码框:</label>
  54. <div class="col-sm-9">
  55. <input type="password" class="form-control" name="password" placeholder="请输入密码">
  56. </div>
  57. </div>
  58. <div class="form-group draggable">
  59. <label class="col-sm-3 control-label">下拉框:</label>
  60. <div class="col-sm-9">
  61. <select class="form-control" name="">
  62. <option>选项 1</option>
  63. <option>选项 2</option>
  64. <option>选项 3</option>
  65. <option>选项 4</option>
  66. </select>
  67. </div>
  68. </div>
  69. <div class="form-group draggable">
  70. <label class="col-sm-3 control-label">纯文本:</label>
  71. <div class="col-sm-9">
  72. <p class="form-control-static">这里是纯文字信息</p>
  73. </div>
  74. </div>
  75. <div class="form-group draggable">
  76. <label class="col-sm-3 control-label">单选框:
  77. </label>
  78. <div class="col-sm-9">
  79. <label class="radio-box"><input type="radio" checked="" value="option1" id="optionsRadios1" name="optionsRadios">选项1</label>
  80. <label class="radio-box"><input type="radio" value="option2" id="optionsRadios2" name="optionsRadios">选项2</label>
  81. </div>
  82. </div>
  83. <div class="form-group draggable">
  84. <label class="col-sm-3 control-label">复选框:</label>
  85. <div class="col-sm-9">
  86. <label class="check-box">
  87. <input type="checkbox" value="option1" id="inlineCheckbox1">选项1</label>
  88. <label class="check-box">
  89. <input type="checkbox" value="option2" id="inlineCheckbox2">选项2</label>
  90. <label class="check-box">
  91. <input type="checkbox" value="option3" id="inlineCheckbox3">选项3</label>
  92. </div>
  93. </div>
  94. <div class="form-group draggable">
  95. <label class="col-sm-3 control-label">切换按钮:
  96. </label>
  97. <div class="col-sm-9">
  98. <label class="toggle-switch switch-solid">
  99. <input type="checkbox" id="status" checked>
  100. <span></span>
  101. </label>
  102. </div>
  103. </div>
  104. <div class="form-group draggable">
  105. <label class="col-sm-3 control-label">日期选择:</label>
  106. <div class="col-sm-9">
  107. <div class="form-group">
  108. <div class="input-group date">
  109. <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
  110. <input type="text" class="form-control" value="2018-04-20">
  111. </div>
  112. </div>
  113. </div>
  114. </div>
  115. <div class="hr-line-dashed"></div>
  116. <div class="form-group draggable">
  117. <div class="col-sm-12 col-sm-offset-3">
  118. <button type="submit" class="btn btn-primary">提交</button>
  119. <button onclick="$.modal.close()" class="btn btn-danger" type="button">关闭</button>
  120. </div>
  121. </div>
  122. </form>
  123. <div class="clearfix"></div>
  124. </div>
  125. </div>
  126. </div>
  127. <div class="col-sm-7">
  128. <div class="ibox float-e-margins">
  129. <div class="ibox-title">
  130. <h5>拖拽左侧表单元素到此区域</h5>
  131. <div class="ibox-tools">
  132. 请选择显示的列数:
  133. <select id="n-columns">
  134. <option value="1">显示1列</option>
  135. <option value="2">显示2列</option>
  136. </select>
  137. </div>
  138. </div>
  139. <div class="ibox-content">
  140. <div class="row form-body form-horizontal m-t">
  141. <div class="col-md-12 droppable sortable">
  142. </div>
  143. <div class="col-md-6 droppable sortable" style="display: none;">
  144. </div>
  145. <div class="col-md-6 droppable sortable" style="display: none;">
  146. </div>
  147. </div>
  148. <button type="submit" class="btn btn-warning" data-clipboard-text="testing" id="copy-to-clipboard">复制代码</button>
  149. </div>
  150. </div>
  151. </div>
  152. </div>
  153. </div>
  154. <th:block th:include="include :: footer" />
  155. <script th:src="@{/js/jquery-ui-1.10.4.min.js}"></script>
  156. <th:block th:include="include :: datetimepicker-js" />
  157. <script th:src="@{/ajax/libs/beautifyhtml/beautifyhtml.js}"></script>
  158. <script type="text/javascript">
  159. $(document).ready(function(){setup_draggable();$("#n-columns").on("change",function(){var v=$(this).val();if(v==="1"){var $col=$(".form-body .col-md-12").toggle(true);$(".form-body .col-md-6 .draggable").each(function(i,el){$(this).remove().appendTo($col)});$(".form-body .col-md-6").toggle(false)}else{var $col=$(".form-body .col-md-6").toggle(true);$(".form-body .col-md-12 .draggable").each(function(i,el){$(this).remove().appendTo(i%2?$col[1]:$col[0])});$(".form-body .col-md-12").toggle(false)}});$("#copy-to-clipboard").on("click",function(){var $copy=$(".form-body").clone().appendTo(document.body);$copy.find(".tools, :hidden").remove();$.each(["draggable","droppable","sortable","dropped","ui-sortable","ui-draggable","ui-droppable","form-body"],function(i,c){$copy.find("."+c).removeClass(c).removeAttr("style")});var html=html_beautify($copy.html());$copy.remove();$modal=get_modal(html).modal("show");$modal.find(".btn").remove();$modal.find(".modal-title").html("复制HTML代码");$modal.find(":input:first").select().focus();return false})});var setup_draggable=function(){$(".draggable").draggable({appendTo:"body",helper:"clone"});$(".droppable").droppable({accept:".draggable",helper:"clone",hoverClass:"droppable-active",drop:function(event,ui){$(".empty-form").remove();var $orig=$(ui.draggable);if(!$(ui.draggable).hasClass("dropped")){var $el=$orig.clone().addClass("dropped").css({"position":"static","left":null,"right":null}).appendTo(this);var id=$orig.find(":input").attr("id");if(id){id=id.split("-").slice(0,-1).join("-")+"-"+(parseInt(id.split("-").slice(-1)[0])+1);$orig.find(":input").attr("id",id);$orig.find("label").attr("for",id)}$('<p class="tools col-sm-12 col-sm-offset-3"> <a class="edit-link">编辑HTML<a> | <a class="remove-link">移除</a></p>').appendTo($el)}else{if($(this)[0]!=$orig.parent()[0]){var $el=$orig.clone().css({"position":"static","left":null,"right":null}).appendTo(this);$orig.remove()}}}}).sortable()};var get_modal=function(content){var modal=$('<div class="modal" style="overflow: auto;" tabindex="-1"> <div class="modal-dialog"><div class="modal-content"><div class="modal-header"><a type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</a><h4 class="modal-title">编辑HTML</h4></div><div class="modal-body ui-front"> <textarea class="form-control textarea-show-src" style="min-height: 200px; margin-bottom: 10px;font-family: Monaco, Fixed"></textarea><button class="btn btn-success">更新HTML</button></div></div></div></div>').appendTo(document.body);var doms = document.getElementsByClassName("textarea-show-src");for (var i = 0; i < doms.length; i++) {doms.item(i).innerHTML = content;}return modal};$(document).on("click",".edit-link",function(ev){var $el=$(this).parent().parent();var $el_copy=$el.clone();var $edit_btn=$el_copy.find(".edit-link").parent().remove();var $modal=get_modal(html_beautify($el_copy.html())).modal("show");$modal.find(":input:first").focus();$modal.find(".btn-success").click(function(ev2){var html=$modal.find("textarea").val();if(!html){$el.remove()}else{$el.html(html);$edit_btn.appendTo($el)}$modal.modal("hide");return false})});$(document).on("click",".remove-link",function(ev){$(this).parent().parent().remove()});
  160. $(".input-group.date").datetimepicker({
  161. format: "yyyy-mm-dd",
  162. minView: "month",
  163. autoclose: true
  164. });
  165. </script>
  166. </body>
  167. </html>