各种细节打磨优化,增加提示

This commit is contained in:
暮光:城中城
2019-02-02 21:17:44 +08:00
committed by zhanghongli
parent 15cfa7e2d1
commit e96418e346
13 changed files with 112 additions and 63 deletions

View File

@@ -26,7 +26,6 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.net.URLEncoder;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
/**
@@ -126,9 +125,11 @@ public class MgDocumentController {
}
locationList.addAll(locationListStorage);
this.storageSwaggerLocationList(locationListStorage);
AtomicInteger idIndex = new AtomicInteger(1);
resourcesSet.forEach(val -> val.setId(idIndex.getAndIncrement()));
resourcesSet.forEach(val -> {
if (val.getId() == null) {
val.setId(storageService.getNextId());
}
});
storageService.put(StorageKeys.SWAGGER_RESOURCES_LIST, JSON.toJSONString(resourcesSet));
}
List<String> swaggerResourceStrList = new LinkedList<>();
@@ -316,15 +317,18 @@ public class MgDocumentController {
SwaggerResourcesInfoVo resourcesInfoVo = new SwaggerResourcesInfoVo(resourcesUrl, resourceList);
resourcesInfoVo.setRewriteDomainUrl(rewriteDomainUrl);
resourcesList.add(resourcesInfoVo);
AtomicInteger idIndex = new AtomicInteger(1);
resourcesList.forEach(val -> val.setId(idIndex.getAndIncrement()));
resourcesList.forEach(val -> {
if (val.getId() == null) {
val.setId(storageService.getNextId());
}
});
}
} catch (Exception e) {
logger.error("获取文档失败:{}{}", resourcesUrl, e.getMessage());
return DocResponseJson.warn("该地址查找文档失败");
}
// 去重
resourcesList = resourcesList.stream().distinct().collect(Collectors.toList());
resourcesList = resourcesList.stream().distinct().sorted(Comparator.comparing(SwaggerResourcesInfoVo::getId)).collect(Collectors.toList());
storageService.put(StorageKeys.SWAGGER_RESOURCES_LIST, JSON.toJSONString(resourcesList));
return DocResponseJson.ok();
}
@@ -366,20 +370,16 @@ public class MgDocumentController {
*
* @author 暮光:城中城
* @since 2018年8月21日
* @param docUrl 文档地址
* @param location 文档地址
* @return 删除结果
*/
@Deprecated
@PostMapping(value = "/deleteSwaggerDoc")
public ResponseJson<Object> deleteSwaggerDoc(String docUrl) {
// String swaggerDocsDeleteStr = storageService.get(StorageKeys.SWAGGER_DOCS_DELETE_LIST);
// Set<String> swaggerDocsDeleteSet = new HashSet<>();
// if (StringUtils.isNotBlank(swaggerDocsDeleteStr)) {
// List<String> swaggerDocsDeleteList = JSON.parseArray(swaggerDocsDeleteStr, String.class);
// swaggerDocsDeleteSet.addAll(swaggerDocsDeleteList);
// }
// swaggerDocsDeleteSet.add(docUrl);
// storageService.put(StorageKeys.SWAGGER_DOCS_DELETE_LIST, JSON.toJSONString(swaggerDocsDeleteSet));
public ResponseJson<Object> deleteSwaggerDoc(String location) {
List<LocationListVo> locationList = this.getLocationSet();
String locationDel = this.encodeUrlParam(location);
locationList = locationList.stream().filter(val -> !Objects.equals(val.getLocation(), locationDel)).collect(Collectors.toList());
this.storageSwaggerLocationList(locationList);
return DocResponseJson.ok();
}
@@ -405,15 +405,16 @@ public class MgDocumentController {
List<LocationListVo> locationList = this.getLocationSet();
// 组装新的对象
LocationListVo locationListVo = new LocationListVo(locationUrl, "");
locationListVo.setRewriteDomainUrl(rewriteDomainUrl);
locationListVo.setOpenVisit(openVisit);
// 如果旧的不为空使用旧的uuid
for (LocationListVo location : locationList) {
if (Objects.equals(location.getLocation(), oldUrl) && StringUtils.isNotBlank(location.getUuid())) {
locationListVo.setUuid(location.getUuid());
locationListVo = location;
break;
}
}
locationListVo.setLocation(locationUrl);
locationListVo.setRewriteDomainUrl(rewriteDomainUrl);
locationListVo.setOpenVisit(openVisit);
// 去除旧的,加入新的
locationList = locationList.stream().filter(val -> !Objects.equals(val.getLocation(), oldUrl)).collect(Collectors.toList());
locationList.add(locationListVo);
@@ -431,14 +432,18 @@ public class MgDocumentController {
*/
private void addSwaggerLocationList(List<SwaggerResource> resourceList, String resourcesUrl, String rewriteDomainUrl, Integer openVisit) {
List<LocationListVo> locationList = this.getLocationSet();
Map<String, LocationListVo> locationListVoMap = locationList.stream().collect(Collectors.toMap(LocationListVo::getLocation, val -> val));
// 加入到location列表
String resourcesDomain = resourcesUrl.substring(0, resourcesUrl.lastIndexOf("/") + 1);
for (SwaggerResource swaggerResource : resourceList) {
String location = this.getLocationUrl(resourcesDomain, swaggerResource.getLocation(), swaggerResource.getName());
LocationListVo locationListVo = new LocationListVo(location, resourcesUrl);
LocationListVo locationListVo = locationListVoMap.get(location);
if (locationListVo == null) {
locationListVo = new LocationListVo(location, resourcesUrl);
locationList.add(locationListVo);
}
locationListVo.setRewriteDomainUrl(rewriteDomainUrl);
locationListVo.setOpenVisit(openVisit);
locationList.add(locationListVo);
}
this.storageSwaggerLocationList(locationList);
}
@@ -447,9 +452,13 @@ public class MgDocumentController {
* 保存location列表
*/
private void storageSwaggerLocationList(List<LocationListVo> locationSet) {
AtomicInteger idIndex = new AtomicInteger(1);
locationSet = locationSet.stream().distinct().collect(Collectors.toList());
locationSet.forEach(val -> val.setId(idIndex.getAndIncrement()));
locationSet.forEach(val -> {
if (val.getId() == null) {
val.setId(storageService.getNextId());
}
});
locationSet = locationSet.stream().sorted(Comparator.comparing(LocationListVo::getId)).collect(Collectors.toList());
storageService.put(StorageKeys.SWAGGER_LOCATION_LIST, JSON.toJSONString(locationSet));
}

View File

@@ -42,7 +42,7 @@ public class MgHttpRequestController {
}
paramUrl = paramUrl.replace("http://", "").replace("https://", "");
String regexStr = paramUrl.substring(0, paramUrl.indexOf("/"));
long inWhiteList = whiteDomain.stream().filter(val -> regexStr.matches(val)).count();
long inWhiteList = whiteDomain.stream().filter(regexStr::matches).count();
if (inWhiteList <= 0) {
return DocResponseJson.warn("该域名不在白名单内,不能代理请求");
}

View File

@@ -25,15 +25,12 @@ public class LocationListVo {
this.uuid = RandomUtil.simpleUUID();
// 修正名字
int indexGroup = location.indexOf("group=");
int indexV2 = location.indexOf("/v2");
if (indexGroup >= 0 && location.length() > indexGroup) {
try {
this.name = URLDecoder.decode(location.substring(indexGroup + 6), "utf-8");
} catch (Exception e) {
e.printStackTrace();
}
} else if (indexV2 >= 0) {
this.name = location.substring(indexV2 + 3);
}
}

View File

@@ -2,7 +2,7 @@ package com.zyplayer.doc.swagger.framework.constant;
/**
* 存储数据的KEY常量类
*
*
* @author 暮光:城中城
* @since 2018年8月21日
*/
@@ -15,4 +15,6 @@ public class StorageKeys {
public static final String SWAGGER_LOCATION_LIST = "swagger-location-list";
// 文档的离线数据key
public static final String SWAGGER_OFFLINE_DOC_START = "swagger-offline-doc-";
}
// 自增ID的key
public static final String SWAGGER_ID_WORKER = "swagger-id-worker";
}

View File

@@ -1,5 +1,8 @@
package com.zyplayer.doc.swagger.framework.service;
import com.zyplayer.doc.swagger.framework.constant.StorageKeys;
import org.apache.commons.lang.math.NumberUtils;
import java.util.List;
/**
@@ -52,4 +55,17 @@ public interface MgStorageService {
*/
List<String> getProxyRequestWhiteDomain();
/**
* 获取一个自增的ID
* @author 暮光:城中城
* @since 2019年1月27日
*/
default Integer getNextId() {
synchronized (StorageKeys.SWAGGER_ID_WORKER) {
String idWorker = this.get(StorageKeys.SWAGGER_ID_WORKER);
Integer nextId = NumberUtils.toInt(idWorker, 1);
this.put(StorageKeys.SWAGGER_ID_WORKER, String.valueOf(nextId + 1));
return nextId;
}
}
}

View File

@@ -39,8 +39,8 @@
<ul>
<li id="onlineDebugLi1" class="local-storage"><a href="javascript:void(0)" path=""><i class="icon-bug"></i> 在线调试管理</a></li>
<li><a href="#" class="page-nav" data-id="docShowConfig" data-href="webjars/zpages/docShowConfig.html" data-icon="icon-cog" data-reload="0"><i class="icon-cog"></i> 文档展示配置</a></li>
<li><a href="#" class="page-nav" data-id="docUrlConfig" data-href="webjars/zpages/docUrlConfig.html" data-icon="icon-list-ul" data-reload="1"><i class="icon-list-ul"></i> 文档地址管理</a></li>
<li><a href="#" class="page-nav" data-id="docUrlDetailConfig" data-href="webjars/zpages/docUrlDetailConfig.html" data-icon="icon-list-ul" data-reload="1"><i class="icon-list-ul"></i> 详细地址管理</a></li>
<li><a href="#" class="page-nav" data-id="docUrlConfig" data-href="webjars/zpages/docUrlConfig.html" data-icon="icon-list" data-reload="1"><i class="icon-list"></i> 文档地址管理</a></li>
<li><a href="#" class="page-nav" data-id="docUrlDetailConfig" data-href="webjars/zpages/docUrlDetailConfig.html" data-icon="icon-list-alt" data-reload="1"><i class="icon-list-alt"></i> 详细地址管理</a></li>
<li><a href="#" class="page-nav" data-id="globalParamConfig" data-href="webjars/zpages/globalParamConfig.html" data-icon="icon-globe" data-reload="1"><i class="icon-globe"></i> 全局参数管理</a></li>
<li><a href="#" class="page-nav" data-id="debugDataConfig" data-href="webjars/zpages/debugDataConfig.html" data-icon="icon-bug" data-reload="1"><i class="icon-bug"></i> 调试数据管理</a></li>
</ul>
@@ -389,7 +389,7 @@
<script type="text/javascript" src="webjars/zui/lib/tabs/zui.tabs.min.js"></script>
<script type="text/javascript" src="webjars/zui/lib/dashboard/zui.dashboard.min.js"></script>
<!--
<!--
<script type="text/javascript" src="webjars/mg-ui/js/mg-ui.min.js"></script>
-->
<script type="text/javascript" src="webjars/mg-ui/js/formatjson.js"></script>

View File

@@ -11,6 +11,7 @@ ul{list-style: none;list-style-type: none;}
.tree-menu li li li li li li li li li a{padding-left: 168px;}
.tree-menu li li li li li li li li li li a{padding-left: 188px;}
.table td, .table th {vertical-align: middle;}
.dropdown-menu>li>a{max-width: 100%;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;}
#tabDocInfo{position: absolute; bottom: 0;top: 60px;overflow-y: auto; right: 0; left: 10px;}
#tabOnlineDebug .param-response-box{position: absolute; bottom: 0;top: 100px;overflow-y: auto; right: 0; left: 10px;padding-right: 10px;}
#tabOnlineDebug .panel{margin-bottom: 10px;}
@@ -21,6 +22,7 @@ ul{list-style: none;list-style-type: none;}
.choice-location-list{margin-bottom: 10px; width: 100%;}
.choice-location-list .btn.dropdown-toggle{width: 100%; text-align: left;}
.choice-location-list .dropdown-menu{width: 100%;}
.choice-location-list .choice-text{max-width: calc(100% - 15px);overflow: hidden;float: left;white-space: nowrap;text-overflow: ellipsis;}
.choice-location-list .caret{float: right;margin-top: 8px;}
/**lable的覆盖样式*/

View File

@@ -96,6 +96,7 @@ function getDocumentListByService() {
var item = json.data[i];
$("#choiceLocationList .dropdown-menu").append('<li><a href="javascript:void(0);" data-location="' + item.location + '">' + item.name + '</a></li>');
}
$("#choiceLocationList .dropdown-menu").append('<li><a href="javascript:void(0);" data-location="">全部文档</a></li>');
$("#choiceLocationList .choice-text").text(json.data[0].name);
addDocumentByLocationService(json.data[0].location);
} else {
@@ -412,7 +413,7 @@ $("#apiPathTree").on("click", ".show-doc", function(){
$("#simulationResultUrlTest").text(data.domain + docUrl + "?zyplayerApiTest=1");
$("#simulationResultUrlTest").attr("href", data.domain + docUrl + "?zyplayerApiTest=1");
$("#simulationResultText").val("");
getStorage('p-simulation-response-' + docUrl, function(data){
getStorage(cacheKeys.pSimulationResponse + docUrl, function(data){
var resultText = getNotEmptyStr(data);
resultText = (typeof resultText == 'string') ? resultText : JSON.stringify(resultText, null, 4);
$("#simulationResultText").val(resultText);

View File

@@ -7,5 +7,5 @@ var cacheKeys = {
swaggerLocationList: 'swagger-location-list',
globalParamList: 'zyplayer-doc-global-param-list',
pRequestObjStart: 'p-request-obj-',
pSimulationResponse: 'p-simulation-response',
}
pSimulationResponse: 'p-simulation-response-',
}

View File

@@ -10,7 +10,7 @@
<body>
<div id="app">
<div class="alert alert-primary">
<div class="content">Tips开放文档地址 可以不需要登录即可访问</div>
<div class="content">Tips开放文档地址 可以不需要登录即可访问,重写域名地址 填写后需开启:文档展示配置->强制重写域名 后才生效</div>
</div>
<table class="table table-bordered setting-table">
<thead>
@@ -26,10 +26,14 @@
<tr v-for="(item,index) in swaggerLocationList" :key="item.id" :data-id="item.id" :data-index="index" >
<td>{{index+1}}</td>
<td>{{item.location}}</td>
<td><a :href="'../../open-doc.html?doc='+item.uuid" target="_blank">{{item.uuid}}</a></td>
<td>
<!--未开放时即使访问这个地址也看不了-->
<a v-if="item.openVisit == 1" :href="'../../open-doc.html?doc='+item.uuid" target="_blank">{{item.uuid}}</a>
<span v-else>暂未开放</span>
</td>
<td>{{item.rewriteDomainUrl}}</td>
<td>
<button class="btn btn-danger" type="button" v-on:click="deleteDocUrl($event)">删除</button>
<button class="btn btn-danger" type="button" @click="deleteDocUrl(item.location)">删除</button>
<button class="btn btn-info" type="button" v-on:click="editDocUrl($event)">编辑</button>
<!--<button class="btn btn-danger" type="button" v-on:click="syncDocData($event)">持久化</button>-->
</td>
@@ -146,20 +150,14 @@
}
});
},
deleteDocUrl: function (event) {
deleteDocUrl: function (location) {
if (!confirm("确定要删除吗?")) {
return;
}
var tr = $(event.currentTarget).parents("tr");
var index = tr.data("index");
var newDocList = [];
for (var i = 0; i < app.swaggerLocationList.length; i++) {
if (i !== index) {
newDocList.push(app.swaggerLocationList[i]);
ajaxTemp(urlBase + "swagger-mg-ui/document/deleteSwaggerDoc", "post", "json", {location: location}, function (json) {
if (validateResult(json)) {
app.refreshList();
}
}
setStorage(cacheKeys.swaggerLocationList, newDocList, function () {
app.swaggerLocationList = newDocList;
});
},
syncDocData: function (event) {