mirror of
https://gitee.com/dromara/zyplayer-doc.git
synced 2026-05-14 11:22:07 +08:00
在线调试优化
This commit is contained in:
@@ -9,7 +9,6 @@
|
|||||||
<version>1.0.0</version>
|
<version>1.0.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<groupId>com.zyplayer</groupId>
|
|
||||||
<artifactId>zyplayer-doc-core</artifactId>
|
<artifactId>zyplayer-doc-core</artifactId>
|
||||||
<version>1.0.0</version>
|
<version>1.0.0</version>
|
||||||
<name>zyplayer-doc-core</name>
|
<name>zyplayer-doc-core</name>
|
||||||
@@ -22,17 +21,6 @@
|
|||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
|
||||||
<groupId>org.mybatis</groupId>
|
|
||||||
<artifactId>mybatis-spring</artifactId>
|
|
||||||
<version>1.3.2</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.mybatis</groupId>
|
|
||||||
<artifactId>mybatis</artifactId>
|
|
||||||
<version>3.4.6</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -116,7 +116,7 @@
|
|||||||
</ul>
|
</ul>
|
||||||
<div class="tab-content">
|
<div class="tab-content">
|
||||||
<div class="tab-pane tab-param-type-pane active" id="docRequestParam">
|
<div class="tab-pane tab-param-type-pane active" id="docRequestParam">
|
||||||
<table class="table table-bordered">
|
<table class="table table-bordered table-condensed">
|
||||||
<thead>
|
<thead>
|
||||||
<tr><th>参数名</th><th>说明</th><th>类型</th><th>参数位置</th><th>是否必填</th></tr>
|
<tr><th>参数名</th><th>说明</th><th>类型</th><th>参数位置</th><th>是否必填</th></tr>
|
||||||
</thead>
|
</thead>
|
||||||
@@ -124,7 +124,7 @@
|
|||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
<div class="tab-pane tab-param-type-pane" id="docRequestExample">
|
<div class="tab-pane tab-param-type-pane" id="docRequestExample">
|
||||||
<table class="table table-bordered">
|
<table class="table table-bordered table-condensed">
|
||||||
<thead>
|
<thead>
|
||||||
<tr><th>参数名</th><th>说明</th><th>类型</th><th>参数位置</th><th>是否必填</th></tr>
|
<tr><th>参数名</th><th>说明</th><th>类型</th><th>参数位置</th><th>是否必填</th></tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ function getNotEmptyStr(str, def) {
|
|||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
function isEmptyObject(obj){
|
function isEmptyObject(obj){
|
||||||
return $.isEmptyObject(obj);
|
return isEmpty(obj) || $.isEmptyObject(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -41,6 +41,8 @@ $(document).ready(function(){
|
|||||||
var postUrl = $("#postUrlInput").val();
|
var postUrl = $("#postUrlInput").val();
|
||||||
var requestHeaderForm = $("#requestHeaderForm").serializeArray();
|
var requestHeaderForm = $("#requestHeaderForm").serializeArray();
|
||||||
var requestParamForm = $("#requestParamForm").serializeArray();
|
var requestParamForm = $("#requestParamForm").serializeArray();
|
||||||
|
var paramHeaderSend = {};
|
||||||
|
var paramFormSend = {};
|
||||||
var paramBodySend = $("[name=paramBody]").val();
|
var paramBodySend = $("[name=paramBody]").val();
|
||||||
var formToUrl = $("[name=formToUrl]").prop('checked') ? 1 : 0;
|
var formToUrl = $("[name=formToUrl]").prop('checked') ? 1 : 0;
|
||||||
var paramSendToServer = {};
|
var paramSendToServer = {};
|
||||||
@@ -51,18 +53,15 @@ $(document).ready(function(){
|
|||||||
if (isNotEmpty(paramBodySend)) {
|
if (isNotEmpty(paramBodySend)) {
|
||||||
try {
|
try {
|
||||||
paramBodySend = JSON.stringify(JSON.parse(paramBodySend));
|
paramBodySend = JSON.stringify(JSON.parse(paramBodySend));
|
||||||
} catch (e) {
|
} catch (e) {}
|
||||||
// e
|
|
||||||
}
|
|
||||||
storeRequestParam.body = paramBodySend;
|
storeRequestParam.body = paramBodySend;
|
||||||
paramSendToServer.body = paramBodySend;
|
paramSendToServer.body = paramBodySend;
|
||||||
// 替换path参数
|
// 替换path参数
|
||||||
Object.keys(requestParamForm).forEach(function (key) {
|
Object.keys(requestParamForm).forEach(function (key) {
|
||||||
postUrl = postUrl.replace("{" + key + "}", requestParamForm[key]);
|
postUrl = postUrl.replace("{" + key + "}", requestParamForm[key]);
|
||||||
});
|
});
|
||||||
} else {
|
}
|
||||||
var reqParamStr = "";
|
var reqParamStr = "";
|
||||||
paramBodySend = {};
|
|
||||||
Object.keys(requestParamForm).forEach(function (key) {
|
Object.keys(requestParamForm).forEach(function (key) {
|
||||||
var value = requestParamForm[key];
|
var value = requestParamForm[key];
|
||||||
if (isNotEmpty(key) && isNotEmpty(value)) {
|
if (isNotEmpty(key) && isNotEmpty(value)) {
|
||||||
@@ -70,45 +69,47 @@ $(document).ready(function(){
|
|||||||
reqParamStr += "&";
|
reqParamStr += "&";
|
||||||
}
|
}
|
||||||
reqParamStr += key + "=" + value;
|
reqParamStr += key + "=" + value;
|
||||||
paramBodySend[key] = value;
|
paramFormSend[key] = value;
|
||||||
// 替换path参数
|
// 替换path参数
|
||||||
postUrl = postUrl.replace("{" + key + "}", value);
|
postUrl = postUrl.replace("{" + key + "}", value);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
storeRequestParam.form = paramBodySend;
|
storeRequestParam.form = paramFormSend;
|
||||||
|
// 表单参数是否拼在url上
|
||||||
if(formToUrl == 1) {
|
if(formToUrl == 1) {
|
||||||
postUrl += "?" + reqParamStr;
|
postUrl += "?" + reqParamStr;
|
||||||
paramBodySend = "";
|
paramFormSend = "";
|
||||||
} else {
|
} else {
|
||||||
paramSendToServer.form = JSON.stringify(paramBodySend);
|
paramSendToServer.form = JSON.stringify(paramFormSend);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
// 显示加载中图标
|
||||||
$(".send-request .icon").removeClass("hide");
|
$(".send-request .icon").removeClass("hide");
|
||||||
// 获取header
|
// 获取header
|
||||||
var requestHeaderStore = {};
|
|
||||||
Object.keys(requestHeaderForm).forEach(function(key){
|
Object.keys(requestHeaderForm).forEach(function(key){
|
||||||
var value = requestHeaderForm[key];
|
var value = requestHeaderForm[key];
|
||||||
if(isNotEmpty(key) && isNotEmpty(value)) {
|
if(isNotEmpty(key) && isNotEmpty(value)) {
|
||||||
requestHeaderStore[key] = value;
|
paramHeaderSend[key] = value;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
storeRequestParam.header = requestHeaderStore;
|
storeRequestParam.header = paramHeaderSend;
|
||||||
paramSendToServer.header = JSON.stringify(requestHeaderStore);
|
paramSendToServer.header = JSON.stringify(paramHeaderSend);
|
||||||
//console.log(paramBodySend);
|
|
||||||
var beforSendTime = new Date().getTime();
|
|
||||||
paramSendToServer.url = postUrl;
|
paramSendToServer.url = postUrl;
|
||||||
paramSendToServer.method = options;
|
paramSendToServer.method = options;
|
||||||
|
//console.log(paramBodySend);
|
||||||
|
var beforeSendTime = new Date().getTime();
|
||||||
|
// 模拟请求开始
|
||||||
ajaxTemp("swagger-mg-ui/http/request", "post", "json", paramSendToServer, function(result){
|
ajaxTemp("swagger-mg-ui/http/request", "post", "json", paramSendToServer, function(result){
|
||||||
|
var afterSendTime = new Date().getTime();
|
||||||
//console.log(result);
|
//console.log(result);
|
||||||
var requestObj = result.data;
|
var requestObj = result.data;
|
||||||
setStorage(cacheKeys.pRequestObjStart + docUrl, storeRequestParam);
|
setStorage(cacheKeys.pRequestObjStart + docUrl, storeRequestParam);
|
||||||
var afterSendTime = new Date().getTime();
|
|
||||||
$("#httpRequestStatus").text(requestObj.status);
|
$("#httpRequestStatus").text(requestObj.status);
|
||||||
$("#httpRequestTime").text((afterSendTime - beforSendTime) + "ms");
|
$("#httpRequestTime").text((afterSendTime - beforeSendTime) + "ms");
|
||||||
try {
|
try {
|
||||||
var htmlStr = Formatjson.processObjectToHtmlPre(JSON.parse(requestObj.data), 0, false, false, false, false);
|
var htmlStr = Formatjson.processObjectToHtmlPre(JSON.parse(requestObj.data), 0, false, false, false, false);
|
||||||
$("#responseBodyJsonDiv").html(htmlStr);
|
$("#responseBodyJsonDiv").html(htmlStr);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
// 转json失败,应该是个页面,输出到iframe里,不能影响当前页面
|
||||||
$("#responseBodyJsonDiv").html("<iframe id='responseBodyJsonIframe'></iframe>");
|
$("#responseBodyJsonDiv").html("<iframe id='responseBodyJsonIframe'></iframe>");
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
$("#responseBodyJsonIframe").contents().find("body").html(requestObj.data);
|
$("#responseBodyJsonIframe").contents().find("body").html(requestObj.data);
|
||||||
@@ -173,14 +174,14 @@ $(document).ready(function(){
|
|||||||
* 在线调试管理-展开所有
|
* 在线调试管理-展开所有
|
||||||
*/
|
*/
|
||||||
$(".tab-online-debug-page .expand-all").click(function(){
|
$(".tab-online-debug-page .expand-all").click(function(){
|
||||||
$("#onlineDebugParamTable .option-img").attr("src", "webjars/mg-ui/img/expanded.png")
|
$("#onlineDebugParamTable .option-img").attr("src", "webjars/mg-ui/img/expanded.png");
|
||||||
$("#onlineDebugParamTable .option-img").parent().next().show();
|
$("#onlineDebugParamTable .option-img").parent().next().show();
|
||||||
});
|
});
|
||||||
/**
|
/**
|
||||||
* 在线调试管理-收起所有
|
* 在线调试管理-收起所有
|
||||||
*/
|
*/
|
||||||
$(".tab-online-debug-page .collapse-all").click(function(){
|
$(".tab-online-debug-page .collapse-all").click(function(){
|
||||||
$("#onlineDebugParamTable .option-img").attr("src", "webjars/mg-ui/img/collapsed.png")
|
$("#onlineDebugParamTable .option-img").attr("src", "webjars/mg-ui/img/collapsed.png");
|
||||||
$("#onlineDebugParamTable .option-img").parent().next().hide();
|
$("#onlineDebugParamTable .option-img").parent().next().hide();
|
||||||
});
|
});
|
||||||
/**
|
/**
|
||||||
@@ -257,6 +258,7 @@ function createOnlineDebugParamTable() {
|
|||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
function createOnlineDebugRequestParam(requestParamObj, url) {
|
function createOnlineDebugRequestParam(requestParamObj, url) {
|
||||||
|
// 查询之前的调试参数信息
|
||||||
getStorage(cacheKeys.pRequestObjStart + url, function(data) {
|
getStorage(cacheKeys.pRequestObjStart + url, function(data) {
|
||||||
createOnlineDebugRequestParamFun(data, requestParamObj, url);
|
createOnlineDebugRequestParamFun(data, requestParamObj, url);
|
||||||
});
|
});
|
||||||
@@ -264,7 +266,9 @@ function createOnlineDebugRequestParam(requestParamObj, url) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 生成在线调试相关数据
|
* 生成在线调试相关数据
|
||||||
* @param requestParamObj
|
* @param pRequestObj 之前的调试参数
|
||||||
|
* @param requestParamObj 参数列表的参数
|
||||||
|
* @param url 请求url
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
function createOnlineDebugRequestParamFun(pRequestObj, requestParamObj, url) {
|
function createOnlineDebugRequestParamFun(pRequestObj, requestParamObj, url) {
|
||||||
@@ -306,9 +310,6 @@ function createOnlineDebugRequestParamFun(pRequestObj, requestParamObj, url) {
|
|||||||
if(typeof pRequestObj.form != 'object') {
|
if(typeof pRequestObj.form != 'object') {
|
||||||
pRequestObj.form = {};
|
pRequestObj.form = {};
|
||||||
}
|
}
|
||||||
if(typeof pRequestObj.body != 'object') {
|
|
||||||
pRequestObj.body = {};
|
|
||||||
}
|
|
||||||
for (var i = 0; i < debugGlobalParam.length; i++) {
|
for (var i = 0; i < debugGlobalParam.length; i++) {
|
||||||
var item = debugGlobalParam[i];
|
var item = debugGlobalParam[i];
|
||||||
if (item.paramIn == 'header') {
|
if (item.paramIn == 'header') {
|
||||||
@@ -330,7 +331,7 @@ function createOnlineDebugRequestParamFun(pRequestObj, requestParamObj, url) {
|
|||||||
}
|
}
|
||||||
$("#tabParamTypeBody textarea").val(JSON.stringify(paramObj, null, 4));
|
$("#tabParamTypeBody textarea").val(JSON.stringify(paramObj, null, 4));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
var tempText = isEmpty(bodyObj) ? JSON.stringify(paramObj, null, 4) : bodyObj;
|
var tempText = isEmptyObject(bodyObj) ? JSON.stringify(paramObj, null, 4) : bodyObj;
|
||||||
$("#tabParamTypeBody textarea").val(tempText);
|
$("#tabParamTypeBody textarea").val(tempText);
|
||||||
}
|
}
|
||||||
$("#tabParamBody .nav li").eq(1).find("a").click();
|
$("#tabParamBody .nav li").eq(1).find("a").click();
|
||||||
|
|||||||
Reference in New Issue
Block a user