Merge branch 'develop'

1.x
tanghc 6 years ago
commit 0f6e981696
  1. 9
      sop-website/website-front/assets/js/format.js
  2. 27
      sop-website/website-front/pages/doc/doc.js

@ -8,13 +8,12 @@
function formatJson(txt,compress/*是否为压缩模式*/){/* 格式化JSON源码(对象转换为JSON文本) */ function formatJson(txt,compress/*是否为压缩模式*/){/* 格式化JSON源码(对象转换为JSON文本) */
var indentChar = ' '; var indentChar = ' ';
if(/^\s*$/.test(txt)){ if(/^\s*$/.test(txt)){
alert('数据为空,无法格式化! '); return '';
return;
} }
try{var data=eval('('+txt+')');} try{var data=eval('('+txt+')');}
catch(e){ catch(e){
alert('数据源语法错误,格式化失败! 错误信息: '+e.description,'err'); console.error('json格式错误,无法格式化,格式化内容:' + txt);
return; return txt;
}; };
var draw=[],last=false,This=this,line=compress?'':'\n',nodeCount=0,maxDepth=0; var draw=[],last=false,This=this,line=compress?'':'\n',nodeCount=0,maxDepth=0;

@ -144,14 +144,9 @@ layui.config({
} }
function createResponseCode(docItem) { function createResponseCode(docItem) {
var responseParameters = docItem.responseParameters;
var method = docItem.name.replace(/\./g, '_'); var method = docItem.name.replace(/\./g, '_');
var result = []; var responseParameters = docItem.responseParameters;
for (var i = 0; i < responseParameters.length; i++) { var bizResult = buildResult(responseParameters);
var responseParameter = responseParameters[i];
result.push('\"'+responseParameter.name+'\": \"' + responseParameter.example + '\"')
}
var bizResult = result.join(",");
var json = '{\n' + var json = '{\n' +
' "'+method+'_response": {\n' + ' "'+method+'_response": {\n' +
' "code": "10000",\n' + ' "code": "10000",\n' +
@ -176,6 +171,24 @@ layui.config({
$('#responseErrorJson').text(errorJson); $('#responseErrorJson').text(errorJson);
} }
function buildResult(parameters) {
var result = [];
for (var i = 0; i < parameters.length; i++) {
var parameter = parameters[i];
result.push('\"'+parameter.name+'\": ' + buildExample(parameter))
}
return result.join(",");
}
function buildExample(parameter) {
var refs = parameter.refs;
if (refs) {
return '{' + buildResult(refs) + '}';
} else {
return '\"' + parameter.example + '\"';
}
}
initDocModules(); initDocModules();
initEvent(); initEvent();
}); });
Loading…
Cancel
Save