content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
API接口管理系统
{arg.name} | {arg.required} | {arg.defaultValue} | {arg.desc} |
{returnValue.name} | {returnValue.desc} |
{arg.name}
{api.name}
接口地址 方法 描述
{api.url}
{api.method}
{api.desc}
参数说明
参数名称 必须默认值 描述
{api.args}返回值
参数名称 描述
{api.returnValues}演示
{api.forms}© 2014 AllMobilize, Inc. Licensed under
href="http://opensource.org/licenses/MIT" target="_blank">MIT license
. by the AmazeUI Team.(function(){
var temp = $("#content-template").html(), //html 模版
argTemp = $("#arg-template").html(), //参数模版
returnValueTemp = $("#returnValue-template").html(), //返回值默认
formTemp=$("#form-template").html() //表单模版
;
var html='';
/**
* 复制字符串
* @param str 字符串
* @param num 复制数量
* @returns {string}
*/
function repeat(str,num){
var n='';
for(var i=0;i
n+=str;
}
return n;
}
/**
* 获取返回值
* @param obj 返回值对象
* @param tempstr 返回值字符串
* @param depth 深度
* @returns {string|XML|*}
*/
function getReturnValues(obj,tempstr,depth){
depth = depth || 0;
var rn = obj.name || "",rd=obj.desc || "";
if(depth !=0 ){
rn && (rn = repeat(" ",depth*3)+rn);
}
tempstr += returnValueTemp.replace("{returnValue.name}",rn)
.replace("{returnValue.desc}",rd);
if(obj.sub){
if(obj.sub instanceof Array){
obj.sub.forEach(function(subRv){
var _depth = depth+1;
tempstr = getReturnValues(subRv,tempstr,_depth);
});
}else if(obj.sub instanceof Object){
for(var i in obj.sub){
var _depth = depth+1;
tempstr += returnValueTemp.replace("{returnValue.name}",repeat(" ",_depth*3)+i)
.replace("{returnValue.desc}","");
if(obj.sub[i] instanceof Array){
_depth = _depth+1;
obj.sub[i].forEach(function(sr){
tempstr = getReturnValues(sr,tempstr,_depth)
})
}
}
return tempstr;
}
}
return tempstr;
}
/**
* 绘制网页
* @param data
*/
function render(data){
var category={};
data.forEach(function(d,index){
if(!category[d.category])category[d.category]={};
category[d.category][d.name]="";
//参数,返回值,表单字符串
var args = '',returnValues='',forms='';
d.args && d.args.forEach(function(a,i){
args+=argTemp.replace("{arg.name}", a.name)
.replace("{arg.required}", a.required || true)
.replace("{arg.defaultValue}", a.defaultValue || "")
.replace("{arg.desc}", a.desc || "");
forms += formTemp.replace(/\{arg\.name\}/g, a.name)
.replace(/\{arg\.id\}/g,a.name+"_"+i+"_"+index)
.replace("{arg.type}", a.type || "text")
.replace("{arg.desc}", a.desc || "")
});
d.returnValues && d.returnValues.forEach(function(rv){
returnValues = getReturnValues(rv,returnValues);
});
html += temp.replace("{api.name}", d.name)
.replace("{api.id}", (d.category || "")+"_"+ (d.name || ""))
.replace("{api.url}", d.url)
.replace("{api.method}", d.method || "get")
.replace("{api.desc}", d.desc || "")
.replace("
{api.args}", args ).replace("
{api.returnValues}", returnValues).replace("{api.forms}",forms)
.replace("{api.target}", d.target || "")
.replace("{api.enctype}", d.enctype || "application/x-www-form-urlencoded")
.replace("{api.action}", d.url)
});
renderSidebar(category);
$("#api-content").html(html);
bindListener();
}
function renderSidebar(category){
var sidebar = '';
for(var c in category){
sidebar+='
'+c+'';if(category[c]){
for(var sc in category[c]){
if(sc){
sidebar+='
'+sc+'';}
}
}
}
$("#sidebar").html(sidebar);
}
function bindListener(){
$(".am-form").submit(function(){
$.ajax({
url:$(this).attr("action"),
type:$(this).attr("method") || "get",
dataType:"json",
data:$(this).serialize(),
success:function(rs){
$("#pre").html(new JSONFormat().parse(rs))
$("#modal").modal({width:900,height:600})
$(".icon").click(function(){
var $n = $(this).next();
if($(this).hasClass("ex")){
$n.hide();
$(this).removeClass("ex").addClass("co");
}else{
$n.show();
$(this).removeClass("co").addClass("ex");
}
});
}
});
return false;
});
}
//加载数据
$.get("api.json",{}, function (rs) {
render(rs);
},"json")
})();
一键复制
编辑
Web IDE
原始数据
按行查看
历史