123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- <link rel="stylesheet" href="/static/editor.md/css/editormd.min.css" />
- <div class="layui-layout layui-layout-admin" style="padding-left: 40px;margin-top: 20px;">
- <form class="layui-form" action="" method="post">
- <input type="hidden" name="id" value="{{.Detail.id}}">
- <div class="layui-form-item">
- <label class="layui-form-label">分组资源</label>
-
- <div class="layui-input-inline">
- <select name="source_id" lay-verify="required" lay-search="" style="width: 100%">
- <option value="">所属资源</option>
- {{range $index,$elem := .sourceList}}
- <option value="{{$elem.Id}}" {{if eq $elem.Id $.Detail.source_id}} selected {{end}}> {{$elem.GroupName}}--{{$elem.SourceName}}</option>
- {{end}}
- </select>
- </div>
- </div>
- <div class="layui-form-item">
- <label class="layui-form-label">接口名称</label>
- <div class="layui-input-block " style="width: 400px">
- <input type="text" name="api_name" id="api_name" lay-verify="required" autocomplete="off" placeholder="接口名称:获取用户列表" class="layui-input" value="{{.Detail.api_name}}">
- </div>
- </div>
- <div class="layui-form-item">
- <label class="layui-form-label">接口地址</label>
- <div class="layui-input-inline" style="width: 400px">
- <input type="text" name="api_url" id="api_url" lay-verify="required" autocomplete="off" placeholder="/User 注意不写host" class="layui-input" value="{{.Detail.api_url}}">
- </div>
- </div>
- <div class="layui-form-item">
- <label class="layui-form-label">请求方式</label>
- <div class="layui-input-block ">
- <input type="radio" name="method" value="1" title="GET" {{if eq .Detail.method 1}}checked{{end}}>
- <input type="radio" name="method" value="2" title="POST" {{if eq .Detail.method 2}}checked{{end}}>
- <input type="radio" name="method" value="3" title="PUT" {{if eq .Detail.method 3}}checked{{end}}>
- <input type="radio" name="method" value="4" title="PATCH" {{if eq .Detail.method 4}}checked{{end}}>
- <input type="radio" name="method" value="5" title="DELETE" {{if eq .Detail.method 5}}checked{{end}}>
- </div>
- </div>
- <div class="layui-form-item">
- <label class="layui-form-label">选择模板</label>
-
- <div class="layui-input-inline">
- <select name="templates" lay-filter="templates" lay-verify="required" lay-search="" style="width: 100%">
- <option value="0">选择内容模板</option>
- {{range $index,$elem := .templates}}
- <option value="{{$elem.Id}}"> {{$elem.TemplateName}}</option>
- {{end}}
- </select>
- </div>
- </div>
- <div class="layui-form-item">
- <label class="layui-form-label">接口详细</label>
- <div class="layui-input-inline" id="api-editormd" style="border: 1px solid #e4e4e4">
- <textarea name="detail" style="display:none;">
- {{.Detail.detail}}
- </textarea>
- </div>
- </div>
-
- <div class="layui-form-item">
- <div class="layui-input-block">
- <button class="layui-btn" lay-submit="" lay-filter="sub">保存</button>
- <button type="reset" class="layui-btn layui-btn-primary">重置</button>
- </div>
- </div>
- </form>
- </div>
- <script>
- var templates = {{.templates}}
- var apiEditor;
- layui.use(['form','element','table','layer','jquery'],function(){
- var form = layui.form; //只有执行了这一步,部分表单元素才会自动修饰成功
- var $ = layui.jquery;
- var table = layui.table;
- form.on('submit(sub)', function(data){
- var form_data = data.field;
- console.log(form_data);
- $.post('{{urlfor "ApiController.AjaxSave"}}', form_data, function (out) {
- if (out.status == 0) {
- layer.msg("操作成功",{icon: 1},function () {
- window.location.href="/api/list";
- })
- } else {
- layer.msg(out.message)
- }
- }, "json");
- return false;
- });
- form.on('select(templates)', function(data){
- layer.confirm('是否切换模板?', {
- btn: ['确定', '取消'] //可以无限个按钮
- ,btn2: function(index, layero){
- layer.close(index);
- }
- }, function(index, layero){
- $.each(templates,function(k,v){
- if (v.Id==data.value) {
- apiEditor.setMarkdown(v.Detail)
- }
- });
- layer.close(index);
- });
-
- });
- //但是,如果你的HTML是动态生成的,自动渲染就会失效
- //因此你需要在相应的地方,执行下述方法来手动渲染,跟这类似的还有 element.init();
- form.render();
- });
- </script>
- {{template "public/editormd.html" .}}
|