update document integration

This commit is contained in:
AceDataCloud committed 2023-01-22 15:57:26 +08:00
1 parent c7fdcd0a4b
commit 798de13a35
14 files changed
+209 -151

No files matched your search

-134
View File
@@ -1,134 +0,0 @@
<template>
<div v-if="schema" class="wrapper">
<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="description">
{{ item?.title }}
</div>
</div>
<div class="right">
<el-select
v-if="item?.enum"
v-model="value[itemKey?.toString()]"
clearable
:placeholder="$t('common.title.select')"
>
<el-option v-for="e in item?.enum" :key="e" :label="e" :value="e" />
</el-select>
<el-input v-else v-model="value[itemKey?.toString()]" />
</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: ['update:form'],
data(): IData {
return {
value: {}
};
},
watch: {
value: {
handler() {
this.$emit('update:form', { ...this.value });
},
deep: true
}
},
methods: {
onChange(key: string, val: string) {
console.log('key', key, val);
this.value[key] = val;
}
}
});
</script>
<style lang="scss" scoped>
.wrapper {
overflow: hidden;
.item {
display: block;
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%;
float: left;
.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;
}
.required {
font-size: 12px;
color: #dd1e2e;
display: inline-block;
padding: 3px;
}
}
.description {
font-size: 12px;
color: #666;
}
}
.right {
width: 30%;
float: left;
padding-top: 6px;
}
}
}
</style>
-55
View File
@@ -1,55 +0,0 @@
<template>
<div v-if="apis" class="wrapper">
<api-list-item v-for="(api, apiIndex) in apis" :key="apiIndex" :api="api"></api-list-item>
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import { IApi, IApiListResponse } from '@/operators/api/models';
import { apiOperator } from '@/operators/api/operator';
import ApiListItem from './ApiListItem.vue';
interface IData {
apis: IApi[];
limit: number;
offset: number;
}
export default defineComponent({
name: 'ApiList',
components: {
ApiListItem
},
data(): IData {
return {
apis: [],
limit: 20,
offset: 0
};
},
mounted() {
this.getApis(this.offset, this.limit);
},
methods: {
getApis(offset: number, limit: number) {
apiOperator
.getAll({
offset,
limit
})
.then(({ data: data }: { data: IApiListResponse }) => {
this.apis = data.items;
})
.catch((error) => {
console.error(error);
});
}
}
});
</script>
<style lang="scss" scoped>
.wrapper {
padding: 20px 0;
}
</style>
-176
View File
@@ -1,176 +0,0 @@
<template>
<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?.is_success" 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="status-code">
{{ response?.status_code }}
</span>
<span class="error-code">
{{ response?.error_code }}
</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>
</el-collapse-item>
</el-collapse>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import { IResponse } from '@/operators/api/models';
import CodeSnippet from '../common/CodeSnippet.vue';
interface IData {
value: {
[key: string]: string | number;
};
}
export default defineComponent({
name: 'ApiResult',
components: {
CodeSnippet
},
props: {
responses: {
type: Object as () => IResponse[] | [],
required: true
}
},
// emits: ['change'],
data(): IData {
return {
value: {}
};
},
watch: {},
methods: {}
});
</script>
<style lang="scss" scoped>
.wrapper {
overflow: hidden;
border: none;
.item {
display: block;
overflow: hidden;
background-color: #f8f8f8;
border-right: 1px solid rgba(0, 0, 0, 0.1);
border-left: 1px solid rgba(0, 0, 0, 0.1);
.status-code,
.error-code {
display: inline-block;
padding-left: 5px;
}
&.el-collapse-item:last-child {
margin-bottom: 0;
}
&: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>
-80
View File
@@ -1,80 +0,0 @@
<template>
<div class="wrapper">
<div class="operation">
<el-button class="btn-try" type="primary" @click="onTry">{{ $t('common.button.try') }}</el-button>
</div>
<div v-if="responseData" class="result">
<div class="title">{{ $t('api.entity.response') }}</div>
<code-snippet :code="responseData" />
</div>
</div>
</template>
<script lang="ts">
import { IApi, IForm } from '@/operators/api/models';
import { defineComponent } from 'vue';
import axios, { Method } from 'axios';
import urlJoin from 'url-join';
import CodeSnippet from '../common/CodeSnippet.vue';
export default defineComponent({
name: 'ApiTry',
components: {
CodeSnippet
},
props: {
api: {
type: Object as () => IApi,
required: true
},
form: {
type: Object as () => IForm,
required: true
}
},
data() {
return {
apiKeyValue: this.apiKey,
responseData: ''
};
},
methods: {
onTry() {
const config = {
method: this.api?.request?.method as Method,
url: urlJoin(this.api?.endpoint, this.api?.path),
params: { ...this.form.queries },
data: { ...this.form.body }
};
console.debug('config of testing', config);
axios(config)
.then((response) => {
this.responseData = JSON.stringify(response?.data, null, ' ');
})
.catch((error) => {
this.responseData = JSON.stringify(error?.response?.data, null, ' ');
});
}
}
});
</script>
<style lang="scss" scoped>
.wrapper {
padding: 15px;
.operation {
margin-bottom: 10px;
.btn-try {
width: 100%;
}
}
.result {
margin-bottom: 10px;
.title {
font-size: 12px;
margin-bottom: 10px;
}
}
}
</style>
-147
View File
@@ -1,147 +0,0 @@
<template>
<div v-if="loading">
<el-skeleton />
<el-divider />
<el-skeleton />
</div>
<div v-else class="item">
<div class="title">
{{ api?.title }}
</div>
<div class="url">
<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="introduction">
<p>{{ api?.introduction }}</p>
</div>
<el-divider />
<div class="queries">
<h2 class="title">{{ $t('api.entity.requestQueries') }}</h2>
<api-form v-model:form="formValue.queries" :schema="api?.request?.queries" />
</div>
<div class="headers">
<h2 class="title">{{ $t('api.entity.requestHeaders') }}</h2>
<api-form v-model:form="formValue.headers" :schema="api?.request?.headers" />
</div>
<div class="body">
<h2 class="title">{{ $t('api.entity.requestBody') }}</h2>
<api-form v-model:form="formValue.body" :schema="api?.request?.body" />
</div>
<div v-if="api?.responses" class="responses">
<h2 class="title">{{ $t('api.entity.response') }}</h2>
<api-result :responses="api?.responses" />
</div>
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import { IApi, IApiDetailResponse, IForm } from '@/operators/api/models';
import ApiForm from './ApiForm.vue';
import ApiResult from './ApiResult.vue';
import urlJoin from 'url-join';
export interface IData {
formValue: IForm | undefined;
}
export default defineComponent({
name: 'ApiUsage',
components: {
ApiForm,
ApiResult
},
props: {
api: {
type: Object as () => IApi,
required: true
},
loading: {
type: Boolean,
required: true
},
form: {
type: Object as () => IForm,
required: true
}
},
emits: ['update:form'],
data() {
return {
formValue: this.form
};
},
watch: {
formValue: {
handler(val) {
this.$emit('update:form', { ...val });
},
deep: true
}
},
methods: {
urlJoin
}
});
</script>
<style lang="scss">
.item {
.title {
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>
+61
View File
@@ -0,0 +1,61 @@
<template>
<div v-if="documents" class="wrapper">
<document-list-item
v-for="(document, documentIndex) in documents"
:key="documentIndex"
:document="document"
></document-list-item>
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import { IDocument, IDocumentListResponse } from '@/operators/document/models';
import DocumentListItem from './ListItem.vue';
import { documentOperator } from '@/operators/document';
interface IData {
documents: IDocument[];
limit: number;
offset: number;
}
export default defineComponent({
name: 'DocumentList',
components: {
DocumentListItem
},
data(): IData {
return {
documents: [],
limit: 20,
offset: 0
};
},
computed: {},
mounted() {
this.getDocuments(this.offset, this.limit);
},
methods: {
getDocuments(offset: number, limit: number) {
documentOperator
.getAll({
offset,
limit
})
.then(({ data: data }: { data: IDocumentListResponse }) => {
this.documents = data.items;
})
.catch((error) => {
console.error(error);
});
}
}
});
</script>
<style lang="scss" scoped>
.wrapper {
padding: 20px 0;
}
</style>
@@ -1,10 +1,15 @@
<template>
<div class="item" @click="onClick">
<div v-if="document.type === 'TEXT'" class="item" @click="onClick">
<el-link type="primary" class="link" :underline="false">
<span class="name">{{ api?.title }}</span>
<span class="name">{{ document?.title }}</span>
</el-link>
<el-tag v-if="api?.request?.method" type="primary" class="request-method" effect="dark">
{{ api?.request?.method }}
</div>
<div v-else-if="document.type === 'API'" class="item" @click="onClick">
<el-link type="primary" class="link" :underline="false">
<span class="name">{{ document?.api?.title }}</span>
</el-link>
<el-tag v-if="document?.api?.request?.method" type="primary" class="request-method" effect="dark">
{{ document?.api?.request?.method }}
</el-tag>
</div>
</template>
@@ -12,12 +17,13 @@
<script lang="ts">
import { defineComponent } from 'vue';
import { IApi } from '@/operators/api/models';
import { IDocument } from '@/operators/document/models';
export default defineComponent({
name: 'ApiListItem',
props: {
api: {
type: Object as () => IApi,
document: {
type: Object as () => IDocument,
required: true
}
},
@@ -26,7 +32,7 @@ export default defineComponent({
this.$router.push({
name: 'document-detail',
params: {
id: this.api.id
id: this.document.id
}
});
}