callApi.html 4.34 KB
<form class="r4" style="max-height:250px;overflow: auto;">
    <div class="fgroup" data-prop="path" required>
        <label>{{SystemEnv.getHtmlNoteName(6007)}}:</label>	<!-- 接口名称: -->
        <select id="ref-list-api" data-placeholder="{{SystemEnv.getHtmlNoteName(6008)}}"><!-- 请选择调用的接口 -->
            <option></option>
            {{
                APIList.reduce(function(prev, item) {
                    prev += "<option data-remark='"+ item.basic.remark + "' data-type='"+ item.basic.front.requestMethod + "' data-cfg='"+ item.basic.return.contentType + "' data-id='"+ item.basic.id + "' value='"+ item.basic.front.path + "'>" + item.basic.name + "</option>";
                    return prev;
                }, '')
            }}
        </select>
    </div>
    <div class="fgroup hide" id="ref-list-type" data-prop="type">
        <input type="text"/><!-- 请求方式 -->
    </div>
    <div class="fgroup hide" id="ref-list-cfg" data-prop="cfg">
        <input type="text"/><!-- 数据类型 -->
    </div>
    <div class="fgroup" id="ref-list-params" data-params="json" data-prop="params">
        <label class="param-des" style="display: none;">{{SystemEnv.getHtmlNoteName(4982)}}</label><!-- 描述: -->
        <span class="param-des" id="ref-list-remark" style="vertical-align: middle;color: #888;display: none;"></span>
        <br class="param-des" style="display: none;" />
        <br class="param-des" style="display: none;" />
        <label class="param-item" style="display: none;">{{SystemEnv.getHtmlNoteName(4983)}}</label><!-- 参数: -->
        <div class="f-params normal param-item" style="display: none;">
        </div>   
    </div>
    
    <script>
        (function() {
            require(['components/common','i18n/lang'], function(common,lang) {
                $("#ref-list-api").on("change", function() {
                    var $this = $(this);
                    var remark = $this.find(":selected").data("remark"),
                        id = $this.find(":selected").data("id"),
                        type = $this.find(":selected").data("type"),
                        cfg = $this.find(":selected").data("cfg"),html;
                    var $param = $('#ref-list-params').children('.f-params'),
                        $remark = $('#ref-list-remark'),
                        $type = $('#ref-list-type input'),
                        $cfg = $('#ref-list-cfg input'),
                        $remarkLine = $('.param-des'),
                        $paramLine = $('.param-item');
                    
                    $remark.html(lang.parse(String(remark)));
                    $remarkLine.toggle(!!remark);
                    if(type==='ANY'){
                        $type.val('');
                    }else{
                        $type.val(type);
                    }
                    $cfg.val(cfg);
                    if(!id){
                        $param.html('');
                        $remark.html('');
                        $type.val('');
                        $cfg.val('');
                        $remarkLine.hide();
                        $paramLine.hide();
                    }else{
                        common.api('api', {
                            action: "info",
                            type: "get",
                            data: { id: id }
                        }).then(function(res) {
                            var data = res.data.frontParameter;
                            var html = '';
                            html = data.reduce(function(prev,item){
                                        prev += '<div>\
                                                    <input class="f-params-key" type="text" value="'+item.name+'" placeholder="'+SystemEnv.getHtmlNoteName(5113)+'"/><!-- 参数名称 -->\
                                                    <span>=</span>\
                                                    <input class="f-params-value" type="text" placeholder="'+lang.parse(item.remark)+'"/><!-- 参数值 -->\
                                                </div>';
                                        return prev;
                                    },'');
                            $param.html(html);
                            $paramLine.toggle(!!html);
                        });
                    }
                });
            })
        })()
    </script>
</form>