edit.html 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <link rel="stylesheet" href="/static/editor.md/css/editormd.min.css" />
  2. <div class="layui-layout layui-layout-admin" style="padding-left: 40px;margin-top: 20px;">
  3. <form class="layui-form" action="" method="post">
  4. <input type="hidden" name="id" value="{{.Detail.id}}">
  5. <div class="layui-form-item">
  6. <label class="layui-form-label">分组资源</label>
  7. <div class="layui-input-inline">
  8. <select name="source_id" lay-verify="required" lay-search="" style="width: 100%">
  9. <option value="">所属资源</option>
  10. {{range $index,$elem := .sourceList}}
  11. <option value="{{$elem.Id}}" {{if eq $elem.Id $.Detail.source_id}} selected {{end}}> {{$elem.GroupName}}--{{$elem.SourceName}}</option>
  12. {{end}}
  13. </select>
  14. </div>
  15. </div>
  16. <div class="layui-form-item">
  17. <label class="layui-form-label">接口名称</label>
  18. <div class="layui-input-block " style="width: 400px">
  19. <input type="text" name="api_name" id="api_name" lay-verify="required" autocomplete="off" placeholder="接口名称:获取用户列表" class="layui-input" value="{{.Detail.api_name}}">
  20. </div>
  21. </div>
  22. <div class="layui-form-item">
  23. <label class="layui-form-label">接口地址</label>
  24. <div class="layui-input-inline" style="width: 400px">
  25. <input type="text" name="api_url" id="api_url" lay-verify="required" autocomplete="off" placeholder="/User 注意不写host" class="layui-input" value="{{.Detail.api_url}}">
  26. </div>
  27. </div>
  28. <div class="layui-form-item">
  29. <label class="layui-form-label">请求方式</label>
  30. <div class="layui-input-block ">
  31. <input type="radio" name="method" value="1" title="GET" {{if eq .Detail.method 1}}checked{{end}}>
  32. <input type="radio" name="method" value="2" title="POST" {{if eq .Detail.method 2}}checked{{end}}>
  33. <input type="radio" name="method" value="3" title="PUT" {{if eq .Detail.method 3}}checked{{end}}>
  34. <input type="radio" name="method" value="4" title="PATCH" {{if eq .Detail.method 4}}checked{{end}}>
  35. <input type="radio" name="method" value="5" title="DELETE" {{if eq .Detail.method 5}}checked{{end}}>
  36. </div>
  37. </div>
  38. <div class="layui-form-item">
  39. <label class="layui-form-label">选择模板</label>
  40. <div class="layui-input-inline">
  41. <select name="templates" lay-filter="templates" lay-verify="required" lay-search="" style="width: 100%">
  42. <option value="0">选择内容模板</option>
  43. {{range $index,$elem := .templates}}
  44. <option value="{{$elem.Id}}"> {{$elem.TemplateName}}</option>
  45. {{end}}
  46. </select>
  47. </div>
  48. </div>
  49. <div class="layui-form-item">
  50. <label class="layui-form-label">接口详细</label>
  51. <div class="layui-input-inline" id="api-editormd" style="border: 1px solid #e4e4e4">
  52. <textarea name="detail" style="display:none;">
  53. {{.Detail.detail}}
  54. </textarea>
  55. </div>
  56. </div>
  57. <div class="layui-form-item">
  58. <div class="layui-input-block">
  59. <button class="layui-btn" lay-submit="" lay-filter="sub">保存</button>
  60. <button type="reset" class="layui-btn layui-btn-primary">重置</button>
  61. </div>
  62. </div>
  63. </form>
  64. </div>
  65. <script>
  66. var templates = {{.templates}}
  67. var apiEditor;
  68. layui.use(['form','element','table','layer','jquery'],function(){
  69. var form = layui.form; //只有执行了这一步,部分表单元素才会自动修饰成功
  70. var $ = layui.jquery;
  71. var table = layui.table;
  72. form.on('submit(sub)', function(data){
  73. var form_data = data.field;
  74. console.log(form_data);
  75. $.post('{{urlfor "ApiController.AjaxSave"}}', form_data, function (out) {
  76. if (out.status == 0) {
  77. layer.msg("操作成功",{icon: 1},function () {
  78. window.location.href="/api/list";
  79. })
  80. } else {
  81. layer.msg(out.message)
  82. }
  83. }, "json");
  84. return false;
  85. });
  86. form.on('select(templates)', function(data){
  87. layer.confirm('是否切换模板?', {
  88. btn: ['确定', '取消'] //可以无限个按钮
  89. ,btn2: function(index, layero){
  90. layer.close(index);
  91. }
  92. }, function(index, layero){
  93. $.each(templates,function(k,v){
  94. if (v.Id==data.value) {
  95. apiEditor.setMarkdown(v.Detail)
  96. }
  97. });
  98. layer.close(index);
  99. });
  100. });
  101. //但是,如果你的HTML是动态生成的,自动渲染就会失效
  102. //因此你需要在相应的地方,执行下述方法来手动渲染,跟这类似的还有 element.init();
  103. form.render();
  104. });
  105. </script>
  106. {{template "public/editormd.html" .}}