接口文档
This commit is contained in:
parent
2e3d3163ef
commit
4b237386ad
|
|
@ -5,5 +5,5 @@ VITE_APP_TITLE=里派基础框架
|
|||
VITE_APP_ENV='development'
|
||||
|
||||
# 开发环境
|
||||
VITE_API_BASE='https://demo.leapy.cn/admin/'
|
||||
VITE_API_BASE='https://demo.leapy.cn'
|
||||
VITE_WS_URL='wss://demo.leapy.cn/ws'
|
||||
|
|
|
|||
|
|
@ -5,5 +5,5 @@ VITE_APP_TITLE=里派基础框架
|
|||
VITE_APP_ENV='production'
|
||||
|
||||
# 生产环境
|
||||
VITE_API_BASE='https://demo.leapy.cn/admin/'
|
||||
VITE_API_BASE='https://demo.leapy.cn'
|
||||
VITE_WS_URL='wss://demo.leapy.cn/ws'
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@
|
|||
"eslint": "^9.27.0",
|
||||
"sass": "^1.89.0",
|
||||
"typescript": "^5.8.3",
|
||||
"vite": "7.1.5"
|
||||
"vite": "7.1.11"
|
||||
},
|
||||
"license": "MIT"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -129,5 +129,10 @@ export default {
|
|||
empty: async function (data = {}) {
|
||||
return await http.delete("crontab_log/remove_all", data);
|
||||
},
|
||||
},
|
||||
swagger: {
|
||||
list: async function (data = {}) {
|
||||
return await http.get("swagger/json", data);
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
<template>
|
||||
<svg t="1761552477023" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5272" width="256" height="256"><path d="M624 706.3h-74.1V464c0-4.4-3.6-8-8-8h-60c-4.4 0-8 3.6-8 8v242.3H400c-6.7 0-10.4 7.7-6.3 12.9l112 141.7c3.2 4.1 9.4 4.1 12.6 0l112-141.7c4.1-5.2 0.4-12.9-6.3-12.9z" p-id="5273"></path><path d="M811.4 366.7C765.6 245.9 648.9 160 512.2 160S258.8 245.8 213 366.6C127.3 389.1 64 467.2 64 560c0 110.5 89.5 200 199.9 200H304c4.4 0 8-3.6 8-8v-60c0-4.4-3.6-8-8-8h-40.1c-33.7 0-65.4-13.4-89-37.7-23.5-24.2-36-56.8-34.9-90.6 0.9-26.4 9.9-51.2 26.2-72.1 16.7-21.3 40.1-36.8 66.1-43.7l37.9-9.9 13.9-36.6c8.6-22.8 20.6-44.1 35.7-63.4 14.9-19.2 32.6-35.9 52.4-49.9 41.1-28.9 89.5-44.2 140-44.2s98.9 15.3 140 44.2c19.9 14 37.5 30.8 52.4 49.9 15.1 19.3 27.1 40.7 35.7 63.4l13.8 36.5 37.8 10C846.1 454.5 884 503.8 884 560c0 33.1-12.9 64.3-36.3 87.7-23.4 23.4-54.5 36.3-87.6 36.3H720c-4.4 0-8 3.6-8 8v60c0 4.4 3.6 8 8 8h40.1C870.5 760 960 670.5 960 560c0-92.7-63.1-170.7-148.6-193.3z" p-id="5274"></path></svg>
|
||||
</template>
|
||||
|
|
@ -0,0 +1,237 @@
|
|||
<template>
|
||||
<el-container style="height: calc(100vh - 86px);">
|
||||
<el-aside width="280px">
|
||||
<el-container>
|
||||
<el-header>
|
||||
<el-input placeholder="输入关键词搜搜" prefix-icon="el-icon-search" readonly>
|
||||
<template #suffix>
|
||||
<el-tag type="info" style="letter-spacing: 0.2em;">^K</el-tag>
|
||||
</template>
|
||||
</el-input>
|
||||
</el-header>
|
||||
<el-main class="nopadding">
|
||||
<el-tree ref="apiRef" :data="apis" node-key="name" :props="{ children: 'children', label: 'name' }"
|
||||
@node-click="apiClick">
|
||||
<template #default="{ node, data }">
|
||||
<span class="custom-tree-node el-tree-node__label">
|
||||
<span class="label">
|
||||
{{ node.label }}
|
||||
</span>
|
||||
<span class="do">
|
||||
<el-text v-if="data.method==='GET'" type="success">GET</el-text>
|
||||
<el-text v-else-if="data.method==='POST'" type="warning">POST</el-text>
|
||||
<el-text v-else-if="data.method==='PUT'" type="primary">PUT</el-text>
|
||||
<el-text v-else-if="data.method==='DELETE'" type="danger">DELETE</el-text>
|
||||
<el-text v-else-if="!data.children" type="warning">{{ data.method }}</el-text>
|
||||
</span>
|
||||
</span>
|
||||
</template>
|
||||
</el-tree>
|
||||
</el-main>
|
||||
<el-footer style="height:50px;text-align: center;">
|
||||
<el-text type="info" size="small">里派提供技术支持</el-text>
|
||||
</el-footer>
|
||||
</el-container>
|
||||
</el-aside>
|
||||
<el-container>
|
||||
<el-header>
|
||||
<section>
|
||||
<el-breadcrumb separator="/">
|
||||
<el-breadcrumb-item>{{ project.info.title }}</el-breadcrumb-item>
|
||||
<el-breadcrumb-item v-for="item in data.tags" :key="item">{{ item }}</el-breadcrumb-item>
|
||||
<el-breadcrumb-item>{{ data.name }}</el-breadcrumb-item>
|
||||
</el-breadcrumb>
|
||||
</section>
|
||||
<section>
|
||||
<el-tag type="info">v{{ project.info.version }}</el-tag>
|
||||
<el-tag type="info">OAS {{ project.json.openapi }}</el-tag>
|
||||
<el-button type="primary" icon="pi-icon-cloud-down" size="small" style="margin-left: 10px;"
|
||||
@click="saveJsonFile">导出
|
||||
</el-button>
|
||||
<el-dropdown @command="switchProject">
|
||||
<span class="el-dropdown-link">
|
||||
{{ project.info.title }}
|
||||
<el-icon class="el-icon--right"><component :is="'el-icon-arrow-down'"/></el-icon>
|
||||
</span>
|
||||
<template #dropdown>
|
||||
<el-dropdown-menu>
|
||||
<el-dropdown-item v-for="(item, index) in config" :key="index" :command="item.module">
|
||||
{{ item.info.title }}
|
||||
</el-dropdown-item>
|
||||
</el-dropdown-menu>
|
||||
</template>
|
||||
</el-dropdown>
|
||||
</section>
|
||||
</el-header>
|
||||
<el-main class="pi-main nopadding" ref="mainRef">
|
||||
<section>
|
||||
<div class="title-panel">
|
||||
<span class="title">{{ data.summary }}</span>
|
||||
<el-dropdown @command="switchServer" style="padding-left: 10px;">
|
||||
<span class="el-dropdown-link">
|
||||
<el-tag style="display: flex;align-content: center;">
|
||||
{{ server.description }}
|
||||
<el-icon class="el-icon--right"><component
|
||||
:is="'el-icon-arrow-down'"/></el-icon>
|
||||
</el-tag>
|
||||
</span>
|
||||
<template #dropdown>
|
||||
<el-dropdown-menu>
|
||||
<el-dropdown-item v-for="(item, index) in project.json.servers" :key="index"
|
||||
:command="item.url">
|
||||
{{ item.description }}
|
||||
</el-dropdown-item>
|
||||
</el-dropdown-menu>
|
||||
</template>
|
||||
</el-dropdown>
|
||||
</div>
|
||||
<div class="url-panel">
|
||||
<el-tag v-if="data.method==='GET'" type="success">GET</el-tag>
|
||||
<el-tag v-else-if="data.method==='POST'" type="warning">POST</el-tag>
|
||||
<el-tag v-else-if="data.method==='PUT'" type="primary">PUT</el-tag>
|
||||
<el-tag v-else-if="data.method==='DELETE'" type="danger">DELETE</el-tag>
|
||||
<el-tag v-else type="warning">{{data.method}}</el-tag>
|
||||
<el-link v-copy="server.url+data.path">{{server.url}}{{data.path}}</el-link>
|
||||
</div>
|
||||
</section>
|
||||
<section v-if="data.method === 'GET'">
|
||||
|
||||
</section>
|
||||
<section>
|
||||
|
||||
</section>
|
||||
</el-main>
|
||||
</el-container>
|
||||
</el-container>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import {ref, onMounted} from "vue";
|
||||
import {parseSwagger} from "./jsonParse";
|
||||
import PiTable from "@/components/piTable/index.vue";
|
||||
|
||||
const props = defineProps({
|
||||
config: {type: Array, required: true}
|
||||
})
|
||||
const apiRef = ref(null)
|
||||
let project = ref({module: '', info: '', json: ''})
|
||||
let server = ref({description: '', url: ''})
|
||||
let apis = ref([])
|
||||
let data = ref({})
|
||||
|
||||
onMounted(() => {
|
||||
project.value = props.config[0]
|
||||
server.value = project.value.json.servers[0]
|
||||
const result = parseSwagger(project.value.json)
|
||||
apis.value = result[0]
|
||||
data.value = result[1]
|
||||
console.log(data.value)
|
||||
})
|
||||
|
||||
function switchProject(cmd) {
|
||||
if (cmd === project.value.module) return;
|
||||
props.config.forEach(item => {
|
||||
if (item.module === cmd) {
|
||||
project.value = item
|
||||
}
|
||||
})
|
||||
server.value = project.value.json.servers[0]
|
||||
const result = parseSwagger(project.value.json)
|
||||
apis.value = result[0]
|
||||
data.value = result[1]
|
||||
}
|
||||
|
||||
function switchServer(cmd) {
|
||||
if (cmd === server.value.url) return;
|
||||
project.value.json.servers.forEach(item => {
|
||||
if (item.url === cmd) {
|
||||
server.value = item
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const saveJsonFile = () => {
|
||||
// 将对象转成字符串
|
||||
const jsonStr = JSON.stringify(project.value.json, null, 2)
|
||||
// 创建 Blob 对象
|
||||
const blob = new Blob([jsonStr], {type: 'application/json'})
|
||||
// 创建下载链接
|
||||
const url = URL.createObjectURL(blob)
|
||||
// 创建隐藏的 a 标签
|
||||
const a = document.createElement('a')
|
||||
a.href = url
|
||||
a.download = project.value.info.title + ".json"
|
||||
a.click()
|
||||
// 释放内存
|
||||
URL.revokeObjectURL(url)
|
||||
}
|
||||
|
||||
function apiClick(row) {
|
||||
if (!row.path) return;
|
||||
data.value = row
|
||||
console.log(data.value)
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.el-dropdown-link {
|
||||
color: unset;
|
||||
align-content: center;
|
||||
}
|
||||
|
||||
.custom-tree-node {
|
||||
display: flex;
|
||||
flex: 1;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
font-size: 14px;
|
||||
padding-right: 24px;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.custom-tree-node .label {
|
||||
display: flex;
|
||||
align-items: center;;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.custom-tree-node .do i {
|
||||
margin-left: 5px;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.custom-tree-node .do i:hover {
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.custom-tree-node:hover .do {
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
:deep(.el-tree-node__content) {
|
||||
height: 32px;
|
||||
}
|
||||
|
||||
.pi-main {
|
||||
padding: 20px;
|
||||
.title-panel {
|
||||
display: flex;
|
||||
align-content: center;
|
||||
padding-bottom: 20px;
|
||||
.title {
|
||||
font-size: 32px;
|
||||
font-weight: bold;
|
||||
}
|
||||
}
|
||||
|
||||
.url-panel {
|
||||
background: #F9FAFB;
|
||||
padding: 10px 18px;
|
||||
a {
|
||||
margin-left: 10px;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
</style>
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
export function parseSwagger(swaggerJson) {
|
||||
const result: any[] = []
|
||||
let first: Object = {}
|
||||
for (const [path, methods] of Object.entries(swaggerJson.paths)) {
|
||||
for (const [method, api] of Object.entries(methods)) {
|
||||
let currentLevel = result
|
||||
api.tags.forEach((level, index) => {
|
||||
let node = currentLevel.find(item => item.name === level)
|
||||
if (!node) {
|
||||
node = { name: level, children: []}
|
||||
currentLevel.push(node)
|
||||
}
|
||||
if (index === api.tags.length - 1) {
|
||||
node.children.push({
|
||||
path,
|
||||
method: method.toUpperCase(),
|
||||
name: api.summary || '',
|
||||
...api
|
||||
})
|
||||
if (first) {
|
||||
first = {
|
||||
path,
|
||||
method: method.toUpperCase(),
|
||||
name: api.summary || '',
|
||||
...api
|
||||
}
|
||||
}
|
||||
} else {
|
||||
currentLevel = node.children
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
return [result, first]
|
||||
}
|
||||
|
|
@ -5,6 +5,8 @@ export default {
|
|||
API_URL: import.meta.env.VITE_APP_ENV === 'development' ? "/api" : import.meta.env.VITE_API_BASE,
|
||||
// websocket
|
||||
WS_URL: import.meta.env.VITE_WS_URL,
|
||||
// 接口前缀
|
||||
API_PREFIX: '/admin/',
|
||||
//请求超时
|
||||
TIMEOUT: 10000,
|
||||
//请求是否开启缓存
|
||||
|
|
|
|||
|
|
@ -57,9 +57,11 @@ router.beforeEach(async (to, from, next) => {
|
|||
// 动态加载菜单
|
||||
/* @ts-ignore */
|
||||
const res = await api.auth.menu()
|
||||
|
||||
/* @ts-ignore */
|
||||
tools.data.set("MENU", tools.makeMenu(res.data.menus, 0))
|
||||
/* @ts-ignore */
|
||||
tools.data.set("PERMISSIONS", res.data.buttons)
|
||||
/* @ts-ignore */
|
||||
tools.data.set("ROLE", res.data.roles)
|
||||
|
||||
let apiMenu = tools.data.get("MENU") || []
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import tools from '@/utils/tools';
|
|||
import router from '@/router';
|
||||
|
||||
// 请求地址
|
||||
axios.defaults.baseURL = sConfig.API_URL
|
||||
axios.defaults.baseURL = sConfig.API_URL + sConfig.API_PREFIX
|
||||
// 超时时间
|
||||
axios.defaults.timeout = sConfig.TIMEOUT
|
||||
// 请求拦截
|
||||
|
|
|
|||
|
|
@ -0,0 +1,33 @@
|
|||
<template>
|
||||
<div id="api-container">
|
||||
<pi-api-doc-show v-if="visible" :config="configuration"></pi-api-doc-show>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import {ref, onMounted} from "vue";
|
||||
import piApiDocShow from "@/components/piApiDocShow"
|
||||
import api from "@/api/index";
|
||||
|
||||
defineOptions({
|
||||
name: 'toolDoc'
|
||||
})
|
||||
|
||||
const configuration = ref([])
|
||||
let visible = ref(false)
|
||||
|
||||
onMounted(() => {
|
||||
getJson()
|
||||
})
|
||||
|
||||
async function getJson() {
|
||||
const res = await api.system.swagger.list();
|
||||
configuration.value = res.data
|
||||
visible.value = true
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
</style>
|
||||
Loading…
Reference in New Issue