update api docs page

This commit is contained in:
AceDataCloud committed 2023-01-21 00:52:05 +08:00
1 parent f8f34b0084
commit 4b493ac330
14 files changed
+505 -92

No files matched your search

+10 -1
View File
@@ -32,6 +32,15 @@ body {
}
.el-input {
border-radius: 10px;
input {
border-radius: 10px;
}
}
.v-codemirror {
.cm-editor {
border-radius: 10px;
overflow: hidden;
}
}
}
+37
View File
@@ -0,0 +1,37 @@
<template>
<codemirror :model-value="code" :disabled="!editable" :extensions="extensions" />
</template>
<script lang="ts">
import { Codemirror } from 'vue-codemirror';
import { json } from '@codemirror/lang-json';
import { oneDark } from '@codemirror/theme-one-dark';
import { defineComponent } from 'vue';
import { Extension } from '@codemirror/state';
interface IData {
extensions: Extension[];
}
export default defineComponent({
name: 'CodeSnippet',
components: {
Codemirror
},
props: {
code: {
type: String,
required: true
},
editable: {
type: Boolean,
required: false
}
},
data(): IData {
return {
extensions: [json(), oneDark]
};
}
});
</script>
+35 -18
View File
@@ -1,21 +1,19 @@
<template>
<div v-if="schema" class="wrapper">
<div v-for="(item, itemKey) in schema.properties" :key="itemKey">
<div class="item">
<div class="left">
<div class="info">
<span class="key">{{ itemKey }}</span>
<span class="type">{{ item.type }}</span>
<span v-if="!item.optional" class="required">required</span>
</div>
<div class="description">
{{ item.title }}
</div>
<div v-for="(item, itemKey) in schema.properties" :key="itemKey" class="item">
<div class="left">
<div class="info">
<span class="key">{{ itemKey }}</span>
<span class="type">{{ item.type }}</span>
<span v-if="!item.optional" class="required">required</span>
</div>
<div class="right">
<el-input v-model="value[itemKey.toString()]" />
<div class="description">
{{ item.title }}
</div>
</div>
<div class="right">
<el-input v-model="value[itemKey.toString()]" />
</div>
</div>
</div>
</template>
@@ -67,8 +65,6 @@ export default defineComponent({
<style lang="scss" scoped>
.wrapper {
border: 1px solid rgba(0, 0, 0, 0.1);
border-radius: 10px;
overflow: hidden;
.item {
@@ -76,6 +72,25 @@ export default defineComponent({
overflow: hidden;
background-color: rgb(248, 248, 248);
padding: 10px;
border-right: 1px solid rgba(0, 0, 0, 0.1);
border-left: 1px solid rgba(0, 0, 0, 0.1);
&:first-child {
border-top: 1px solid rgba(0, 0, 0, 0.1);
border-top-left-radius: 10px;
border-top-right-radius: 10px;
}
&:not(:first-child):not(:last-child) {
border-top: 1px solid rgba(0, 0, 0, 0.1);
}
&:last-child {
border-top: 1px solid rgba(0, 0, 0, 0.1);
border-bottom: 1px solid rgba(0, 0, 0, 0.1);
border-bottom-left-radius: 10px;
border-bottom-right-radius: 10px;
}
.left {
width: 70%;
@@ -85,18 +100,19 @@ export default defineComponent({
font-size: 14px;
font-weight: bold;
display: inline-block;
padding: 6px;
padding: 3px;
padding-left: 0;
}
.type {
font-size: 14px;
display: inline-block;
padding: 6px;
padding: 3px;
}
.required {
font-size: 12px;
color: #dd1e2e;
display: inline-block;
padding: 6px;
padding: 3px;
}
}
.description {
@@ -107,6 +123,7 @@ export default defineComponent({
.right {
width: 30%;
float: left;
padding-top: 6px;
}
}
}
+7 -5
View File
@@ -1,8 +1,6 @@
<template>
<div class="wrapper">
<div v-if="apis">
<api-list-item v-for="(api, apiIndex) in apis" :key="apiIndex" :api="api"></api-list-item>
</div>
<div v-if="apis" class="wrapper">
<api-list-item v-for="(api, apiIndex) in apis" :key="apiIndex" :api="api"></api-list-item>
</div>
</template>
@@ -51,4 +49,8 @@ export default defineComponent({
});
</script>
<style lang="scss" scoped></style>
<style lang="scss" scoped>
.wrapper {
padding: 20px 0;
}
</style>
+29 -14
View File
@@ -1,15 +1,18 @@
<template>
<div class="item">
<el-link type="primary" class="link" @click="onClick">
<div class="item" @click="onClick">
<el-link type="primary" class="link" :underline="false">
<span class="name">{{ api?.title }}</span>
<span class="request-method">{{ api?.request?.method }}</span>
</el-link>
<el-tag v-if="api?.request?.method" type="primary" class="request-method" effect="dark">
{{ api?.request?.method }}
</el-tag>
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import { IApi } from '@/operators/api/models';
export default defineComponent({
name: 'ApiListItem',
props: {
@@ -31,19 +34,31 @@ export default defineComponent({
});
</script>
<style lang="scss">
.link {
.name {
display: flex;
<style lang="scss" scoped>
$height: 35px;
.item {
height: $height;
line-height: $height;
padding-left: 5px;
cursor: pointer;
border-radius: 5px;
overflow: hidden;
position: relative;
&:hover {
background-color: rgba(0, 0, 0, 0.1);
}
.link {
color: #333;
.name {
display: flex;
}
}
.request-method {
display: flex;
padding-left: 0;
padding-right: 0;
width: 40px;
flex-grow: 0;
flex-shrink: 0;
flex-basis: auto;
position: absolute;
right: 10px;
top: 5px;
}
}
</style>
+123 -40
View File
@@ -1,16 +1,55 @@
<template>
<div v-if="responses" class="wrapper">
<div v-for="(response, responseKey) in responses" :key="responseKey" class="item">
<div>
{{ response }}
<el-collapse v-if="responses" id="document-response-item" class="wrapper" accordion>
<el-collapse-item v-for="(response, responseKey) in responses" :key="responseKey" class="item" :name="responseKey">
<template #title>
<span class="badge">
<el-tag v-if="response.isSuccess" class="ml-2" type="success">{{ $t('api.entity.success') }}</el-tag>
<el-tag v-else class="ml-2" type="danger">{{ $t('api.entity.failure') }}</el-tag>
</span>
<span class="code">
{{ response.statusCode }}
</span>
</template>
<div class="item-body">
<div v-if="response?.headers?.properties" class="headers">
<h2 class="title">{{ $t('api.entity.responseHeaders') }}</h2>
<div v-for="(item, itemKey) in response?.headers?.properties" :key="itemKey">
<div class="property">
<div class="info">
<span class="key">{{ itemKey }}</span>
<span class="type">{{ item.type }}</span>
</div>
<div class="description">
{{ item.title }}
</div>
</div>
</div>
</div>
<div v-if="response?.body?.properties" class="body">
<h2 class="title">{{ $t('api.entity.responseBody') }}</h2>
<div v-for="(item, itemKey) in response?.body?.properties" :key="itemKey" class="property">
<div class="info">
<span class="key">{{ itemKey }}</span>
<span class="type">{{ item.type }}</span>
</div>
<div class="description">
{{ item.title }}
</div>
</div>
</div>
<div v-if="response?.example" class="example">
<h2 class="title">{{ $t('api.entity.responseExample') }}</h2>
<code-snippet :code="response?.example" />
</div>
</div>
</div>
</div>
</el-collapse-item>
</el-collapse>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import { IResponse, ISchema } from '@/operators/api/models';
import { IResponse } from '@/operators/api/models';
import CodeSnippet from '../common/CodeSnippet.vue';
interface IData {
value: {
@@ -20,6 +59,9 @@ interface IData {
export default defineComponent({
name: 'ApiResult',
components: {
CodeSnippet
},
props: {
responses: {
type: Object as () => IResponse[] | [],
@@ -39,47 +81,88 @@ export default defineComponent({
<style lang="scss" scoped>
.wrapper {
border: 1px solid rgba(0, 0, 0, 0.1);
border-radius: 10px;
overflow: hidden;
border: none;
.item {
display: block;
overflow: hidden;
background-color: rgb(248, 248, 248);
padding: 10px;
background-color: #f8f8f8;
border-right: 1px solid rgba(0, 0, 0, 0.1);
border-left: 1px solid rgba(0, 0, 0, 0.1);
.left {
width: 70%;
float: left;
.info {
.key {
font-size: 14px;
font-weight: bold;
display: inline-block;
padding: 6px;
}
.type {
font-size: 14px;
display: inline-block;
padding: 6px;
}
.required {
font-size: 12px;
color: #dd1e2e;
display: inline-block;
padding: 6px;
}
}
.description {
font-size: 12px;
color: #666;
}
&.el-collapse-item:last-child {
margin-bottom: 0;
}
.right {
width: 30%;
float: left;
&:first-child {
border-top: 1px solid rgba(0, 0, 0, 0.1);
border-top-left-radius: 10px;
border-top-right-radius: 10px;
}
&:not(:first-child):not(:last-child) {
border-top: 1px solid rgba(0, 0, 0, 0.1);
}
&:last-child {
border-top: 1px solid rgba(0, 0, 0, 0.1);
border-bottom: 1px solid rgba(0, 0, 0, 0.1);
border-bottom-left-radius: 10px;
border-bottom-right-radius: 10px;
}
.item-body {
padding: 15px;
.body,
.headers {
.property {
padding: 10px;
border-right: 1px solid rgba(0, 0, 0, 0.1);
border-left: 1px solid rgba(0, 0, 0, 0.1);
&:first-of-type {
border-top: 1px solid rgba(0, 0, 0, 0.1);
border-top-left-radius: 10px;
border-top-right-radius: 10px;
}
&:not(:first-of-type):not(:last-of-type) {
border-top: 1px solid rgba(0, 0, 0, 0.1);
}
&:last-of-type {
border-top: 1px solid rgba(0, 0, 0, 0.1);
border-bottom: 1px solid rgba(0, 0, 0, 0.1);
border-bottom-left-radius: 10px;
border-bottom-right-radius: 10px;
}
.info {
.key {
font-size: 14px;
font-weight: bold;
display: inline-block;
padding: 3px;
padding-left: 0;
}
.type {
font-size: 14px;
display: inline-block;
padding: 3px;
}
}
}
}
}
}
}
</style>
<style lang="scss">
#document-response-item {
.el-collapse-item__header {
border: none;
background: none;
}
}
</style>
+64 -11
View File
@@ -4,26 +4,27 @@
{{ api?.title }}
</div>
<div class="url">
<el-button size="mini">{{ api?.request?.method }}</el-button>
<span>{{ api?.endpoint }}{{ api?.path }}</span>
<el-tag class="method" size="mini" type="primary" effect="dark">{{ api?.request?.method }}</el-tag>
<span v-if="api?.endpoint && api?.path" class="endpoint">{{ urlJoin(api?.endpoint, api?.path) }}</span>
</div>
<div class="description">
<p>{{ api?.description }}</p>
<div class="introduction">
<p>{{ api?.introduction }}</p>
</div>
<el-divider />
<div class="queries">
<h2>Queries</h2>
<h2 class="title">{{ $t('api.entity.requestQueries') }}</h2>
<api-form :schema="api?.request.queries" />
</div>
<div class="headers">
<h2>Headers</h2>
<h2 class="title">{{ $t('api.entity.requestHeaders') }}</h2>
<api-form :schema="api?.request.headers" />
</div>
<div class="body">
<h2>Body</h2>
<h2 class="title">{{ $t('api.entity.requestBody') }}</h2>
<api-form :schema="api?.request.body" />
</div>
<div class="responses">
<h2>Responses</h2>
<div v-if="api?.responses" class="responses">
<h2 class="title">{{ $t('api.entity.response') }}</h2>
<api-result :responses="api?.responses" />
</div>
</div>
@@ -35,6 +36,7 @@ import { IApi, IApiDetailResponse } from '@/operators/api/models';
import { apiOperator } from '@/operators/api/operator';
import ApiForm from './ApiForm.vue';
import ApiResult from './ApiResult.vue';
import urlJoin from 'url-join';
export interface IData {
api: IApi | undefined;
@@ -70,6 +72,7 @@ export default defineComponent({
this.getApi(this.id);
},
methods: {
urlJoin,
getApi(id: string) {
this.loading = true;
apiOperator
@@ -91,9 +94,59 @@ export default defineComponent({
<style lang="scss">
.item {
.title {
font-size: 1.9em;
font-weight: var(--markdown-title-weight);
font-size: 26px;
font-weight: 500;
line-height: 1.2;
margin-bottom: 10px;
}
.url {
margin-bottom: 10px;
.method {
border-radius: 10px;
padding: 1px 8px;
font-size: 10px;
transform: scale(0.8);
}
.endpoint {
font-size: 12px;
}
}
.introduction {
font-size: 16px;
font-weight: bold;
margin-bottom: 10px;
}
.queries {
margin-bottom: 10px;
.title {
font-size: 12px;
margin-bottom: 10px;
}
}
.headers {
margin-bottom: 10px;
.title {
font-size: 12px;
margin-bottom: 10px;
}
}
.body {
margin-bottom: 10px;
.title {
font-size: 12px;
margin-bottom: 10px;
}
}
.responses {
margin-bottom: 10px;
.title {
font-size: 12px;
margin-bottom: 10px;
}
}
}
</style>
+11
View File
@@ -0,0 +1,11 @@
export default {
requestQueries: 'URL参数',
requestBody: '请求体',
responseBody: '响应体',
requestHeaders: '请求头',
responseHeaders: '响应头',
response: '响应',
success: '成功',
failure: '失败',
responseExample: '样例'
};
+5
View File
@@ -0,0 +1,5 @@
import entity from './entity';
export default {
entity
};
+3 -1
View File
@@ -4,6 +4,7 @@ import course from './course/index';
import service from './service/index';
import console from './console/index';
import application from './application';
import api from './api';
export default {
common,
@@ -11,5 +12,6 @@ export default {
course,
service,
console,
application
application,
api
};
+2 -1
View File
@@ -23,6 +23,7 @@ export interface IResponse {
example?: string;
isSuccess: boolean;
errorCode?: string;
statusCode: number;
body: ISchema;
headers: ISchema;
}
@@ -33,7 +34,7 @@ export interface IApi {
endpoint: string;
alias: string;
title?: string;
description?: string;
introduction?: string;
tags?: string[];
request: IRequest;
responses: IResponse[];
-1
View File
@@ -36,7 +36,6 @@ export default defineComponent({
<style lang="scss" scoped>
.wrapper {
width: 100%;
height: 100vh;
overflow: hidden;
.left {