swagger文档展示开发

This commit is contained in:
暮光:城中城
2021-10-20 22:32:25 +08:00
parent 9267aed477
commit 5cb267fba6
16 changed files with 146 additions and 65 deletions

View File

@@ -1,31 +1,20 @@
<template>
<div class="menu-layout">
<div style="padding: 10px 5px;">
<a-select placeholder="请选择分组" v-model:value="swaggerDocChoice" style="width: 100%;">
<a-select-option :value="item.url" v-for="item in swaggerResourceList">{{item.name}}</a-select-option>
</a-select>
</div>
<a-menu theme="light" mode="inline" :inline-collapsed="collapsed" v-model:openKeys="openKeys" v-model:selectedKeys="selectedKeys">
<menu-children-layout :menuItem="menuItem" v-for="menuItem in menuData"></menu-children-layout>
</a-menu>
<a-directory-tree :tree-data="treeData" v-model:expandedKeys="expandedKeys" @select="docChecked">
<a-tree-node key="0-0" title="parent 0">
<a-tree-node key="0-0-0" is-leaf >
<template #title>
<router-link :to="{path: '/doc/view', query: {id: 1}}">leaf 0-0</router-link>
</template>
</a-tree-node>
<a-tree-node key="0-0-1" is-leaf >
<template #title>
<router-link :to="{path: '/doc/view', query: {id: 2}}">leaf 0-1</router-link>
</template>
</a-tree-node>
</a-tree-node>
<a-tree-node key="0-1" title="parent 1">
<a-tree-node key="0-1-0" title="leaf 1-0" is-leaf />
<a-tree-node key="0-1-1" title="leaf 1-1" is-leaf />
</a-tree-node>
</a-directory-tree>
<a-directory-tree :tree-data="treeData" v-model:expandedKeys="expandedKeys" @select="docChecked"></a-directory-tree>
</div>
</template>
<script>
import MenuChildrenLayout from './MenuChildrenLayout.vue'
import {customApi} from '../../api'
export default {
name: 'MenuLayout',
@@ -54,6 +43,8 @@
},
],
expandedKeys: [],
swaggerResourceList: [],
swaggerDocChoice: undefined,
}
},
watch:{
@@ -62,7 +53,7 @@
},
components: {MenuChildrenLayout},
mounted() {
this.getMenuData();
this.menuData = this.$router.options.routes.find((item) => item.path === '/').children[0].children;
let meta = this.$route.meta || {};
let path = this.$route.path;
if (!!meta.parentPath) {
@@ -73,35 +64,22 @@
if (matched.length >= 1) {
this.openKeys = [matched[1].path];
}
this.getSwaggerResourceList();
},
methods: {
getMenuData() {
let menuData = this.$router.options.routes.find((item) => item.path === '/').children[0].children;
this.menuData = JSON.parse(JSON.stringify(menuData));
// 模拟数据返回,暂时不以这种展示
// setTimeout(() => {
// this.menuData.push({
// name: '用户管理接口',
// meta: {icon: 'FileTextOutlined'},
// children: [
// {
// path: '/doc/view?id=2',
// name: '获取用户信息',
// query: {id: 222}
// }, {
// path: '/doc/view?id=3',
// name: '删除用户',
// query: {id: 333}
// }
// ]
// });
// }, 1000);
},
docChecked(val, node) {
if (node.node.isLeaf) {
let dataRef = node.node.dataRef;
this.$router.push({path: dataRef.path, query: dataRef.query});
}
},
getSwaggerResourceList() {
customApi.post('./swagger-resources').then(res => {
this.swaggerResourceList = res || [];
if (this.swaggerResourceList.length > 0) {
this.swaggerDocChoice = this.swaggerResourceList[0].url;
}
});
}
}
}