add.html 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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-block " style="width: 400px">
  7. <input type="text" name="api_public_name" id="api_public_name" lay-verify="required" autocomplete="off" placeholder="比如:调用说明" class="layui-input" value="">
  8. </div>
  9. </div>
  10. <div class="layui-form-item">
  11. <label class="layui-form-label">排序</label>
  12. <div class="layui-input-block " style="width: 200px">
  13. <input type="text" name="sort" id="sort" lay-verify="required" autocomplete="off" placeholder="数字" class="layui-input" value="99">
  14. </div>
  15. </div>
  16. <div class="layui-form-item">
  17. <label class="layui-form-label">选择模板</label>
  18. <div class="layui-input-inline">
  19. <select name="source_id" lay-filter="templates" lay-verify="required" lay-search="" style="width: 100%">
  20. <option value="0">选择内容模板</option>
  21. {{range $index,$elem := .templates}}
  22. <option value="{{$elem.Id}}"> {{$elem.TemplateName}}</option>
  23. {{end}}
  24. </select>
  25. </div>
  26. </div>
  27. <div class="layui-form-item">
  28. <label class="layui-form-label">文档内容</label>
  29. <div class="layui-input-inline" id="api-editormd" style="border: 1px solid #e4e4e4">
  30. <textarea name="detail" id="detail" style="display:none;">
  31. #### 可以选择模板,亲
  32. </textarea>
  33. </div>
  34. </div>
  35. <div class="layui-form-item">
  36. <div class="layui-input-block">
  37. <button class="layui-btn" lay-submit="" lay-filter="sub">保存</button>
  38. <button type="reset" class="layui-btn layui-btn-primary">重置</button>
  39. </div>
  40. </div>
  41. </form>
  42. </div>
  43. <script>
  44. var templates = {{.templates}}
  45. var apiEditor;
  46. layui.use(['form','element','table','layer','jquery'],function(){
  47. var form = layui.form; //只有执行了这一步,部分表单元素才会自动修饰成功
  48. var $ = layui.jquery;
  49. var table = layui.table;
  50. form.on('submit(sub)', function(data){
  51. var form_data = data.field;
  52. $.post('{{urlfor "ApiPublicController.AjaxSave"}}', form_data, function (out) {
  53. if (out.status == 0) {
  54. layer.msg("操作成功",{icon: 1},function () {
  55. window.location.href="/apipublic/list";
  56. })
  57. } else {
  58. layer.msg(out.message)
  59. }
  60. }, "json");
  61. return false;
  62. });
  63. form.on('select(templates)', function(data){
  64. layer.confirm('是否切换模板?', {
  65. btn: ['确定', '取消'] //可以无限个按钮
  66. ,btn2: function(index, layero){
  67. layer.close(index);
  68. }
  69. }, function(index, layero){
  70. $.each(templates,function(k,v){
  71. if (v.Id==data.value) {
  72. apiEditor.setMarkdown(v.Detail)
  73. form.render();
  74. }
  75. });
  76. layer.close(index);
  77. });
  78. });
  79. //但是,如果你的HTML是动态生成的,自动渲染就会失效
  80. //因此你需要在相应的地方,执行下述方法来手动渲染,跟这类似的还有 element.init();
  81. form.render();
  82. });
  83. </script>
  84. {{template "public/editormd.html" .}}