dubbo文档展示优化
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
||||
<!DOCTYPE HTML>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
@@ -10,101 +10,133 @@
|
||||
<body>
|
||||
<div id="app">
|
||||
<el-container style="height: 100%;">
|
||||
|
||||
<el-aside width="200px" style="height: 100%;">
|
||||
<el-radio-group v-model="isCollapse" style="margin-bottom: 20px;">
|
||||
<el-radio-button :label="false">展开</el-radio-button>
|
||||
<el-radio-button :label="true">收起</el-radio-button>
|
||||
</el-radio-group>
|
||||
<el-menu default-active="1-4-1" class="el-menu-vertical-demo" @open="handleOpen" @close="handleClose" :collapse="isCollapse">
|
||||
<el-aside width="auto" style="height: 100%;padding-top: 10px;">
|
||||
<el-row><el-button type="primary" v-on:click="reloadService">重新加载服务列表</el-button></el-row>
|
||||
<el-row><el-switch v-model="isCollapse"></el-switch></el-row>
|
||||
<el-menu default-active="" class="el-menu-vertical-demo" @open="handleOpen" @close="handleClose" :collapse="isCollapse">
|
||||
<el-submenu index="1">
|
||||
<template slot="title">
|
||||
<i class="el-icon-location"></i>
|
||||
<span slot="title">导航一</span>
|
||||
</template>
|
||||
<el-menu-item-group>
|
||||
<span slot="title">分组一</span>
|
||||
<el-menu-item index="1-1">选项1</el-menu-item>
|
||||
<el-menu-item index="1-2">选项2</el-menu-item>
|
||||
</el-menu-item-group>
|
||||
<el-menu-item-group title="分组2">
|
||||
<el-menu-item index="1-3">选项3</el-menu-item>
|
||||
</el-menu-item-group>
|
||||
<el-submenu index="1-4">
|
||||
<span slot="title">选项4</span>
|
||||
<el-menu-item index="1-4-1">选项1</el-menu-item>
|
||||
</el-submenu>
|
||||
</el-submenu>
|
||||
<el-menu-item index="2">
|
||||
<i class="el-icon-menu"></i>
|
||||
<span slot="title">导航二</span>
|
||||
</el-menu-item>
|
||||
<el-menu-item index="3" disabled>
|
||||
<i class="el-icon-document"></i>
|
||||
<span slot="title">导航三</span>
|
||||
</el-menu-item>
|
||||
<el-menu-item index="4">
|
||||
<i class="el-icon-setting"></i>
|
||||
<span slot="title">导航四</span>
|
||||
</el-menu-item>
|
||||
</el-menu>
|
||||
<el-tree :data="pathIndex" :props="defaultProps" @node-click="handleNodeClick"></el-tree>
|
||||
</el-aside>
|
||||
<el-container>
|
||||
<el-main>Main</el-main>
|
||||
<el-tabs type="border-card" style="width: 100%;">
|
||||
<el-tab-pane label="接口说明">
|
||||
<el-form label-width="80px">
|
||||
<el-form-item label="服务:">
|
||||
{{dubboInfo.interface}}
|
||||
</el-form-item>
|
||||
<el-form-item label="方法:">
|
||||
{{dubboInfo.method}}
|
||||
</el-form-item>
|
||||
<el-form-item label="说明:">
|
||||
|
||||
</el-form-item>
|
||||
<el-form-item label="参数:">
|
||||
|
||||
</el-form-item>
|
||||
<el-form-item label="结果:">
|
||||
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</el-tab-pane>
|
||||
<el-tab-pane label="在线调试">
|
||||
在线调试页面
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
</el-container>
|
||||
</el-container>
|
||||
</div>
|
||||
</body>
|
||||
<script src="https://unpkg.com/vue/dist/vue.js"></script>
|
||||
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
|
||||
<script type="text/javascript" src="https://unpkg.com/vue/dist/vue.js"></script>
|
||||
<script type="text/javascript" src="https://unpkg.com/element-ui/lib/index.js"></script>
|
||||
<script type="text/javascript" src="webjars/doc-dubbo/js/jquery-3.1.0.min.js"></script>
|
||||
<script type="text/javascript" src="webjars/doc-dubbo/js/common.js"></script>
|
||||
<script type="text/javascript" src="webjars/doc-dubbo/js/doc-dubbo-tree.js"></script>
|
||||
|
||||
<script>
|
||||
|
||||
new Vue({
|
||||
var app = new Vue({
|
||||
el: '#app',
|
||||
data() {
|
||||
const item = {
|
||||
date: '2016-05-02',
|
||||
name: '王小虎',
|
||||
address: '上海市普陀区金沙江路 1518 弄'
|
||||
};
|
||||
return {
|
||||
tableData: Array(20).fill(item)
|
||||
isCollapse: false,
|
||||
pathIndex: [],
|
||||
defaultProps: {
|
||||
children: 'children',
|
||||
label: 'label'
|
||||
},
|
||||
// 展示的信息
|
||||
dubboInfo: {},
|
||||
// 树的下表
|
||||
projectTreeIdIndex: 1,
|
||||
// 依据目录树存储的map全局对象
|
||||
treePathDataMap: new Map(),
|
||||
// dubbo列表
|
||||
dubboDocList: [],
|
||||
}
|
||||
},
|
||||
mounted: function(){
|
||||
ajaxTemp("zyplayer-doc-dubbo/doc-dubbo/getDocList", "get", "json", {}, function (json) {
|
||||
if (validateResult(json)) {
|
||||
dubboDocList = json.data || [];
|
||||
app.pathIndex = createTreeViewByTree(dubboDocList);
|
||||
}
|
||||
});
|
||||
},
|
||||
methods: {
|
||||
handleOpen(key, keyPath) {
|
||||
console.log(key, keyPath);
|
||||
},
|
||||
handleClose(key, keyPath) {
|
||||
console.log(key, keyPath);
|
||||
},
|
||||
handleNodeClick(data) {
|
||||
if (data.children == null) {
|
||||
var path = data.interface;
|
||||
var dubboInfo = app.treePathDataMap.get(path);
|
||||
dubboInfo.method = data.method;
|
||||
app.dubboInfo = dubboInfo;
|
||||
console.log(data);
|
||||
}
|
||||
},
|
||||
reloadService(){
|
||||
ajaxTemp("zyplayer-doc-dubbo/doc-dubbo/reloadService", "get", "json", {}, function (json) {
|
||||
if (validateResult(json)) {
|
||||
app.$message({
|
||||
message: '加载成功!',
|
||||
type: 'success'
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
</script>
|
||||
<style>
|
||||
.el-header, .el-footer {
|
||||
background-color: #B3C0D1;
|
||||
color: #333;
|
||||
text-align: center;
|
||||
line-height: 60px;
|
||||
}
|
||||
.el-aside {
|
||||
background-color: #fff;
|
||||
color: #333;
|
||||
text-align: center;
|
||||
}
|
||||
.el-main {
|
||||
background-color: #E9EEF3;
|
||||
color: #333;
|
||||
text-align: center;
|
||||
line-height: 160px;
|
||||
}
|
||||
.el-menu {
|
||||
box-sizing: border-box;
|
||||
border-right: 0;
|
||||
margin-right: 3px;
|
||||
}
|
||||
body > .el-container {
|
||||
margin-bottom: 40px;
|
||||
.el-tree{
|
||||
margin-right: 3px;
|
||||
}
|
||||
.el-menu-vertical-demo:not(.el-menu--collapse) {
|
||||
width: 200px;
|
||||
.el-tree-node__content{
|
||||
padding-right: 20px;
|
||||
}
|
||||
html,body {
|
||||
html,body,#app {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
@@ -0,0 +1,139 @@
|
||||
/**
|
||||
* 以树形方式生成并展示:
|
||||
* /api
|
||||
* /data
|
||||
* /getDateList
|
||||
* post
|
||||
* get
|
||||
* @author 暮光:城中城
|
||||
* @since 2018年5月26日
|
||||
*/
|
||||
|
||||
/**
|
||||
* 把原始的json字符串转换成对象列表的方式,方便后续使用
|
||||
* @param json swagger的原始对象
|
||||
* @returns
|
||||
*/
|
||||
function createTreeViewByTree(json, keywords) {
|
||||
var pathIndex = [];
|
||||
if (isEmptyObject(json)) {
|
||||
return;
|
||||
}
|
||||
//console.log(paths);
|
||||
for (var i = 0; i < json.length; i++) {
|
||||
var interface = json[i].interface;
|
||||
//console.log(key, paths[key]);
|
||||
if (!findInPathsValue(json[i], keywords)) {
|
||||
continue;
|
||||
}
|
||||
if (json[i].nodeList.length <= 0) {
|
||||
continue;
|
||||
}
|
||||
var methods = json[i].nodeList[0].methods;
|
||||
for (var j = 0; j < methods.length; j++) {
|
||||
var interfaceTemp = interface + "." + methods[j];
|
||||
var keyArr = interfaceTemp.split(".");
|
||||
var nowPathObj = null;
|
||||
keyArr.forEach(function(val, index) {
|
||||
//console.log(val, index);
|
||||
if(isEmpty(val) && index == 0) {
|
||||
return;
|
||||
}
|
||||
var nowPath = val;
|
||||
// if(nowPathObj == null) {
|
||||
// nowPathObj = [];
|
||||
// var temp = nowPathObj[0] = {};
|
||||
// temp[nowPath] = findNode(pathIndex, nowPath);
|
||||
// if (temp[nowPath] == null) {
|
||||
// temp[nowPath] = {};
|
||||
// pathIndex.push(nowPathObj);
|
||||
// }
|
||||
// }
|
||||
// var tempPathObj = findNode(nowPathObj, nowPath);
|
||||
// if(isEmpty(tempPathObj)) {
|
||||
// var temp = [];
|
||||
// tempPathObj = temp[0] = {};
|
||||
// nowPathObj.push(temp);
|
||||
// }
|
||||
// nowPathObj = tempPathObj;
|
||||
// nowPathObj.label = nowPath;
|
||||
if (nowPathObj == null) {
|
||||
nowPathObj = findNode(pathIndex, nowPath);
|
||||
if (nowPathObj == null) {
|
||||
nowPathObj = {label: nowPath, children: []};
|
||||
pathIndex.push(nowPathObj);
|
||||
}
|
||||
nowPathObj = nowPathObj.children;
|
||||
} else {
|
||||
var tempPathObj = findNode(nowPathObj, nowPath);
|
||||
if(tempPathObj == null) {
|
||||
tempPathObj = {label: nowPath, children: []};
|
||||
nowPathObj.push(tempPathObj);
|
||||
}
|
||||
nowPathObj = tempPathObj.children;
|
||||
if (index == keyArr.length - 1) {
|
||||
var tempPath = app.projectTreeIdIndex + ":" + interfaceTemp;
|
||||
tempPathObj.children = null;
|
||||
tempPathObj.method = methods[j];
|
||||
tempPathObj.interface = tempPath;
|
||||
app.treePathDataMap.set(tempPath, json[i]);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
app.projectTreeIdIndex++;
|
||||
//var htmlStr = getTreeHtmlForTree(pathIndex, app.projectTreeIdIndex);
|
||||
console.log(pathIndex);
|
||||
return pathIndex;
|
||||
}
|
||||
|
||||
function findNode(arr, service){
|
||||
for (var i = 0; i < arr.length; i++) {
|
||||
if(arr[i].label == service) {
|
||||
return arr[i];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将对象列表递归的方式转换成文档格式html字符串
|
||||
* @param pathData 处理后的对象列表
|
||||
* @returns 生成的html字符串
|
||||
*/
|
||||
function getTreeHtmlForTree(pathData, treeIdStr) {
|
||||
var tempStr = "";
|
||||
var indexNow = 1;
|
||||
Object.keys(pathData).forEach(function (key) {
|
||||
var tempNode = pathData[key];
|
||||
var tempTreeId = treeIdStr + "_" + indexNow;
|
||||
if (isNotEmpty(tempNode.interface)) {
|
||||
tempNode.treeId = tempTreeId;
|
||||
tempStr += '<li m-id="' + tempTreeId + '"><a href="#" class="show-doc" method="' + tempNode.method + '" path="' + tempNode.interface + '">' + key + '</a></li>';
|
||||
} else {
|
||||
tempStr += '<li>';
|
||||
tempStr += '<a href="#">' + key + '</a>';
|
||||
tempStr += '<ul>';
|
||||
tempStr += getTreeHtmlForTree(tempNode, tempTreeId);
|
||||
tempStr += '</ul>';
|
||||
tempStr += '</li>';
|
||||
}
|
||||
indexNow++;
|
||||
});
|
||||
return tempStr;
|
||||
}
|
||||
|
||||
function findInPathsValue(pathsValue, keywords) {
|
||||
if (isEmpty(keywords)) {
|
||||
return true;
|
||||
}
|
||||
keywords = keywords.toLowerCase();
|
||||
// 找路径和说明里面包含关键字的
|
||||
var interface = pathsValue.interface;
|
||||
if (isNotEmpty(interface) && interface.toLowerCase().indexOf(keywords) >= 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -20,9 +20,9 @@ $(document).ready(function(){
|
||||
globalLoadingMessager = new $.zui.Messager({type: 'primary', close: false, time: 0}).show();
|
||||
showGlobalLoadingMessage('获取文档列表中,请稍候...', true);
|
||||
ajaxTemp("zyplayer-doc-dubbo/doc-dubbo/getDocList", "get", "json", {}, function (json) {
|
||||
if (validateResult(json) && json.data.length >= 1) {
|
||||
dubboDocList = json.data;
|
||||
createTreeViewByTree(json.data);
|
||||
if (validateResult(json)) {
|
||||
dubboDocList = json.data || [];
|
||||
createTreeViewByTree(dubboDocList);
|
||||
initDashboard();
|
||||
documentLoadFinish();
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ zyplayer:
|
||||
dubbo:
|
||||
# 优先使用zookeeper,未配置时找nacos的配置
|
||||
zookeeper:
|
||||
# url: 127.0.0.1:2181
|
||||
url: 127.0.0.1:2181
|
||||
nacos:
|
||||
url: http://127.0.0.1:8848/nacos
|
||||
# 服务名称,多个使用 ; 分割,nacos没办法获取所有的服务列表,所以需要指定
|
||||
|
||||
Reference in New Issue
Block a user