swagger文档展示开发
This commit is contained in:
6
zyplayer-doc-ui/swagger-ui/src/api/custom.js
Normal file
6
zyplayer-doc-ui/swagger-ui/src/api/custom.js
Normal file
@@ -0,0 +1,6 @@
|
||||
import apiClient from './request/custom.js'
|
||||
|
||||
export const customApi = {
|
||||
post: (url, data) => apiClient({url: url, method: 'post', data: data}),
|
||||
};
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
export { zyplayerApi } from './zyplayer.js';
|
||||
export { customApi } from './custom.js';
|
||||
|
||||
|
||||
|
||||
14
zyplayer-doc-ui/swagger-ui/src/api/request/custom.js
Normal file
14
zyplayer-doc-ui/swagger-ui/src/api/request/custom.js
Normal file
@@ -0,0 +1,14 @@
|
||||
import Axios from 'axios'
|
||||
import interceptors from './interceptors'
|
||||
import {getCustomApiBaseUrl} from "./utils";
|
||||
|
||||
const apiClient = Axios.create({
|
||||
baseURL: getCustomApiBaseUrl(),
|
||||
timeout: 20000,
|
||||
headers: {'Content-type': 'application/x-www-form-urlencoded'},
|
||||
withCredentials: true
|
||||
});
|
||||
interceptors(apiClient);
|
||||
|
||||
export default apiClient;
|
||||
|
||||
@@ -4,7 +4,7 @@ import {getZyplayerApiBaseUrl} from "./utils";
|
||||
|
||||
// 增加不需要验证结果的标记
|
||||
const noValidate = {
|
||||
"/zyplayer-doc-db/executor/execute": true,
|
||||
"./swagger-resources": true,
|
||||
"/zyplayer-doc-db/datasource/test": true,
|
||||
};
|
||||
|
||||
@@ -38,7 +38,7 @@ export default function (axios) {
|
||||
response => {
|
||||
if (!!response.message) {
|
||||
vue.$message.error('请求错误:' + response.message);
|
||||
}else {
|
||||
} else {
|
||||
if (!response.config.needValidateResult || response.data.errCode === 200) {
|
||||
return response.data;
|
||||
} else if (response.data.errCode === 400) {
|
||||
|
||||
@@ -11,3 +11,15 @@ export function getZyplayerApiBaseUrl() {
|
||||
return baseUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取custom后端域名
|
||||
*/
|
||||
export function getCustomApiBaseUrl() {
|
||||
let env = import.meta.env.VITE_APP_ENV;
|
||||
let baseUrl = import.meta.env.VITE_APP_CUSTOM_URL_ONLINE;
|
||||
if ("dev" === env) {
|
||||
baseUrl = import.meta.env.VITE_APP_CUSTOM_URL_DEV;
|
||||
}
|
||||
return baseUrl;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,10 +20,18 @@ let routers = [
|
||||
path: '/doc/console',
|
||||
name: '控制台',
|
||||
meta: {
|
||||
icon: 'DashboardOutlined'
|
||||
hidden: true,
|
||||
},
|
||||
component: () => import('./views/common/Console.vue')
|
||||
},
|
||||
{
|
||||
path: '/doc/manage',
|
||||
name: '文档管理',
|
||||
meta: {
|
||||
icon: 'DashboardOutlined'
|
||||
},
|
||||
component: () => import('./views/doc/DocManage.vue')
|
||||
},
|
||||
{
|
||||
path: '/doc/setting',
|
||||
name: '系统配置',
|
||||
|
||||
48
zyplayer-doc-ui/swagger-ui/src/views/doc/DocManage.vue
Normal file
48
zyplayer-doc-ui/swagger-ui/src/views/doc/DocManage.vue
Normal file
@@ -0,0 +1,48 @@
|
||||
<template>
|
||||
<a-table :dataSource="dataSource" :columns="columns"/>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { ref, onMounted } from 'vue'
|
||||
|
||||
export default {
|
||||
setup() {
|
||||
onMounted(() => {
|
||||
console.log('Component is mounted!');
|
||||
});
|
||||
return {
|
||||
dataSource: [
|
||||
{
|
||||
key: '1',
|
||||
name: '胡彦斌',
|
||||
age: 32,
|
||||
address: '西湖区湖底公园1号',
|
||||
},
|
||||
{
|
||||
key: '2',
|
||||
name: '胡彦祖',
|
||||
age: 42,
|
||||
address: '西湖区湖底公园1号',
|
||||
},
|
||||
],
|
||||
columns: [
|
||||
{
|
||||
title: '姓名',
|
||||
dataIndex: 'name',
|
||||
key: 'name',
|
||||
},
|
||||
{
|
||||
title: '年龄',
|
||||
dataIndex: 'age',
|
||||
key: 'age',
|
||||
},
|
||||
{
|
||||
title: '住址',
|
||||
dataIndex: 'address',
|
||||
key: 'address',
|
||||
},
|
||||
],
|
||||
};
|
||||
},
|
||||
};
|
||||
</script>
|
||||
Reference in New Issue
Block a user