edit.html 7.7 KB

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