debug参数展示,基本功能开发

This commit is contained in:
暮光:城中城
2018-12-13 00:03:28 +08:00
parent a9c86940e2
commit 72d7f64cd6
12 changed files with 1170 additions and 1029 deletions

View File

@@ -1,52 +1,64 @@
package com.zyplayer.doc.manage.framework.config; package com.zyplayer.doc.manage.framework.config;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.springframework.context.annotation.Bean; import com.zyplayer.doc.manage.framework.interceptor.RequestInfoInterceptor;
import org.springframework.context.annotation.Configuration; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.FormatterRegistry; import org.springframework.context.annotation.Bean;
import org.springframework.format.datetime.DateFormatter; import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType; import org.springframework.format.FormatterRegistry;
import org.springframework.http.converter.HttpMessageConverter; import org.springframework.format.datetime.DateFormatter;
import org.springframework.stereotype.Component; import org.springframework.http.MediaType;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.stereotype.Component;
import com.alibaba.fastjson.serializer.SerializerFeature; import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import com.alibaba.fastjson.support.config.FastJsonConfig; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
import com.alibaba.fastjson.serializer.SerializerFeature;
@Component import com.alibaba.fastjson.support.config.FastJsonConfig;
@Configuration import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
public class WebMvcConfig implements WebMvcConfigurer {
@Component
@Override @Configuration
public void addFormatters(FormatterRegistry registry) { public class WebMvcConfig implements WebMvcConfigurer {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
format.setLenient(true); @Autowired
DateFormatter dateFormatter = new DateFormatter(); RequestInfoInterceptor requestInfoInterceptor;
dateFormatter.setPattern("yyyy-MM-dd HH:mm:ss");
dateFormatter.setLenient(true); @Override
registry.addFormatter(dateFormatter); public void addFormatters(FormatterRegistry registry) {
} SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
format.setLenient(true);
@Bean DateFormatter dateFormatter = new DateFormatter();
public FastJsonHttpMessageConverter fastJsonHttpMessageConverter() { dateFormatter.setPattern("yyyy-MM-dd HH:mm:ss");
FastJsonHttpMessageConverter fastJsonHttpMessageConverter = new FastJsonHttpMessageConverter(); dateFormatter.setLenient(true);
List<MediaType> supportedMediaTypes = new ArrayList<>(); registry.addFormatter(dateFormatter);
supportedMediaTypes.add(new MediaType("application", "json", Charset.forName("UTF-8"))); }
fastJsonHttpMessageConverter.setSupportedMediaTypes(supportedMediaTypes);
FastJsonConfig fastJsonConfig = new FastJsonConfig(); @Bean
fastJsonConfig.setSerializerFeatures(SerializerFeature.DisableCircularReferenceDetect, SerializerFeature.WriteDateUseDateFormat); public FastJsonHttpMessageConverter fastJsonHttpMessageConverter() {
fastJsonHttpMessageConverter.setFastJsonConfig(fastJsonConfig); FastJsonHttpMessageConverter fastJsonHttpMessageConverter = new FastJsonHttpMessageConverter();
return fastJsonHttpMessageConverter; List<MediaType> supportedMediaTypes = new ArrayList<>();
} supportedMediaTypes.add(new MediaType("application", "json", Charset.forName("UTF-8")));
fastJsonHttpMessageConverter.setSupportedMediaTypes(supportedMediaTypes);
@Override FastJsonConfig fastJsonConfig = new FastJsonConfig();
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) { fastJsonConfig.setSerializerFeatures(SerializerFeature.DisableCircularReferenceDetect, SerializerFeature.WriteDateUseDateFormat);
converters.add(0, fastJsonHttpMessageConverter()); fastJsonHttpMessageConverter.setFastJsonConfig(fastJsonConfig);
} return fastJsonHttpMessageConverter;
}
}
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
converters.add(0, fastJsonHttpMessageConverter());
}
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(requestInfoInterceptor).excludePathPatterns("/**/*.js", "/**/*.css", "/**/*.png",
"/**/*.gif", "/**/*.jpg", "/**/*.jpeg", "/**/fonts/*");
}
}

View File

@@ -1,33 +1,107 @@
/* /*
Navicat Premium Data Transfer Navicat Premium Data Transfer
Source Server : 127.0.0.1 Source Server : 127.0.0.1
Source Server Type : MySQL Source Server Type : MySQL
Source Server Version : 50624 Source Server Version : 50624
Source Host : 127.0.0.1:3306 Source Host : 127.0.0.1:3306
Source Schema : zyplayer-doc-manage Source Schema : zyplayer-doc-manage
Target Server Type : MySQL Target Server Type : MySQL
Target Server Version : 50624 Target Server Version : 50624
File Encoding : 65001 File Encoding : 65001
Date: 27/11/2018 20:19:45 Date: 12/12/2018 14:29:09
*/ */
SET NAMES utf8mb4; SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0; SET FOREIGN_KEY_CHECKS = 0;
-- ---------------------------- -- ----------------------------
-- Table structure for zyplayer_storage -- Table structure for auth_info
-- ---------------------------- -- ----------------------------
DROP TABLE IF EXISTS `zyplayer_storage`; DROP TABLE IF EXISTS `auth_info`;
CREATE TABLE `zyplayer_storage` ( CREATE TABLE `auth_info` (
`id` int(11) NOT NULL AUTO_INCREMENT, `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键自增ID',
`doc_key` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `auth_name` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '权限名',
`doc_value` varchar(2048) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `auth_desc` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '权限说明',
`creation_time` datetime NULL DEFAULT NULL, `can_edit` tinyint(4) NULL DEFAULT 1 COMMENT '是否可编辑 0=否 1=是',
PRIMARY KEY (`id`) USING BTREE, `create_uid` bigint(20) NULL DEFAULT NULL COMMENT '创建人',
UNIQUE INDEX `key`(`doc_key`) USING BTREE COMMENT 'key唯一索引' `creation_time` datetime(0) NULL DEFAULT NULL COMMENT '创建时间',
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact; PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 5 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
SET FOREIGN_KEY_CHECKS = 1;
-- ----------------------------
-- Records of auth_info
-- ----------------------------
INSERT INTO `auth_info` VALUES (1, 'DOC_ALL', '文档查看权', 0, 1, '2018-12-01 11:40:42');
INSERT INTO `auth_info` VALUES (2, 'AUTH_MANAGE', '权限管理权', 0, 1, '2018-12-01 11:40:42');
INSERT INTO `auth_info` VALUES (3, 'AUTH_ASSIGN', '权限分配权', 0, 1, '2018-12-01 11:40:42');
INSERT INTO `auth_info` VALUES (4, 'USER_MANAGE', '用户管理权', 0, 1, '2018-12-01 11:40:42');
-- ----------------------------
-- Table structure for user_auth
-- ----------------------------
DROP TABLE IF EXISTS `user_auth`;
CREATE TABLE `user_auth` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键自增ID',
`user_id` bigint(20) NULL DEFAULT NULL COMMENT '用户ID',
`auth_id` bigint(20) NULL DEFAULT NULL COMMENT '权限ID',
`create_uid` bigint(20) NULL DEFAULT NULL COMMENT '创建用户ID',
`update_uid` bigint(20) NULL DEFAULT NULL COMMENT '更新用户ID',
`del_flag` tinyint(4) NULL DEFAULT 0 COMMENT '是否删除 0=未删除 1=已删除',
`creation_time` datetime(0) NULL DEFAULT NULL COMMENT '创建时间',
`update_time` datetime(0) NULL DEFAULT NULL COMMENT '更新时间',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 5 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
-- ----------------------------
-- Records of user_auth
-- ----------------------------
INSERT INTO `user_auth` VALUES (1, 1, 1, 1, 1, 0, '2018-12-01 11:41:13', '2018-12-01 11:41:13');
INSERT INTO `user_auth` VALUES (2, 1, 2, 1, 1, 0, '2018-12-01 11:41:13', '2018-12-01 11:41:13');
INSERT INTO `user_auth` VALUES (3, 1, 3, 1, 1, 0, '2018-12-01 11:41:13', '2018-12-01 11:41:13');
INSERT INTO `user_auth` VALUES (4, 1, 4, 1, 1, 0, '2018-12-01 11:41:13', '2018-12-01 11:41:13');
-- ----------------------------
-- Table structure for user_info
-- ----------------------------
DROP TABLE IF EXISTS `user_info`;
CREATE TABLE `user_info` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键自增ID',
`user_no` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '用户编号,用于登录等',
`password` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '密码',
`user_name` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '用户名',
`email` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '邮箱',
`avatar` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '头像',
`del_flag` tinyint(4) NULL DEFAULT 0 COMMENT '是否删除 0=未删除 1=已删除',
`create_uid` bigint(20) NULL DEFAULT NULL COMMENT '创建人',
`creation_time` datetime(0) NULL DEFAULT NULL COMMENT '创建时间',
`update_time` datetime(0) NULL DEFAULT NULL COMMENT '修改时间',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 2 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
-- ----------------------------
-- Records of user_info
-- ----------------------------
INSERT INTO `user_info` VALUES (1, 'zyplayer', 'e10adc3949ba59abbe56e057f20f883e', '暮光:城中城', '806783409@qq.com', NULL, 0, NULL, '2018-12-01 11:37:39', NULL);
-- ----------------------------
-- Table structure for zyplayer_storage
-- ----------------------------
DROP TABLE IF EXISTS `zyplayer_storage`;
CREATE TABLE `zyplayer_storage` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`doc_key` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`doc_value` text CHARACTER SET utf8 COLLATE utf8_general_ci NULL,
`creation_time` datetime(0) NULL DEFAULT NULL,
`update_time` datetime(0) NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE,
UNIQUE INDEX `key`(`doc_key`) USING BTREE COMMENT 'key唯一索引'
) ENGINE = InnoDB AUTO_INCREMENT = 16 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
-- ----------------------------
-- Records of zyplayer_storage
-- ----------------------------
SET FOREIGN_KEY_CHECKS = 1;

View File

@@ -1,286 +1,330 @@
package com.zyplayer.doc.swagger.controller; package com.zyplayer.doc.swagger.controller;
import java.net.URLEncoder; import cn.hutool.http.HttpRequest;
import java.util.Arrays; import com.alibaba.fastjson.JSON;
import java.util.HashMap; import com.alibaba.fastjson.TypeReference;
import java.util.HashSet; import com.zyplayer.doc.core.json.DocResponseJson;
import java.util.LinkedList; import com.zyplayer.doc.core.json.ResponseJson;
import java.util.List; import com.zyplayer.doc.swagger.controller.vo.SwaggerResourcesInfoVo;
import java.util.Map; import com.zyplayer.doc.swagger.framework.configuration.EnableSwaggerMgUi;
import java.util.Set; import com.zyplayer.doc.swagger.framework.configuration.SpringContextUtil;
import com.zyplayer.doc.swagger.framework.constant.StorageKeys;
import javax.servlet.http.HttpServletRequest; import com.zyplayer.doc.swagger.framework.service.MgStorageService;
import javax.servlet.http.HttpServletResponse; import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.apache.commons.lang.StringUtils; import org.slf4j.LoggerFactory;
import org.slf4j.Logger; import org.springframework.aop.support.AopUtils;
import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.aop.support.AopUtils; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.ResponseBody; import springfox.documentation.swagger.web.SwaggerResource;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import com.alibaba.fastjson.JSON; import javax.servlet.http.HttpServletResponse;
import com.alibaba.fastjson.TypeReference; import java.net.URLEncoder;
import com.zyplayer.doc.core.json.DocResponseJson; import java.util.*;
import com.zyplayer.doc.core.json.ResponseJson;
import com.zyplayer.doc.swagger.framework.configuration.EnableSwaggerMgUi; /**
import com.zyplayer.doc.swagger.framework.configuration.SpringContextUtil; * 文档控制器
import com.zyplayer.doc.swagger.framework.constant.StorageKeys; *
import com.zyplayer.doc.swagger.framework.service.MgStorageService; * @author 暮光:城中城
* @since 2018年8月21日
import cn.hutool.http.HttpRequest; */
import springfox.documentation.swagger.web.SwaggerResource; @RestController
@RequestMapping("/swagger-mg-ui/document")
/** public class MgDocumentController {
* 文档控制器
* private static Logger logger = LoggerFactory.getLogger(MgDocumentController.class);
* @author 暮光:城中城
* @since 2018年8月21日 @Autowired
*/ private MgStorageService storageService;
@RestController
@RequestMapping("/swagger-mg-ui/document") /**
public class MgDocumentController { * 获取所有的文档地址
*
private static Logger logger = LoggerFactory.getLogger(MgDocumentController.class); * @author 暮光:城中城
* @since 2018年8月21日
@Autowired * @return 文档内容
private MgStorageService storageService; */
@ResponseBody
/** @PostMapping(value = "/resourcesList")
* 获取所有的文档地址 public ResponseJson<Set<SwaggerResourcesInfoVo>> resourcesList() {
* String swaggerResourcesStr = storageService.get(StorageKeys.SWAGGER_RESOURCES_LIST);
* @author 暮光:城中城 Set<SwaggerResourcesInfoVo> resourcesSet = new HashSet<>();
* @since 2018年8月21日 if (StringUtils.isNotBlank(swaggerResourcesStr)) {
* @return 文档内容 List<SwaggerResourcesInfoVo> resourcesList = JSON.parseArray(swaggerResourcesStr, SwaggerResourcesInfoVo.class);
*/ resourcesSet.addAll(resourcesList);
@ResponseBody }
@PostMapping(value = "/resourcesList") return DocResponseJson.ok(resourcesSet);
public ResponseJson<Set<String>> resourcesList() { }
String swaggerResourcesStr = storageService.get(StorageKeys.SWAGGER_RESOURCES_LIST);
Set<String> resourcesSet = new HashSet<>(); /**
if (StringUtils.isNotBlank(swaggerResourcesStr)) { * 获取所有的文档
List<String> resourcesList = JSON.parseArray(swaggerResourcesStr, String.class); * @author 暮光:城中城
resourcesSet.addAll(resourcesList); * @since 2018年8月21日
} * @param request request
return DocResponseJson.ok(resourcesSet); * @param response response
} */
@ResponseBody
/** @PostMapping(value = "/docs")
* 获取所有的文档 public void docs(HttpServletRequest request, HttpServletResponse response) {
* @author 暮光:城中城 boolean needRestorage = true;
* @since 2018年8月21日 String choiseDocList = request.getParameter("choiseDocList");
* @param request request // 转成set防止重复
* @param response response Set<SwaggerResourcesInfoVo> resourcesSet = new HashSet<>();
*/ Set<String> swaggerDocsDeleteSet = new HashSet<>();
@ResponseBody if (StringUtils.isNotBlank(choiseDocList)) {
@PostMapping(value = "/docs") needRestorage = false;// 选择的则不再存入
public void docs(HttpServletRequest request, HttpServletResponse response) { for (String url : choiseDocList.split(",")) {
boolean needRestorage = true; resourcesSet.add(new SwaggerResourcesInfoVo(url));
String choiseDocList = request.getParameter("choiseDocList"); }
// 转成set防止重复 } else {
Set<String> resourcesSet = new HashSet<>(); String swaggerResourcesStr = storageService.get(StorageKeys.SWAGGER_RESOURCES_LIST);
Set<String> swaggerDocsDeleteSet = new HashSet<>(); String swaggerDocsDeleteStr = storageService.get(StorageKeys.SWAGGER_DOCS_DELETE_LIST);
if (StringUtils.isNotBlank(choiseDocList)) { if (StringUtils.isNotBlank(swaggerResourcesStr)) {
needRestorage = false;// 选择的则不再存入 List<SwaggerResourcesInfoVo> resourcesList = JSON.parseArray(swaggerResourcesStr, SwaggerResourcesInfoVo.class);
resourcesSet.addAll(Arrays.asList(choiseDocList.split(","))); resourcesSet.addAll(resourcesList);
} else { } else {
String swaggerResourcesStr = storageService.get(StorageKeys.SWAGGER_RESOURCES_LIST); // 默认加上自身的文档
String swaggerDocsDeleteStr = storageService.get(StorageKeys.SWAGGER_DOCS_DELETE_LIST); String serverPath = "http://" + request.getServerName() // 服务器地址
if (StringUtils.isNotBlank(swaggerResourcesStr)) { + ":" + request.getServerPort() // 端口号
List<String> resourcesList = JSON.parseArray(swaggerResourcesStr, String.class); + request.getContextPath();
resourcesSet.addAll(resourcesList); // 是否加入自身的文档
} else { Object object = SpringContextUtil.getBeanWithAnnotation(EnableSwaggerMgUi.class);
// 默认加上自身的文档 EnableSwaggerMgUi swaggerMgUi = object.getClass().getAnnotation(EnableSwaggerMgUi.class);
String serverPath = "http://" + request.getServerName() // 服务器地址 if (swaggerMgUi == null) {
+ ":" + request.getServerPort() // 端口号 // 直接通过superclass去找
+ request.getContextPath(); Class<?> superclass = object.getClass().getSuperclass();
// 是否加入自身的文档 if (superclass != null) {
Object object = SpringContextUtil.getBeanWithAnnotation(EnableSwaggerMgUi.class); swaggerMgUi = superclass.getAnnotation(EnableSwaggerMgUi.class);
EnableSwaggerMgUi swaggerMgUi = object.getClass().getAnnotation(EnableSwaggerMgUi.class); }
if (swaggerMgUi == null) { }
// 直接通过superclass去找 if (swaggerMgUi == null) {
Class<?> superclass = object.getClass().getSuperclass(); // 再通过AopUtils去找
if (superclass != null) { Class<?> targetClass = AopUtils.getTargetClass(object);
swaggerMgUi = superclass.getAnnotation(EnableSwaggerMgUi.class); if (targetClass != null) {
} swaggerMgUi = targetClass.getAnnotation(EnableSwaggerMgUi.class);
} }
if (swaggerMgUi == null) { }
// 再通过AopUtils去找 if (swaggerMgUi == null) {
Class<?> targetClass = AopUtils.getTargetClass(object); resourcesSet.add(new SwaggerResourcesInfoVo(serverPath + "/swagger-resources"));
if (targetClass != null) { } else {
swaggerMgUi = targetClass.getAnnotation(EnableSwaggerMgUi.class); if (swaggerMgUi.selfDoc()) {
} resourcesSet.add(new SwaggerResourcesInfoVo(serverPath + "/swagger-resources"));
} }
if (swaggerMgUi == null) { // 启动后第一次访问没有数据情况下需要加载进来的swagger-resources地址
resourcesSet.add(serverPath + "/swagger-resources"); String[] defaultResources = swaggerMgUi.defaultResources();
} else { if (defaultResources != null && defaultResources.length > 0) {
if (swaggerMgUi.selfDoc()) { for (String url : defaultResources) {
resourcesSet.add(serverPath + "/swagger-resources"); resourcesSet.add(new SwaggerResourcesInfoVo(url));
} }
// 启动后第一次访问没有数据情况下需要加载进来的swagger-resources地址 }
String[] defaultResources = swaggerMgUi.defaultResources(); }
if (defaultResources != null && defaultResources.length > 0) { }
resourcesSet.addAll(Arrays.asList(defaultResources)); if (StringUtils.isNotBlank(swaggerDocsDeleteStr)) {
} List<String> swaggerDocsDeleteList = JSON.parseArray(swaggerDocsDeleteStr, String.class);
} swaggerDocsDeleteSet.addAll(swaggerDocsDeleteList);
} }
if (StringUtils.isNotBlank(swaggerDocsDeleteStr)) { }
List<String> swaggerDocsDeleteList = JSON.parseArray(swaggerDocsDeleteStr, String.class); List<Map<String, Object>> swaggerResourceList = new LinkedList<>();
swaggerDocsDeleteSet.addAll(swaggerDocsDeleteList); List<String> swaggerResourceStrList = new LinkedList<>();
} for (SwaggerResourcesInfoVo resourcesInfoVo : resourcesSet) {
} List<SwaggerResource> resourceList = null;
List<Map<String, Object>> swaggerResourceList = new LinkedList<>(); String resourcesUrl = resourcesInfoVo.getUrl();
List<String> swaggerResourceStrList = new LinkedList<>(); try {
for (String resourcesUrl : resourcesSet) { String resourcesStr = HttpRequest.get(resourcesUrl).timeout(3000).execute().body();
List<SwaggerResource> resourceList = null; resourceList = JSON.parseArray(resourcesStr, SwaggerResource.class);
try { } catch (Exception e) {
String resourcesStr = HttpRequest.get(resourcesUrl).timeout(3000).execute().body(); logger.error("获取文档失败:{}{}", resourcesUrl, e.getMessage());
resourceList = JSON.parseArray(resourcesStr, SwaggerResource.class); }
} catch (Exception e) { if (resourceList == null || resourceList.isEmpty()) {
logger.error("获取文档失败:{}{}", resourcesUrl, e.getMessage()); continue;
} }
if (resourceList == null || resourceList.isEmpty()) { resourcesUrl = resourcesUrl.substring(0, resourcesUrl.lastIndexOf("/") + 1);
continue; for (SwaggerResource resource : resourceList) {
} String location = resource.getLocation();
resourcesUrl = resourcesUrl.substring(0, resourcesUrl.lastIndexOf("/") + 1); // 最后一个斜杠在resourcesUrl中已经加上替换掉后面的防止两根斜杠
for (SwaggerResource resource : resourceList) { location = location.startsWith("/") ? location.replaceFirst("/", "") : location;
String location = resource.getLocation(); if (location.indexOf("?") >= 0) {
// 最后一个斜杠在resourcesUrl中已经加上替换掉后面的防止两根斜杠 try {
location = location.startsWith("/") ? location.replaceFirst("/", "") : location; String encode = URLEncoder.encode(resource.getName(), "utf-8");
if (location.indexOf("?") >= 0) { location = location.substring(0, location.lastIndexOf("?")) + "?group=" + encode;
try { } catch (Exception e) {
String encode = URLEncoder.encode(resource.getName(), "utf-8"); e.printStackTrace();
location = location.substring(0, location.lastIndexOf("?")) + "?group=" + encode; }
} catch (Exception e) { }
e.printStackTrace(); location = resourcesUrl + location;
} // 已删除的则不处理
} if (swaggerDocsDeleteSet.contains(location)) {
location = resourcesUrl + location; continue;
// 已删除的则不处理 }
if (swaggerDocsDeleteSet.contains(location)) { try {
continue; String resourceStr = HttpRequest.get(location).timeout(3000).execute().body();
} Map<String, Object> jsonObject = JSON.parseObject(resourceStr, new TypeReference<HashMap<String, Object>>(){});
try { if (jsonObject == null || jsonObject.isEmpty()) {
String resourceStr = HttpRequest.get(location).timeout(3000).execute().body(); continue;
Map<String, Object> jsonObject = JSON.parseObject(resourceStr, new TypeReference<HashMap<String, Object>>(){}); }
if (jsonObject == null || jsonObject.isEmpty()) { jsonObject.put("fullUrl", location);
continue; swaggerResourceList.add(jsonObject);
} // 本来想转对象之后赋值但是在此转成JSON字符串之后格式就不是之前的了所有不能转。。。
jsonObject.put("fullUrl", location); // 直接字符串拼接,坑真多~
swaggerResourceList.add(jsonObject); resourceStr = resourceStr.substring(1);
// 本来想转对象之后赋值但是在此转成JSON字符串之后格式就不是之前的了所有不能转。。。 resourceStr = "{\"fullUrl\":\"" + location + "\","
// 直接字符串拼接,坑真多~ + "\"domainUrl\":\"" + resourcesUrl + "\","
resourceStr = resourceStr.substring(1); + resourceStr;
resourceStr = "{\"fullUrl\":\"" + location + "\"," swaggerResourceStrList.add(resourceStr);
+ "\"domainUrl\":\"" + resourcesUrl + "\"," } catch (Exception e) {
+ resourceStr; logger.error("获取文档失败:{}{}", location, e.getMessage());
swaggerResourceStrList.add(resourceStr); }
} catch (Exception e) { }
logger.error("获取文档失败:{}{}", location, e.getMessage()); }
} if (needRestorage) {
} storageService.put(StorageKeys.SWAGGER_RESOURCES_LIST, JSON.toJSONString(resourcesSet));
} }
if (needRestorage) { // 用默认的json解析要内存溢出解析不了JSONObject、、就只有这样写了~
storageService.put(StorageKeys.SWAGGER_RESOURCES_LIST, JSON.toJSONString(resourcesSet)); DocResponseJson.ok(swaggerResourceStrList).send(response);
} }
// 用默认的json解析要内存溢出解析不了JSONObject、、就只有这样写了~
DocResponseJson.ok(swaggerResourceStrList).send(response); /**
} * 增加/swagger-resources地址
*
/** * @author 暮光:城中城
* 增加/swagger-resources地址 * @since 2018年8月21日
* * @param resourcesUrl swagger-resources地址
* @author 暮光:城中城 * @return 添加结果
* @since 2018年8月21日 */
* @param resourcesUrl swagger-resources地址 @PostMapping(value = "/addSwaggerResources")
* @return 添加结果 public ResponseJson<Object> addSwaggerResources(String resourcesUrl) {
*/ String swaggerResourcesStr = storageService.get(StorageKeys.SWAGGER_RESOURCES_LIST);
@PostMapping(value = "/addSwaggerResources") String swaggerDocsDeleteStr = storageService.get(StorageKeys.SWAGGER_DOCS_DELETE_LIST);
public ResponseJson<Object> addSwaggerResources(String resourcesUrl) { Set<String> swaggerDocsDeleteSet = new HashSet<>();
String swaggerResourcesStr = storageService.get(StorageKeys.SWAGGER_RESOURCES_LIST); if (StringUtils.isNotBlank(swaggerDocsDeleteStr)) {
String swaggerDocsDeleteStr = storageService.get(StorageKeys.SWAGGER_DOCS_DELETE_LIST); List<String> swaggerDocsDeleteList = JSON.parseArray(swaggerDocsDeleteStr, String.class);
Set<String> swaggerDocsDeleteSet = new HashSet<>(); swaggerDocsDeleteSet.addAll(swaggerDocsDeleteList);
if (StringUtils.isNotBlank(swaggerDocsDeleteStr)) { }
List<String> swaggerDocsDeleteList = JSON.parseArray(swaggerDocsDeleteStr, String.class); // 转成set防止重复
swaggerDocsDeleteSet.addAll(swaggerDocsDeleteList); Set<SwaggerResourcesInfoVo> resourcesSet = new HashSet<>();
} if (StringUtils.isNotBlank(swaggerResourcesStr)) {
// 转成set防止重复 List<SwaggerResourcesInfoVo> resourcesList = JSON.parseArray(swaggerResourcesStr, SwaggerResourcesInfoVo.class);
Set<String> resourcesSet = new HashSet<>(); resourcesSet.addAll(resourcesList);
if (StringUtils.isNotBlank(swaggerResourcesStr)) { }
List<String> resourcesList = JSON.parseArray(swaggerResourcesStr, String.class); try {
resourcesSet.addAll(resourcesList); String resourcesStr = HttpRequest.get(resourcesUrl).timeout(3000).execute().body();
} List<SwaggerResource> resourceList = JSON.parseArray(resourcesStr, SwaggerResource.class);
String resourcesStr = null; if (resourceList == null || resourceList.isEmpty()) {
try { return DocResponseJson.warn("该地址未找到文档");
// resourcesStr = HttpRequest.get(resourcesUrl).timeout(3000).execute().body(); }
// List<SwaggerResource> resourceList = JSON.parseArray(resourcesStr, SwaggerResource.class); // 重新加入的时候把之前的已删除的回恢复
// if (resourceList == null || resourceList.isEmpty()) { String resourcesDomain = resourcesUrl.substring(0, resourcesUrl.lastIndexOf("/") + 1);
// return DocResponseJson.warn("该地址未找到文档"); for (SwaggerResource swaggerResource : resourceList) {
// } String location = swaggerResource.getLocation();
// // 重新加入的时候把之前的已删除的回恢复 // 最后一个斜杠在resourcesUrl中已经加上替换掉后面的防止两根斜杠
// String resourcesDomain = resourcesUrl.substring(0, resourcesUrl.lastIndexOf("/") + 1); location = location.startsWith("/") ? location.replaceFirst("/", "") : location;
// for (SwaggerResource swaggerResource : resourceList) { if (location.indexOf("?") >= 0) {
// String location = swaggerResource.getLocation(); try {
// // 最后一个斜杠在resourcesUrl中已经加上替换掉后面的防止两根斜杠 String encode = URLEncoder.encode(swaggerResource.getName(), "utf-8");
// location = location.startsWith("/") ? location.replaceFirst("/", "") : location; location = location.substring(0, location.lastIndexOf("?")) + "?group=" + encode;
// if (location.indexOf("?") >= 0) { } catch (Exception e) {
// try { e.printStackTrace();
// String encode = URLEncoder.encode(swaggerResource.getName(), "utf-8"); }
// location = location.substring(0, location.lastIndexOf("?")) + "?group=" + encode; }
// } catch (Exception e) { location = resourcesDomain + location;
// e.printStackTrace(); swaggerDocsDeleteSet.remove(location);
// } }
// } resourcesSet.add(new SwaggerResourcesInfoVo(resourcesUrl));
// location = resourcesDomain + location; } catch (Exception e) {
// swaggerDocsDeleteSet.remove(location); // 暂不想支持直接添加地址
// } // try {
resourcesSet.add(resourcesUrl); // SwaggerLocationVo swaggerLocationVo = JSON.parseObject(resourcesStr, SwaggerLocationVo.class);
} catch (Exception e) { // if (StringUtils.isNotBlank(swaggerLocationVo.getSwagger())) {
// 暂不想支持直接添加地址 // Set<String> locationSet = new HashSet<>();
// try { // if (StringUtils.isNotBlank(swaggerLocationListStr)) {
// SwaggerLocationVo swaggerLocationVo = JSON.parseObject(resourcesStr, SwaggerLocationVo.class); // String swaggerLocationListStr = storageService.get(StorageKeys.SWAGGER_LOCATION_LIST);
// if (StringUtils.isNotBlank(swaggerLocationVo.getSwagger())) { // List<String> locationList = JSON.parseArray(swaggerLocationListStr, String.class);
// Set<String> locationSet = new HashSet<>(); // locationSet.addAll(locationList);
// if (StringUtils.isNotBlank(swaggerLocationListStr)) { // storageService.put(StorageKeys.SWAGGER_LOCATION_LIST, JSON.toJSONString(locationSet));
// String swaggerLocationListStr = storageService.get(StorageKeys.SWAGGER_LOCATION_LIST); // }
// List<String> locationList = JSON.parseArray(swaggerLocationListStr, String.class); // } else {
// locationSet.addAll(locationList); // return DocResponseJson.warn("该地址查找文档失败");
// storageService.put(StorageKeys.SWAGGER_LOCATION_LIST, JSON.toJSONString(locationSet)); // }
// } // } catch (Exception e2) {
// } else { logger.error("获取文档失败:{}{}", resourcesUrl, e.getMessage());
// return DocResponseJson.warn("该地址查找文档失败"); return DocResponseJson.warn("该地址查找文档失败");
// } // }
// } catch (Exception e2) { }
logger.error("获取文档失败:{}{}", resourcesUrl, e.getMessage()); storageService.put(StorageKeys.SWAGGER_RESOURCES_LIST, JSON.toJSONString(resourcesSet));
return DocResponseJson.warn("该地址查找文档失败"); storageService.put(StorageKeys.SWAGGER_DOCS_DELETE_LIST, JSON.toJSONString(swaggerDocsDeleteSet));
// } return DocResponseJson.ok();
} }
storageService.put(StorageKeys.SWAGGER_RESOURCES_LIST, JSON.toJSONString(resourcesSet));
storageService.put(StorageKeys.SWAGGER_DOCS_DELETE_LIST, JSON.toJSONString(swaggerDocsDeleteSet)); /**
return DocResponseJson.ok(); * 增加/swagger-resources地址
} *
* @author 暮光:城中城
/** * @since 2018年8月21日
* 删除/v2/api-docs * @param resourcesUrl swagger-resources地址
* * @return 添加结果
* @author 暮光:城中城 */
* @since 2018年8月21日 @PostMapping(value = "/syncDocData")
* @param docUrl 文档地址 public ResponseJson<Object> syncDocData(String resourcesUrl) {
* @return 删除结果 String swaggerResourcesStr = storageService.get(StorageKeys.SWAGGER_RESOURCES_LIST);
*/ // 转成set防止重复
@PostMapping(value = "/deleteSwaggerDoc") Set<SwaggerResourcesInfoVo> resourcesSet = new HashSet<>();
public ResponseJson<Object> deleteSwaggerDoc(String docUrl) { if (StringUtils.isNotBlank(swaggerResourcesStr)) {
String swaggerDocsDeleteStr = storageService.get(StorageKeys.SWAGGER_DOCS_DELETE_LIST); List<SwaggerResourcesInfoVo> resourcesList = JSON.parseArray(swaggerResourcesStr, SwaggerResourcesInfoVo.class);
Set<String> swaggerDocsDeleteSet = new HashSet<>(); resourcesSet.addAll(resourcesList);
if (StringUtils.isNotBlank(swaggerDocsDeleteStr)) { }
List<String> swaggerDocsDeleteList = JSON.parseArray(swaggerDocsDeleteStr, String.class); try {
swaggerDocsDeleteSet.addAll(swaggerDocsDeleteList); String resourcesStr = HttpRequest.get(resourcesUrl).timeout(3000).execute().body();
} List<SwaggerResource> resourceList = JSON.parseArray(resourcesStr, SwaggerResource.class);
swaggerDocsDeleteSet.add(docUrl); if (resourceList == null || resourceList.isEmpty()) {
storageService.put(StorageKeys.SWAGGER_DOCS_DELETE_LIST, JSON.toJSONString(swaggerDocsDeleteSet)); return DocResponseJson.warn("该地址未找到文档");
return DocResponseJson.ok(); }
} // 重新加入的时候把之前的已删除的回恢复
} String resourcesDomain = resourcesUrl.substring(0, resourcesUrl.lastIndexOf("/") + 1);
for (SwaggerResource swaggerResource : resourceList) {
String location = swaggerResource.getLocation();
// 最后一个斜杠在resourcesUrl中已经加上替换掉后面的防止两根斜杠
location = location.startsWith("/") ? location.replaceFirst("/", "") : location;
if (location.indexOf("?") >= 0) {
try {
String encode = URLEncoder.encode(swaggerResource.getName(), "utf-8");
location = location.substring(0, location.lastIndexOf("?")) + "?group=" + encode;
} catch (Exception e) {
e.printStackTrace();
}
}
location = resourcesDomain + location;
}
resourcesSet.add(new SwaggerResourcesInfoVo(resourcesUrl));
} catch (Exception e) {
logger.error("获取文档失败:{}{}", resourcesUrl, e.getMessage());
return DocResponseJson.warn("该地址查找文档失败");
}
storageService.put(StorageKeys.SWAGGER_RESOURCES_LIST, JSON.toJSONString(resourcesSet));
return DocResponseJson.ok();
}
/**
* 删除/v2/api-docs
*
* @author 暮光:城中城
* @since 2018年8月21日
* @param docUrl 文档地址
* @return 删除结果
*/
@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));
return DocResponseJson.ok();
}
}

View File

@@ -1,16 +1,18 @@
package com.zyplayer.doc.swagger.framework.constant; package com.zyplayer.doc.swagger.framework.constant;
/** /**
* 存储数据的KEY常量类 * 存储数据的KEY常量类
* *
* @author 暮光:城中城 * @author 暮光:城中城
* @since 2018年8月21日 * @since 2018年8月21日
*/ */
public class StorageKeys { public class StorageKeys {
// 所有文档地址 // 所有文档地址
public static final String SWAGGER_RESOURCES_LIST = "swagger-resources-list"; public static final String SWAGGER_RESOURCES_LIST = "swagger-resources-list";
// 已删除的文档 // 已删除的文档
public static final String SWAGGER_DOCS_DELETE_LIST = "swagger-docs-delete-list"; public static final String SWAGGER_DOCS_DELETE_LIST = "swagger-docs-delete-list";
// 所有详细文档地址 // 所有详细文档地址
public static final String SWAGGER_LOCATION_LIST = "swagger-location-list"; public static final String SWAGGER_LOCATION_LIST = "swagger-location-list";
// 文档的离线数据key
public static final String SWAGGER_OFFLINE_DOC_START = "swagger-offline-doc-";
} }

View File

@@ -383,6 +383,7 @@
<script type="text/javascript" src="webjars/mg-ui/js/mg-ui-tag.js"></script> <script type="text/javascript" src="webjars/mg-ui/js/mg-ui-tag.js"></script>
<script type="text/javascript" src="webjars/mg-ui/js/mg-ui-debug.js"></script> <script type="text/javascript" src="webjars/mg-ui/js/mg-ui-debug.js"></script>
<script type="text/javascript" src="webjars/mg-ui/js/mg-ui-export.js"></script> <script type="text/javascript" src="webjars/mg-ui/js/mg-ui-export.js"></script>
<script type="text/javascript" src="webjars/mg-ui/js/mg-ui-cache-keys.js"></script>
<script type="text/javascript" src="webjars/mg-ui/js/mg-ui.js"></script> <script type="text/javascript" src="webjars/mg-ui/js/mg-ui.js"></script>
</html> </html>

View File

@@ -3,4 +3,5 @@ var cacheKeys = {
swaggerResourcesList: 'swagger-resources-list', swaggerResourcesList: 'swagger-resources-list',
globalParamList: 'zyplayer-doc-global-param-list', globalParamList: 'zyplayer-doc-global-param-list',
pRequestObjStart: 'p-request-obj-', pRequestObjStart: 'p-request-obj-',
pSimulationResponse: 'p-simulation-response',
} }

View File

@@ -10,5 +10,9 @@ var exports = {
exportDocument: function(){ exportDocument: function(){
// 定义在mg-ui.js用于打开导出文档框 // 定义在mg-ui.js用于打开导出文档框
exportDocument(); exportDocument();
},
updateGlobalParam: function(param){
// 更新调试的全局参数变量
debugGlobalParam = param;
} }
}; };

View File

@@ -19,6 +19,8 @@ var projectTreeIdIndex = 1;
var projectLoadingIndex = 0; var projectLoadingIndex = 0;
// 请求到的文档列表 // 请求到的文档列表
var documentJsonArr = []; var documentJsonArr = [];
// 调试的全局参数变量
var debugGlobalParam = [];
// 用户的配置对象 // 用户的配置对象
var userSettings = {}; var userSettings = {};
// 默认用户的配置对象 // 默认用户的配置对象
@@ -86,7 +88,7 @@ function getDocumentListByService() {
showGlobalLoadingMessage('等待选择需展示的文档,请选择...', true); showGlobalLoadingMessage('等待选择需展示的文档,请选择...', true);
for (var i = 0; i < json.data.length; i++) { for (var i = 0; i < json.data.length; i++) {
var item = json.data[i]; var item = json.data[i];
$("#choiseDocListUl").append('<li value="'+item+'">'+item+'</li>'); $("#choiseDocListUl").append('<li value="'+item.url+'">'+item.url+'</li>');
} }
$('#choiseDocModal').modal({moveable:true, backdrop:'static', keyboard: false}); $('#choiseDocModal').modal({moveable:true, backdrop:'static', keyboard: false});
} else { } else {
@@ -159,48 +161,6 @@ $("#changeContentWidth").click(function(){
changeContentWidth(isMinWidth ? 360 : 120); changeContentWidth(isMinWidth ? 360 : 120);
}); });
/**
* 修改tree的class
*/
$("input[name='treeShowType']").change(function() {
userSettings.treeShowType = $("input[name='treeShowType']:checked").val();
updateTreeShowType();
storeUserSettings();
});
/**
* 切换url分成一层一层的展示、整个url显示为一层展示
*/
$("input[name='catalogShowType']").change(function() {
userSettings.catalogShowType = $("input[name='catalogShowType']:checked").val();
regeneratePathTree();
storeUserSettings();
});
/**
* 是否展示参数类型
*/
$("input[name='showParamType']").change(function() {
userSettings.showParamType = $("input[name='showParamType']:checked").val();
storeUserSettings();
});
/**
* 是否仅使用上次请求参数
*/
$("input[name='onlyUseLastParam']").change(function() {
userSettings.onlyUseLastParam = $("input[name='onlyUseLastParam']:checked").val();
storeUserSettings();
});
/**
* 是否自动填充请求参数
*/
$("input[name='autoFillParam']").change(function() {
userSettings.autoFillParam = $("input[name='autoFillParam']:checked").val();
storeUserSettings();
});
/** /**
* 搜索框回车事件 * 搜索框回车事件
*/ */
@@ -1030,7 +990,7 @@ function updateTreeShowType() {
* 存储用户设置 * 存储用户设置
*/ */
function storeUserSettings() { function storeUserSettings() {
setStorage('userSettings', userSettings); setStorage(cacheKeys.userSettings, userSettings);
} }
/** /**
@@ -1046,7 +1006,7 @@ function updateUserSettings(newSetting) {
* @returns * @returns
*/ */
function initUserSettings() { function initUserSettings() {
getStorage('userSettings', function(data) { getStorage(cacheKeys.userSettings, function(data) {
userSettings = data; userSettings = data;
if(isEmpty(userSettings) || isEmptyObject(userSettings)) { if(isEmpty(userSettings) || isEmptyObject(userSettings)) {
userSettings = defaultUserSettings; userSettings = defaultUserSettings;
@@ -1057,6 +1017,9 @@ function initUserSettings() {
// 增加文档 // 增加文档
getDocumentListByService(); getDocumentListByService();
}); });
getStorage(cacheKeys.globalParamList, function(data) {
debugGlobalParam = data;
});
} }
function showGlobalLoadingMessage(text, loading) { function showGlobalLoadingMessage(text, loading) {

View File

@@ -77,6 +77,7 @@
var app = new Vue({ var app = new Vue({
el: '#app', el: '#app',
data: { data: {
initCount: 5,
catalogShowType: '', catalogShowType: '',
treeShowType: '', treeShowType: '',
showParamType:'', showParamType:'',
@@ -122,12 +123,14 @@
}, },
} }
}); });
// 存储用户的配置信息 // 存储用户的配置信息
function storeUserSettings(){ function storeUserSettings() {
setStorage(cacheKeys.userSettings, app.userSettings, function(){ if (app.initCount-- <= 0) {
getExport().updateUserSettings(app.userSettings); setStorage(cacheKeys.userSettings, app.userSettings, function () {
}); getExport().updateUserSettings(app.userSettings);
});
}
} }
</script> </script>

View File

@@ -1,5 +1,5 @@
<!doctype html> <!doctype html>
<html> <html xmlns:v-on="http://www.w3.org/1999/xhtml">
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
@@ -14,15 +14,18 @@
<tr> <tr>
<td style="width: 50px;">序号</td> <td style="width: 50px;">序号</td>
<td>地址</td> <td>地址</td>
<td>持久化时间</td>
<td>操作</td> <td>操作</td>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr v-for="(item,index) in swaggerResourcesList" :key="item.id" :data-id="item.id" :data-index="index" > <tr v-for="(item,index) in swaggerResourcesList" :key="item.id" :data-id="item.id" :data-index="index" >
<td>{{index+1}}</td> <td>{{index+1}}</td>
<td>{{item}}</td> <td>{{item.url}}</td>
<td>{{item.lastSync}}</td>
<td> <td>
<button class="btn btn-danger" type="button" v-on:click="deleteDocUrl($event)">删除</button> <button class="btn btn-danger" type="button" v-on:click="deleteDocUrl($event)">删除</button>
<!--<button class="btn btn-danger" type="button" v-on:click="syncDocData($event)">持久化</button>-->
</td> </td>
</tr> </tr>
<tr> <tr>
@@ -93,7 +96,8 @@
ajaxTemp(urlBase + "swagger-mg-ui/document/addSwaggerResources", "post", "json", {resourcesUrl: addNewDocumentInput}, function(json){ ajaxTemp(urlBase + "swagger-mg-ui/document/addSwaggerResources", "post", "json", {resourcesUrl: addNewDocumentInput}, function(json){
if(validateResult(json)) { if(validateResult(json)) {
//window.parent.document.location.reload(); //window.parent.document.location.reload();
app.swaggerResourcesList.push(addNewDocumentInput); //app.swaggerResourcesList.push(addNewDocumentInput);
app.refreshList();
$('#addNewDocumentModal').modal('hide'); $('#addNewDocumentModal').modal('hide');
Toast.success("保存成功,刷新后生效!"); Toast.success("保存成功,刷新后生效!");
} }
@@ -117,6 +121,17 @@
setStorage(cacheKeys.swaggerResourcesList, newDocList, function(){ setStorage(cacheKeys.swaggerResourcesList, newDocList, function(){
app.swaggerResourcesList = newDocList; app.swaggerResourcesList = newDocList;
}); });
},
syncDocData: function(event){
var tr = $(event.currentTarget).parents("tr");
var index = tr.data("index");
var newDocUrl = app.swaggerResourcesList[index].url;
ajaxTemp(urlBase + "swagger-mg-ui/document/syncDocData", "post", "json", {resourcesUrl: newDocUrl}, function(json){
if(validateResult(json)) {
app.refreshList();
Toast.success("持久化成功!");
}
});
} }
}, },
mounted: function(){ mounted: function(){

View File

@@ -24,7 +24,7 @@
<tbody> <tbody>
<tr v-for="(item,index) in globalParamList" :key="item.id" :data-id="item.id" :data-index="index"> <tr v-for="(item,index) in globalParamList" :key="item.id" :data-id="item.id" :data-index="index">
<td> <td>
<select class="form-control" v-model:value="item.position"> <select class="form-control" v-model:value="item.paramIn">
<option value="header">header</option> <option value="header">header</option>
<option value="form">form</option> <option value="form">form</option>
</select> </select>
@@ -81,11 +81,12 @@
}, },
addGlobalParamLine: function () { addGlobalParamLine: function () {
app.globalParamList.push({ app.globalParamList.push({
position: 'header', key: '', value: '' paramIn: 'header', key: '', value: ''
}); });
}, },
saveAllGlobalParam: function () { saveAllGlobalParam: function () {
setStorage(cacheKeys.globalParamList, app.globalParamList, function(){ setStorage(cacheKeys.globalParamList, app.globalParamList, function(){
getExport().updateGlobalParam(app.globalParamList);
Toast.success("保存成功!"); Toast.success("保存成功!");
}); });
}, },