update api view
This commit is contained in:
1 parent
2b32240fe0
commit
f8f34b0084
9 files changed
+326
-56
No files matched your search
@@ -30,4 +30,8 @@ body {
|
||||
.el-button {
|
||||
border-radius: 9999px;
|
||||
}
|
||||
|
||||
.el-input {
|
||||
border-radius: 10px;
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@
|
||||
<el-col :span="20">
|
||||
<el-menu :default-active="active" class="el-menu-demo" mode="horizontal" @select="onSelect">
|
||||
<el-menu-item v-t="'common.nav.service'" index="/services"></el-menu-item>
|
||||
<!-- <el-menu-item v-t="'common.nav.category'" index="/categories"></el-menu-item> -->
|
||||
<el-menu-item v-t="'common.nav.document'" index="/documents"></el-menu-item>
|
||||
</el-menu>
|
||||
</el-col>
|
||||
<el-col :span="4">
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
<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>
|
||||
<div class="right">
|
||||
<el-input v-model="value[itemKey.toString()]" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent } from 'vue';
|
||||
import { ISchema } from '@/operators/api/models';
|
||||
|
||||
interface IData {
|
||||
value: {
|
||||
[key: string]: string | number;
|
||||
};
|
||||
}
|
||||
|
||||
export default defineComponent({
|
||||
name: 'ApiForm',
|
||||
props: {
|
||||
schema: {
|
||||
type: Object as () => ISchema | undefined,
|
||||
required: true
|
||||
}
|
||||
},
|
||||
emits: ['change'],
|
||||
data(): IData {
|
||||
return {
|
||||
value: {}
|
||||
};
|
||||
},
|
||||
watch: {
|
||||
value: {
|
||||
handler() {
|
||||
console.log('change', this.value);
|
||||
this.$emit('change', { ...this.value });
|
||||
},
|
||||
deep: true
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
onChange(key: string, val: string) {
|
||||
console.log('key', key, val);
|
||||
this.value[key] = val;
|
||||
this.$emit('change', {
|
||||
...this.value
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.wrapper {
|
||||
border: 1px solid rgba(0, 0, 0, 0.1);
|
||||
border-radius: 10px;
|
||||
overflow: hidden;
|
||||
|
||||
.item {
|
||||
display: block;
|
||||
overflow: hidden;
|
||||
background-color: rgb(248, 248, 248);
|
||||
padding: 10px;
|
||||
|
||||
.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;
|
||||
}
|
||||
}
|
||||
.right {
|
||||
width: 30%;
|
||||
float: left;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -1,8 +1,8 @@
|
||||
<template>
|
||||
<div class="item">
|
||||
<el-link type="primary" class="link" @click="onClick">
|
||||
<span class="name">{{ api.title }}</span>
|
||||
<span class="request-method">{{ api.requestMethod }}</span>
|
||||
<span class="name">{{ api?.title }}</span>
|
||||
<span class="request-method">{{ api?.request?.method }}</span>
|
||||
</el-link>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
<template>
|
||||
<div v-if="responses" class="wrapper">
|
||||
<div v-for="(response, responseKey) in responses" :key="responseKey" class="item">
|
||||
<div>
|
||||
{{ response }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent } from 'vue';
|
||||
import { IResponse, ISchema } from '@/operators/api/models';
|
||||
|
||||
interface IData {
|
||||
value: {
|
||||
[key: string]: string | number;
|
||||
};
|
||||
}
|
||||
|
||||
export default defineComponent({
|
||||
name: 'ApiResult',
|
||||
props: {
|
||||
responses: {
|
||||
type: Object as () => IResponse[] | [],
|
||||
required: true
|
||||
}
|
||||
},
|
||||
// emits: ['change'],
|
||||
data(): IData {
|
||||
return {
|
||||
value: {}
|
||||
};
|
||||
},
|
||||
watch: {},
|
||||
methods: {}
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.wrapper {
|
||||
border: 1px solid rgba(0, 0, 0, 0.1);
|
||||
border-radius: 10px;
|
||||
overflow: hidden;
|
||||
|
||||
.item {
|
||||
display: block;
|
||||
overflow: hidden;
|
||||
background-color: rgb(248, 248, 248);
|
||||
padding: 10px;
|
||||
|
||||
.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;
|
||||
}
|
||||
}
|
||||
.right {
|
||||
width: 30%;
|
||||
float: left;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -1,49 +1,99 @@
|
||||
<template>
|
||||
<div class="item">
|
||||
<el-link type="primary" class="link" @click="onClick">
|
||||
<span class="name">{{ api.title }}</span>
|
||||
<span class="request-method">{{ api.requestMethod }}</span>
|
||||
</el-link>
|
||||
<div class="title">
|
||||
{{ api?.title }}
|
||||
</div>
|
||||
<div class="url">
|
||||
<el-button size="mini">{{ api?.request?.method }}</el-button>
|
||||
<span>{{ api?.endpoint }}{{ api?.path }}</span>
|
||||
</div>
|
||||
<div class="description">
|
||||
<p>{{ api?.description }}</p>
|
||||
</div>
|
||||
<div class="queries">
|
||||
<h2>Queries</h2>
|
||||
<api-form :schema="api?.request.queries" />
|
||||
</div>
|
||||
<div class="headers">
|
||||
<h2>Headers</h2>
|
||||
<api-form :schema="api?.request.headers" />
|
||||
</div>
|
||||
<div class="body">
|
||||
<h2>Body</h2>
|
||||
<api-form :schema="api?.request.body" />
|
||||
</div>
|
||||
<div class="responses">
|
||||
<h2>Responses</h2>
|
||||
<api-result :responses="api?.responses" />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent } from 'vue';
|
||||
import { IApi } from '@/operators/api/models';
|
||||
import { IApi, IApiDetailResponse } from '@/operators/api/models';
|
||||
import { apiOperator } from '@/operators/api/operator';
|
||||
import ApiForm from './ApiForm.vue';
|
||||
import ApiResult from './ApiResult.vue';
|
||||
|
||||
export interface IData {
|
||||
api: IApi | undefined;
|
||||
loading: boolean;
|
||||
}
|
||||
|
||||
export default defineComponent({
|
||||
name: 'ApiListItem',
|
||||
name: 'ApiUsage',
|
||||
components: {
|
||||
ApiForm,
|
||||
ApiResult
|
||||
},
|
||||
props: {
|
||||
api: {
|
||||
type: Object as () => IApi,
|
||||
id: {
|
||||
type: String,
|
||||
required: true
|
||||
}
|
||||
},
|
||||
data(): IData {
|
||||
return {
|
||||
api: undefined,
|
||||
loading: false
|
||||
};
|
||||
},
|
||||
watch: {
|
||||
id: {
|
||||
handler() {
|
||||
this.getApi(this.id);
|
||||
}
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.getApi(this.id);
|
||||
},
|
||||
methods: {
|
||||
onClick() {
|
||||
this.$router.push({
|
||||
name: 'document-detail',
|
||||
params: {
|
||||
id: this.api.id
|
||||
}
|
||||
});
|
||||
getApi(id: string) {
|
||||
this.loading = true;
|
||||
apiOperator
|
||||
.get(id)
|
||||
.then(({ data: data }: { data: IApiDetailResponse }) => {
|
||||
this.loading = false;
|
||||
this.api = data;
|
||||
console.log('api', this.api);
|
||||
})
|
||||
.catch((error) => {
|
||||
this.loading = false;
|
||||
console.error(error);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
.link {
|
||||
.name {
|
||||
display: flex;
|
||||
}
|
||||
.request-method {
|
||||
display: flex;
|
||||
padding-left: 0;
|
||||
padding-right: 0;
|
||||
width: 40px;
|
||||
flex-grow: 0;
|
||||
flex-shrink: 0;
|
||||
flex-basis: auto;
|
||||
.item {
|
||||
.title {
|
||||
font-size: 1.9em;
|
||||
font-weight: var(--markdown-title-weight);
|
||||
line-height: 1.2;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -7,5 +7,6 @@ export default {
|
||||
publication: '发布',
|
||||
course: '课程',
|
||||
category: '分类',
|
||||
service: '服务'
|
||||
service: '服务',
|
||||
document: '文档'
|
||||
};
|
||||
@@ -1,13 +1,43 @@
|
||||
export interface ISchema {
|
||||
properties: {
|
||||
[key: string]: ISchema;
|
||||
};
|
||||
type: 'object' | 'array' | 'string' | 'number';
|
||||
title: string;
|
||||
optional: boolean;
|
||||
}
|
||||
|
||||
export interface IRequest {
|
||||
id: string;
|
||||
body: ISchema;
|
||||
headers: ISchema;
|
||||
queries: ISchema;
|
||||
params: ISchema;
|
||||
method: 'GET' | 'POST' | 'HEAD' | 'PUT' | 'DELETE' | 'CONNECT' | 'OPTIONS' | 'TRACE' | 'PATCH';
|
||||
}
|
||||
|
||||
export interface IResponse {
|
||||
id: string;
|
||||
title: string;
|
||||
description?: string;
|
||||
example?: string;
|
||||
isSuccess: boolean;
|
||||
errorCode?: string;
|
||||
body: ISchema;
|
||||
headers: ISchema;
|
||||
}
|
||||
|
||||
export interface IApi {
|
||||
id: string;
|
||||
path: string;
|
||||
endpoint: string;
|
||||
alias: string;
|
||||
title?: string;
|
||||
description?: string;
|
||||
tags?: string[];
|
||||
endpoint?: string;
|
||||
request: IRequest;
|
||||
responses: IResponse[];
|
||||
isFree?: boolean;
|
||||
requestMethod?: boolean;
|
||||
swaggerConfiguration?: string;
|
||||
service?: string;
|
||||
createdAt?: string;
|
||||
updatedAt?: string;
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<api-list />
|
||||
</div>
|
||||
<div class="main">
|
||||
<api-usage v-if="api" :api="api" />
|
||||
<api-usage :id="id" />
|
||||
</div>
|
||||
<div class="right"></div>
|
||||
</el-col>
|
||||
@@ -19,33 +19,17 @@ import ApiUsage from '@/components/document/ApiUsage.vue';
|
||||
import { apiOperator } from '@/operators/api/operator';
|
||||
import { IApi, IApiDetailResponse } from '@/operators/api/models';
|
||||
|
||||
export interface IData {
|
||||
api: IApi | undefined;
|
||||
}
|
||||
|
||||
export default defineComponent({
|
||||
components: {
|
||||
ApiList,
|
||||
ApiUsage
|
||||
},
|
||||
data(): IData {
|
||||
return {
|
||||
api: undefined
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
getApi(id: string) {
|
||||
apiOperator
|
||||
.get(id)
|
||||
.then(({ data: data }: { data: IApiDetailResponse }) => {
|
||||
this.api = data;
|
||||
console.log('api', this.api);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(error);
|
||||
});
|
||||
computed: {
|
||||
id() {
|
||||
return this.$route.params.id.toString();
|
||||
}
|
||||
}
|
||||
},
|
||||
methods: {}
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -59,18 +43,21 @@ export default defineComponent({
|
||||
float: left;
|
||||
width: 280px;
|
||||
height: 100%;
|
||||
box-shadow: 1px 0 0 #eee;
|
||||
}
|
||||
|
||||
.main {
|
||||
float: left;
|
||||
width: calc(100% - 760px);
|
||||
height: 100%;
|
||||
padding: 30px;
|
||||
}
|
||||
|
||||
.right {
|
||||
float: left;
|
||||
width: 480px;
|
||||
height: 100%;
|
||||
box-shadow: -1px 0 0 #eee;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
Reference in new issue
Block a user