From 266b728d146cde936e85ea64082f685ffe7f785f Mon Sep 17 00:00:00 2001 From: fengshuonan Date: Thu, 14 Jan 2021 23:26:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9EAPI=E6=96=87=E6=A1=A3?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E7=95=8C=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../guns/modular/api/ApiViewController.java | 30 +++++ src/main/webapp/assets/expand/css/style.css | 22 +++- src/main/webapp/assets/modular/api/api.js | 88 ++++++++++++++ src/main/webapp/pages/modular/api/api.html | 109 ++++++++++++++++++ 4 files changed, 246 insertions(+), 3 deletions(-) create mode 100644 src/main/java/cn/stylefeng/guns/modular/api/ApiViewController.java create mode 100644 src/main/webapp/assets/modular/api/api.js create mode 100644 src/main/webapp/pages/modular/api/api.html diff --git a/src/main/java/cn/stylefeng/guns/modular/api/ApiViewController.java b/src/main/java/cn/stylefeng/guns/modular/api/ApiViewController.java new file mode 100644 index 00000000..c07a7d01 --- /dev/null +++ b/src/main/java/cn/stylefeng/guns/modular/api/ApiViewController.java @@ -0,0 +1,30 @@ +package cn.stylefeng.guns.modular.api; + +import cn.stylefeng.roses.kernel.resource.api.annotation.ApiResource; +import cn.stylefeng.roses.kernel.resource.api.annotation.GetResource; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Controller; + +/** + * API文档管理 + * + * @author fengshuonan + * @date 2021/1/14 21:05 + */ +@Controller +@Slf4j +@ApiResource(name = "API文档管理") +public class ApiViewController { + + /** + * 编辑应用界面 + * + * @author fengshuonan + * @date 2021/1/6 13:37 + */ + @GetResource(name = "API文档界面", path = "/view/api") + public String apiIndex() { + return "/modular/api/api.html"; + } + +} diff --git a/src/main/webapp/assets/expand/css/style.css b/src/main/webapp/assets/expand/css/style.css index 9590501f..cf2db66b 100644 --- a/src/main/webapp/assets/expand/css/style.css +++ b/src/main/webapp/assets/expand/css/style.css @@ -36,7 +36,7 @@ border-top: 3px solid #d2d6de; margin-bottom: 20px; width: 100%; - box-shadow: 0 1px 1px rgba(0,0,0,0.1) + box-shadow: 0 1px 1px rgba(0, 0, 0, 0.1) } .box-main { @@ -44,5 +44,21 @@ border: 0; padding-top: 2px; border-radius: 0; - box-shadow: none -} \ No newline at end of file + box-shadow: none; + overflow: scroll; +} + +.wide-layui-form-label { + float: left; + display: block; + padding: 9px 15px; + width: 130px; + font-weight: 400; + line-height: 20px; + text-align: right; +} + +.wide-layui-input-block { + margin-left: 160px; + min-height: 36px; +} diff --git a/src/main/webapp/assets/modular/api/api.js b/src/main/webapp/assets/modular/api/api.js new file mode 100644 index 00000000..23b49ebc --- /dev/null +++ b/src/main/webapp/assets/modular/api/api.js @@ -0,0 +1,88 @@ +layui.use(['layer', 'form', 'table', 'HttpRequest', 'func', 'tree'], function () { + var $ = layui.jquery; + var form = layui.form; + var table = layui.table; + var HttpRequest = layui.HttpRequest; + var func = layui.func; + var tree = layui.tree; + + /** + * Api管理的参数 + */ + var ApiManager = { + condition: { + resourceCode: "", + resourceName: "" + } + }; + + // 选择api树上的接口时 + ApiManager.onClickApi = function (obj) { + ApiManager.condition.resourceCode = obj.data.id; + + // 如果是具体接口,则查看接口详情 + if (obj.data.resourceFlag === true) { + ApiManager.search(); + } + }; + + // 点击查询按钮 + ApiManager.search = function () { + var detailRequest = new HttpRequest(Feng.ctxPath + "/resource/getDetail", 'get', function (data) { + form.val('apiDetailForm', data.data); + }, function (data) { + Feng.error("查询失败!" + data.message); + }); + detailRequest.set("resourceCode", ApiManager.condition.resourceCode); + var detailResult = detailRequest.start(false); + + // 参数的表头 + var columns = [[ + {field: 'chineseName', title: '中文名称', width: 150}, + {field: 'fieldClassType', title: '字段类型', width: 150}, + {field: 'fieldName', title: '字段名称', width: 200}, + { + field: 'groupAnnotations', title: '按校验组分的注解集合', templet: function (data) { + return JSON.stringify(data.groupAnnotations); + } + } + ]]; + + // 渲染请求参数列表 + table.render({ + elem: '#requestParamsTable', + cols: columns, + data: detailResult.data.paramFieldDescriptions, + even: true + }); + + // 渲染请求参数列表 + table.render({ + elem: '#responseParamsTable', + cols: columns, + data: detailResult.data.responseFieldDescriptions, + even: true + }); + + }; + + // 初始化api树 + var request = new HttpRequest(Feng.ctxPath + '/resource/getTree', 'get', function (data) { + tree.render({ + elem: '#apiTree', + data: data.data, + click: ApiManager.onClickApi, + onlyIconControl: true + }); + }); + request.start(); + +}); + +$(function () { + var panehHidden = false; + if ($(this).width() < 769) { + panehHidden = true; + } + $('#myContiner').layout({initClosed: panehHidden, west__size: 330}); +}); diff --git a/src/main/webapp/pages/modular/api/api.html b/src/main/webapp/pages/modular/api/api.html new file mode 100644 index 00000000..bc7293b4 --- /dev/null +++ b/src/main/webapp/pages/modular/api/api.html @@ -0,0 +1,109 @@ +@layout("/layout/_tree_container.html", {plugins:["jquery-layout"], js:["/assets/modular/api/api.js"]}){ + +
+ API接口文档 +
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 接口详情 +
+
+
+
+
+ +
+ +
+
+
+
+
+ +
+ +
+
+
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ 请求参数 +
+ +
+ +
+ 响应参数 +
+ +
+ +
+
+
+
+
+
+
+ +@}