add.html 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <div class="layui-layout layui-layout-admin" style="padding-left: 40px;margin-top: 20px;">
  2. <link rel="stylesheet" href="/static/editor.md/css/editormd.min.css" />
  3. <div style="margin: 10px 0px">
  4. <blockquote class="layui-elem-quote">
  5. 说明:仅仅支持一级分组
  6. </blockquote>
  7. </div>
  8. <form class="layui-form" action="" method="post" >
  9. <div class="layui-form-item">
  10. <label class="layui-form-label">分组名称</label>
  11. <div class="layui-input-inline">
  12. <input type="text" name="group_name" id="group_name" lay-verify="required" autocomplete="off" placeholder="分组名称" class="layui-input" value="">
  13. </div>
  14. <div class="layui-form-mid layui-word-aux">*</div>
  15. </div>
  16. <div class="layui-form-item layui-form-text">
  17. <label class="layui-form-label">说明</label>
  18. <div class="layui-input-inline" style="width: 600px;">
  19. <!-- <textarea name="detail" id="detail" placeholder="请输入内容" class="layui-textarea"></textarea> -->
  20. <textarea id="detail" name="detail" style="display: none;"></textarea>
  21. </div>
  22. </div>
  23. <div class="layui-form-item">
  24. <label class="layui-form-label">环境配置</label>
  25. <div class="layui-input-block">
  26. {{range $k, $v := .envlists}}
  27. <input type="checkbox" name="env_ids[]" lay-filter="env_ids" title="{{$v.EnvName}}" value="{{$v.Id}}">
  28. {{end}}
  29. </div>
  30. </div>
  31. <div class="layui-form-item">
  32. <label class="layui-form-label">状态码</label>
  33. <div class="layui-input-block">
  34. {{range $k, $v := .codelists}}
  35. <input type="checkbox" name="code_ids[]" lay-filter="code_ids" title="{{$v.Code}}" value="{{$v.Id}}">
  36. {{end}}
  37. </div>
  38. </div>
  39. <div class="layui-form-item">
  40. <label class="layui-form-label">公共文档</label>
  41. <div class="layui-input-block">
  42. {{range $k, $v := .apiPublicLists}}
  43. <input type="checkbox" name="api_public_ids[]" lay-filter="api_public_ids" title="{{$v.ApiPublicName}}" value="{{$v.Id}}">
  44. {{end}}
  45. </div>
  46. </div>
  47. <div class="layui-form-item">
  48. <div class="layui-input-block">
  49. <button class="layui-btn" lay-submit="" lay-filter="sub">立即提交</button>
  50. <button type="reset" class="layui-btn layui-btn-primary">重置</button>
  51. </div>
  52. </div>
  53. </form>
  54. </div>
  55. <script>
  56. layui.use(['form','element','layer','jquery','layedit'],function(){
  57. var form = layui.form; //只有执行了这一步,部分表单元素才会自动修饰成功
  58. var $ = layui.jquery;
  59. var layedit = layui.layedit;
  60. var index = layedit.build('detail' , {
  61. tool: [
  62. 'strong' //加粗
  63. ,'italic' //斜体
  64. ,'underline' //下划线
  65. ,'del' //删除线
  66. ,'|' //分割线
  67. ,'left' //左对齐
  68. ,'center' //居中对齐
  69. ,'right' //右对齐
  70. ,'link' //超链接
  71. ,'unlink' //清除链接
  72. ,'face' //表情
  73. ,'image' //插入图片
  74. ],
  75. height: 180
  76. }); //建立编辑器
  77. var env_ids,api_public_ids,code_ids;
  78. var envids=[],apipublicids=[],codeids=[];
  79. form.on('checkbox(env_ids)', function(data){
  80. if(data.elem.checked==true){
  81. envids.push(data.value)
  82. }else{
  83. $.each(envids,function(index,item){
  84. // index是索引值(即下标) item是每次遍历得到的值;
  85. if(item==data.value){
  86. envids.splice(index,1);
  87. }
  88. });
  89. }
  90. envids.sort();
  91. env_ids = envids.join(",");
  92. });
  93. form.on('checkbox(api_public_ids)', function(data){
  94. if(data.elem.checked==true){
  95. apipublicids.push(data.value)
  96. }else{
  97. $.each(apipublicids,function(index,item){
  98. // index是索引值(即下标) item是每次遍历得到的值;
  99. if(item==data.value){
  100. apipublicids.splice(index,1);
  101. }
  102. });
  103. }
  104. apipublicids.sort();
  105. api_public_ids = apipublicids.join(",");
  106. });
  107. form.on('checkbox(code_ids)', function(data){
  108. if(data.elem.checked==true){
  109. codeids.push(data.value)
  110. }else{
  111. $.each(codeids,function(index,item){
  112. // index是索引值(即下标) item是每次遍历得到的值;
  113. if(item==data.value){
  114. codeids.splice(index,1);
  115. }
  116. });
  117. }
  118. codeids.sort();
  119. code_ids = codeids.join(",");
  120. });
  121. form.on('checkbox(env_ids)', function(data){
  122. if(data.elem.checked==true){
  123. envids.push(data.value)
  124. }else{
  125. $.each(envids,function(index,item){
  126. // index是索引值(即下标) item是每次遍历得到的值;
  127. if(item==data.value){
  128. envids.splice(index,1);
  129. }
  130. });
  131. }
  132. envids.sort();
  133. env_ids = envids.join(",");
  134. });
  135. form.on('submit(sub)', function(data){
  136. var form_data = data.field;
  137. form_data.env_ids = env_ids;
  138. form_data.api_public_ids = api_public_ids;
  139. form_data.code_ids = code_ids;
  140. form_data.detail = layedit.getContent(index);
  141. if (!env_ids || !api_public_ids || !code_ids) {
  142. layer.msg("请选择环境、状态码、公共文档");
  143. return false;
  144. }
  145. $.post('{{urlfor "GroupController.AjaxSave"}}', form_data, function (out) {
  146. if (out.status == 0) {
  147. layer.msg("操作成功",{icon: 1},function () {
  148. window.location.href='{{urlfor "GroupController.List"}}'
  149. })
  150. } else {
  151. layer.msg(out.message)
  152. }
  153. }, "json");
  154. return false;
  155. });
  156. //但是,如果你的HTML是动态生成的,自动渲染就会失效
  157. //因此你需要在相应的地方,执行下述方法来手动渲染,跟这类似的还有 element.init();
  158. form.render();
  159. });
  160. </script>