add.html 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. <div class="layui-form-item">
  5. <label class="layui-form-label">分组资源</label>
  6. <div class="layui-input-inline">
  7. <select name="source_id" lay-verify="required" lay-search="" style="width: 100%">
  8. <option value="">所属资源</option>
  9. {{range $index,$elem := .sourceList}}
  10. <option value="{{$elem.Id}}"> {{$elem.GroupName}}--{{$elem.SourceName}}</option>
  11. {{end}}
  12. </select>
  13. </div>
  14. </div>
  15. <div class="layui-form-item">
  16. <label class="layui-form-label">接口名称</label>
  17. <div class="layui-input-block " style="width: 400px">
  18. <input type="text" name="api_name" id="api_name" lay-verify="required" autocomplete="off" placeholder="接口名称:获取用户列表" class="layui-input" value="">
  19. </div>
  20. </div>
  21. <div class="layui-form-item">
  22. <label class="layui-form-label">接口地址</label>
  23. <div class="layui-input-inline" style="width: 400px">
  24. <input type="text" name="api_url" id="api_url" lay-verify="required" autocomplete="off" placeholder="/User 注意不写host" class="layui-input" value="">
  25. </div>
  26. </div>
  27. <div class="layui-form-item">
  28. <label class="layui-form-label">请求方式</label>
  29. <div class="layui-input-block ">
  30. <input type="radio" name="method" value="1" title="GET" checked>
  31. <input type="radio" name="method" value="2" title="POST">
  32. <input type="radio" name="method" value="3" title="PUT">
  33. <input type="radio" name="method" value="5" title="DELETE">
  34. <input type="radio" name="method" value="4" title="PATCH">
  35. </div>
  36. </div>
  37. <div class="layui-form-item">
  38. <label class="layui-form-label">选择模板</label>
  39. <div class="layui-input-inline">
  40. <select name="templates" lay-filter="templates" lay-verify="required" lay-search="" style="width: 100%">
  41. <option value="0">选择内容模板</option>
  42. {{range $index,$elem := .templates}}
  43. <option value="{{$elem.Id}}"> {{$elem.TemplateName}}</option>
  44. {{end}}
  45. </select>
  46. </div>
  47. </div>
  48. <div class="layui-form-item">
  49. <label class="layui-form-label">接口详细</label>
  50. <div class="layui-input-inline" id="api-editormd" style="border: 1px solid #e4e4e4">
  51. <textarea name="detail" style="display:none;">
  52. #### 简要描述:
  53. - 用户登录接口
  54. #### 请求头:
  55. |参数名|是否必须|类型|说明|
  56. |:---- |:---|:----- |----- |
  57. |Content-Type |是 |string |请求类型: application/json |
  58. |Content-MD5 |是 |string | 请求内容签名 |
  59. #### 请求参数:
  60. |参数名|是否必须|类型|说明|示例值
  61. |:---- |:---|:----- |----- |----- |
  62. |username |是 |string |用户名 | george518
  63. |password |是 |string | 密码 | george518
  64. #### 返回参数:
  65. |参数名|类型|说明|
  66. |:----- |:-----|----- |
  67. |group_level |int |用户组id,1:超级管理员;2:普通用户 |
  68. #### 返回示例:
  69. **正确时返回:**
  70. ```
  71. {
  72. "status": 200,
  73. "message": "Success",
  74. "data": {
  75. "uid": "1",
  76. "account": "admin",
  77. "nickname": "Minho",
  78. "group_level": 0 ,
  79. "create_time": "1436864169",
  80. "last_login_time": "0",
  81. }
  82. }
  83. ```
  84. **错误时返回:**
  85. ```
  86. {
  87. "status": 300,
  88. "message": "invalid username"
  89. "data":{
  90. }
  91. }
  92. ```
  93. #### 调用示例:
  94. ```
  95. <?php
  96. echo "Hello world";
  97. ```
  98. #### 备注:
  99. - 更多返回错误代码请看首页的错误代码描述
  100. #### 接口版本:
  101. |版本号|制定人|制定日期|修订日期|
  102. |:---- |:---|:----- |----- |
  103. |2.1.0 |郝大全 |2018-01-15 | 2018-01-15 |
  104. </textarea>
  105. </div>
  106. </div>
  107. <div class="layui-form-item">
  108. <div class="layui-input-block">
  109. <button class="layui-btn" lay-submit="" lay-filter="sub">保存</button>
  110. <button type="reset" class="layui-btn layui-btn-primary">重置</button>
  111. </div>
  112. </div>
  113. </form>
  114. </div>
  115. <script>
  116. var templates = {{.templates}}
  117. var apiEditor;
  118. layui.use(['form','element','table','layer','jquery'],function(){
  119. var form = layui.form; //只有执行了这一步,部分表单元素才会自动修饰成功
  120. var $ = layui.jquery;
  121. var table = layui.table;
  122. form.on('submit(sub)', function(data){
  123. var form_data = data.field;
  124. $.post('{{urlfor "ApiController.AjaxSave"}}', form_data, function (out) {
  125. if (out.status == 0) {
  126. layer.msg("操作成功",{icon: 1},function () {
  127. window.location.href="/api/list";
  128. })
  129. } else {
  130. layer.msg(out.message)
  131. }
  132. }, "json");
  133. return false;
  134. });
  135. form.on('select(templates)', function(data){
  136. layer.confirm('是否切换模板?', {
  137. btn: ['确定', '取消'] //可以无限个按钮
  138. ,btn2: function(index, layero){
  139. layer.close(index);
  140. }
  141. }, function(index, layero){
  142. $.each(templates,function(k,v){
  143. if (v.Id==data.value) {
  144. apiEditor.setMarkdown(v.Detail)
  145. }
  146. });
  147. layer.close(index);
  148. });
  149. });
  150. //但是,如果你的HTML是动态生成的,自动渲染就会失效
  151. //因此你需要在相应的地方,执行下述方法来手动渲染,跟这类似的还有 element.init();
  152. form.render();
  153. });
  154. </script>
  155. {{template "public/editormd.html" .}}