2021-10-17 19:50:22 +08:00
|
|
|
<template>
|
|
|
|
|
<div class="menu-layout">
|
2021-10-23 23:13:56 +08:00
|
|
|
<a-menu theme="light" mode="inline" :inline-collapsed="false" v-model:openKeys="openKeys" v-model:selectedKeys="selectedKeys">
|
2021-10-17 19:50:22 +08:00
|
|
|
<menu-children-layout :menuItem="menuItem" v-for="menuItem in menuData"></menu-children-layout>
|
|
|
|
|
</a-menu>
|
2021-10-23 23:13:56 +08:00
|
|
|
<a-divider style="margin: 6px 0;"/>
|
2021-10-26 22:32:42 +08:00
|
|
|
<div v-show="!collapsed" class="doc-tree">
|
2021-10-23 23:13:56 +08:00
|
|
|
<div style="padding: 10px 5px;">
|
2021-10-26 22:32:42 +08:00
|
|
|
<a-select placeholder="请选择分组" v-model:value="swaggerDocChoice" @change="swaggerDocChoiceChange" style="width: 100%;">
|
2021-10-23 23:13:56 +08:00
|
|
|
<a-select-option :value="item.url" v-for="item in swaggerResourceList">{{item.name}}</a-select-option>
|
|
|
|
|
</a-select>
|
|
|
|
|
</div>
|
2021-10-26 22:32:42 +08:00
|
|
|
<a-directory-tree :showIcon="false" :tree-data="treeData" v-model:expandedKeys="expandedKeys" @select="docChecked">
|
|
|
|
|
<template #title="{ title, isLeaf, method }">
|
|
|
|
|
<template v-if="isLeaf">
|
|
|
|
|
<a-tag color="pink" v-if="method === 'get'">get</a-tag>
|
|
|
|
|
<a-tag color="red" v-else-if="method === 'post'">post</a-tag>
|
|
|
|
|
<a-tag color="orange" v-else-if="method === 'put'">put</a-tag>
|
|
|
|
|
<a-tag color="green" v-else-if="method === 'head'">head</a-tag>
|
|
|
|
|
<a-tag color="cyan" v-else-if="method === 'patch'">patch</a-tag>
|
|
|
|
|
<a-tag color="blue" v-else-if="method === 'delete'">delete</a-tag>
|
|
|
|
|
<a-tag color="purple" v-else-if="method === 'options'">options</a-tag>
|
|
|
|
|
<a-tag color="purple" v-else-if="method === 'trace'">trace</a-tag>
|
|
|
|
|
</template>
|
|
|
|
|
{{title}}
|
|
|
|
|
</template>
|
|
|
|
|
</a-directory-tree>
|
2021-10-23 23:13:56 +08:00
|
|
|
</div>
|
2021-10-17 19:50:22 +08:00
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
import MenuChildrenLayout from './MenuChildrenLayout.vue'
|
2021-10-20 22:32:25 +08:00
|
|
|
import {customApi} from '../../api'
|
2021-10-26 22:32:42 +08:00
|
|
|
import {createTreeViewByTag, getTreeDataForTag} from '../../store/SwaggerDocUtil'
|
2021-10-17 19:50:22 +08:00
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
name: 'MenuLayout',
|
2021-10-23 23:13:56 +08:00
|
|
|
props: {
|
|
|
|
|
collapsed: {
|
|
|
|
|
type: Boolean,
|
|
|
|
|
default: false
|
|
|
|
|
},
|
|
|
|
|
},
|
2021-10-17 19:50:22 +08:00
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
menuData: [],
|
|
|
|
|
selectedKeys: [],
|
|
|
|
|
openKeys: [],
|
|
|
|
|
// 文档树
|
|
|
|
|
treeData: [
|
|
|
|
|
{
|
|
|
|
|
title: '用户管理接口文档',
|
|
|
|
|
key: '0-0',
|
|
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
title: '用户信息管理',
|
|
|
|
|
key: '0-0-0',
|
|
|
|
|
children: [
|
2021-10-26 22:32:42 +08:00
|
|
|
{title: '/getUserInfo', key: '0-0-0-0', isLeaf: true, query: {path: '/getUserInfo'}},
|
|
|
|
|
{title: '/deleteUserInfo', key: '0-0-0-1', isLeaf: true, query: {path: '/deleteUserInfo'}},
|
|
|
|
|
{title: '/updateUserInfo', key: '0-0-0-2', isLeaf: true, query: {path: '/updateUserInfo'}},
|
2021-10-17 19:50:22 +08:00
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
expandedKeys: [],
|
2021-10-20 22:32:25 +08:00
|
|
|
swaggerResourceList: [],
|
|
|
|
|
swaggerDocChoice: undefined,
|
2021-10-17 19:50:22 +08:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
watch:{
|
|
|
|
|
'$store.state.userInfo'(userInfo) {
|
2021-10-23 23:13:56 +08:00
|
|
|
},
|
|
|
|
|
collapsed(x) {
|
|
|
|
|
console.log(x, this.collapsed)
|
2021-10-17 19:50:22 +08:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
components: {MenuChildrenLayout},
|
|
|
|
|
mounted() {
|
2021-10-20 22:32:25 +08:00
|
|
|
this.menuData = this.$router.options.routes.find((item) => item.path === '/').children[0].children;
|
2021-10-17 19:50:22 +08:00
|
|
|
let meta = this.$route.meta || {};
|
|
|
|
|
let path = this.$route.path;
|
|
|
|
|
if (!!meta.parentPath) {
|
|
|
|
|
path = meta.parentPath;
|
|
|
|
|
}
|
|
|
|
|
this.selectedKeys = [path];
|
|
|
|
|
let matched = this.$route.matched;
|
|
|
|
|
if (matched.length >= 1) {
|
|
|
|
|
this.openKeys = [matched[1].path];
|
|
|
|
|
}
|
2021-10-20 22:32:25 +08:00
|
|
|
this.getSwaggerResourceList();
|
2021-10-17 19:50:22 +08:00
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
docChecked(val, node) {
|
|
|
|
|
if (node.node.isLeaf) {
|
|
|
|
|
let dataRef = node.node.dataRef;
|
2021-10-26 22:32:42 +08:00
|
|
|
this.$router.push({path: '/doc/view', query: dataRef.query});
|
2021-10-17 19:50:22 +08:00
|
|
|
}
|
2021-10-20 22:32:25 +08:00
|
|
|
},
|
|
|
|
|
getSwaggerResourceList() {
|
2021-10-26 22:32:42 +08:00
|
|
|
customApi.get('./swagger-resources').then(res => {
|
2021-10-20 23:34:59 +08:00
|
|
|
if (res instanceof Array) {
|
|
|
|
|
this.swaggerResourceList = res || [];
|
|
|
|
|
if (this.swaggerResourceList.length > 0) {
|
|
|
|
|
this.swaggerDocChoice = this.swaggerResourceList[0].url;
|
2021-10-26 22:32:42 +08:00
|
|
|
this.swaggerDocChoiceChange();
|
2021-10-20 23:34:59 +08:00
|
|
|
}
|
2021-10-23 23:13:56 +08:00
|
|
|
} else {
|
|
|
|
|
this.$message.error('获取文档列表请求失败');
|
2021-10-20 22:32:25 +08:00
|
|
|
}
|
|
|
|
|
});
|
2021-10-26 22:32:42 +08:00
|
|
|
},
|
|
|
|
|
swaggerDocChoiceChange() {
|
|
|
|
|
this.loadV2Doc(this.swaggerDocChoice);
|
|
|
|
|
},
|
|
|
|
|
loadV2Doc(url) {
|
|
|
|
|
customApi.get(url).then(res => {
|
|
|
|
|
let v2Doc = this.toJsonObj(res);
|
|
|
|
|
if (typeof v2Doc !== 'object') {
|
|
|
|
|
this.$message.error('获取文档数据请求失败');
|
|
|
|
|
}
|
|
|
|
|
this.$store.commit('setSwaggerDoc', v2Doc);
|
|
|
|
|
let metaInfo = {url};
|
|
|
|
|
let treeData = createTreeViewByTag(v2Doc);
|
|
|
|
|
this.treeData = getTreeDataForTag(v2Doc, treeData.pathIndex, metaInfo);
|
|
|
|
|
this.$store.commit('setSwaggerTreePathMap', treeData.treePathDataMap);
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
toJsonObj(value) {
|
|
|
|
|
if (typeof value !== 'string') {
|
|
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
return JSON.parse(value);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
try {
|
|
|
|
|
return eval('(' + value + ')');// 处理变态的单双引号共存字符串
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return value || undefined;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-10-17 19:50:22 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
2021-10-26 22:32:42 +08:00
|
|
|
<style>
|
|
|
|
|
.doc-tree{padding: 10px 4px;}
|
|
|
|
|
.doc-tree .ant-tree-switcher{width: 15px;}
|
|
|
|
|
.doc-tree .ant-tree-switcher-noop{width: 0;}
|
|
|
|
|
.doc-tree .ant-tag{margin-right: 0;}
|
|
|
|
|
</style>
|