edit.html 3.7 KB

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