update document integration
This commit is contained in:
1 parent
c7fdcd0a4b
commit
798de13a35
14 files changed
+209
-151
No files matched your search
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -38,8 +38,8 @@
|
||||
<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 ApiForm from './Form.vue';
|
||||
import ApiResult from './Result.vue';
|
||||
import urlJoin from 'url-join';
|
||||
|
||||
export interface IData {
|
||||
@@ -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>
|
||||
@@ -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
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -3,7 +3,16 @@
|
||||
<el-header class="header">
|
||||
<top-header />
|
||||
</el-header>
|
||||
<el-main class="main"> <router-view /> </el-main>
|
||||
<el-main class="main">
|
||||
<el-row>
|
||||
<el-col :span="22" :offset="1">
|
||||
<div class="left">
|
||||
<document-list />
|
||||
</div>
|
||||
<router-view />
|
||||
</el-col>
|
||||
</el-row>
|
||||
</el-main>
|
||||
<el-footer class="footer">
|
||||
<bottom-footer />
|
||||
</el-footer>
|
||||
@@ -13,11 +22,14 @@
|
||||
<script lang="ts">
|
||||
import { TopHeader } from '@/components/common/index';
|
||||
import BottomFooter from '@/components/common/BottomFooter.vue';
|
||||
import DocumentList from '@/components/document/List.vue';
|
||||
|
||||
export default {
|
||||
name: 'LayoutCourse',
|
||||
components: {
|
||||
TopHeader,
|
||||
BottomFooter
|
||||
BottomFooter,
|
||||
DocumentList
|
||||
}
|
||||
};
|
||||
</script>
|
||||
@@ -30,4 +42,13 @@ export default {
|
||||
.header {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.main {
|
||||
.left {
|
||||
float: left;
|
||||
width: 280px;
|
||||
height: 100%;
|
||||
box-shadow: 1px 0 0 #eee;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from './models';
|
||||
export * from './operator';
|
||||
@@ -0,0 +1,20 @@
|
||||
import { IApi } from '../api/models';
|
||||
|
||||
export interface IDocument {
|
||||
id?: string;
|
||||
name?: string;
|
||||
type: 'API' | 'TEXT';
|
||||
title?: string;
|
||||
content?: string;
|
||||
rank?: number;
|
||||
api?: IApi;
|
||||
created_at?: string;
|
||||
updated_at?: string;
|
||||
}
|
||||
|
||||
export interface IDocumentListResponse {
|
||||
count: number;
|
||||
items: IDocument[];
|
||||
}
|
||||
|
||||
export type IDocumentDetailResponse = IDocument;
|
||||
@@ -0,0 +1,36 @@
|
||||
import { AxiosResponse } from 'axios';
|
||||
import { httpClient } from '../instance';
|
||||
import { IDocument, IDocumentDetailResponse, IDocumentListResponse } from './models';
|
||||
|
||||
export interface IDocumentQuery {
|
||||
limit: number;
|
||||
offset: number;
|
||||
}
|
||||
|
||||
class DocumentOperator {
|
||||
key = 'documents';
|
||||
|
||||
async getAll(query: IDocumentQuery): Promise<AxiosResponse<IDocumentListResponse>> {
|
||||
return await httpClient.get(`/${this.key}/`, {
|
||||
params: query
|
||||
});
|
||||
}
|
||||
|
||||
async get(id: string): Promise<AxiosResponse<IDocumentDetailResponse>> {
|
||||
return await httpClient.get(`/${this.key}/${id}`);
|
||||
}
|
||||
|
||||
async create(data: IDocument): Promise<AxiosResponse<IDocumentDetailResponse>> {
|
||||
return await httpClient.post(`/${this.key}/`, data);
|
||||
}
|
||||
|
||||
async update(id: string, data: IDocument): Promise<AxiosResponse<IDocumentDetailResponse>> {
|
||||
return await httpClient.put(`/${this.key}/${id}`, data);
|
||||
}
|
||||
|
||||
async delete(id: string): Promise<AxiosResponse<null>> {
|
||||
return await httpClient.delete(`/${this.key}/${id}`);
|
||||
}
|
||||
}
|
||||
|
||||
export const documentOperator = new DocumentOperator();
|
||||
@@ -4,3 +4,4 @@ export * from './auth';
|
||||
export * from './service';
|
||||
export * from './user';
|
||||
export * from './api';
|
||||
export * from './document';
|
||||
@@ -1,42 +1,38 @@
|
||||
<template>
|
||||
<el-row class="wrapper">
|
||||
<el-col :span="22" :offset="1">
|
||||
<div class="left">
|
||||
<api-list />
|
||||
</div>
|
||||
<div v-if="api" class="main">
|
||||
<api-usage v-model:form="form" :api="api" :loading="loading" />
|
||||
</div>
|
||||
<div v-if="api" class="right">
|
||||
<api-try :form="form" :api="api" />
|
||||
</div>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<div v-if="document" class="center">
|
||||
<div v-if="document.type === 'TEXT'">
|
||||
<markdown-renderer :content="document?.content" />
|
||||
</div>
|
||||
<div v-else-if="document.type === 'API'">
|
||||
<api-usage v-if="document.api" v-model:form="form" :loading="loading" :api="document.api" />
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="document?.type === 'API' && document?.api" class="right">
|
||||
<api-try :form="form" :api="document?.api" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent } from 'vue';
|
||||
import ApiList from '@/components/document/ApiList.vue';
|
||||
import ApiUsage from '@/components/document/ApiUsage.vue';
|
||||
import ApiTry from '@/components/document/ApiTry.vue';
|
||||
import { apiOperator } from '@/operators/api/operator';
|
||||
import { IApi, IApiDetailResponse, IForm } from '@/operators/api/models';
|
||||
import ApiUsage from '@/components/api/Usage.vue';
|
||||
import ApiTry from '@/components/api/Try.vue';
|
||||
import { documentOperator, IDocument, IDocumentDetailResponse } from '@/operators';
|
||||
import { IForm } from '@/operators/api/models';
|
||||
|
||||
export interface IData {
|
||||
api: IApi | undefined;
|
||||
document: IDocument | undefined;
|
||||
loading: boolean;
|
||||
form: IForm;
|
||||
}
|
||||
|
||||
export default defineComponent({
|
||||
components: {
|
||||
ApiList,
|
||||
ApiUsage,
|
||||
ApiTry
|
||||
},
|
||||
data(): IData {
|
||||
return {
|
||||
api: undefined,
|
||||
document: undefined,
|
||||
loading: false,
|
||||
form: {}
|
||||
};
|
||||
@@ -49,21 +45,21 @@ export default defineComponent({
|
||||
watch: {
|
||||
id: {
|
||||
handler(val) {
|
||||
if (val) this.getApi(val);
|
||||
if (val) this.getDocument(val);
|
||||
}
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.getApi(this.id);
|
||||
this.getDocument(this.id);
|
||||
},
|
||||
methods: {
|
||||
getApi(id: string) {
|
||||
getDocument(id: string) {
|
||||
this.loading = true;
|
||||
apiOperator
|
||||
documentOperator
|
||||
.get(id)
|
||||
.then(({ data: data }: { data: IApiDetailResponse }) => {
|
||||
.then(({ data: data }: { data: IDocumentDetailResponse }) => {
|
||||
this.loading = false;
|
||||
this.api = data;
|
||||
this.document = data;
|
||||
})
|
||||
.catch((error) => {
|
||||
this.loading = false;
|
||||
@@ -75,29 +71,17 @@ export default defineComponent({
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.wrapper {
|
||||
width: 100%;
|
||||
overflow: hidden;
|
||||
.center {
|
||||
float: left;
|
||||
width: calc(100% - 760px);
|
||||
height: 100%;
|
||||
padding: 30px;
|
||||
}
|
||||
|
||||
.left {
|
||||
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;
|
||||
}
|
||||
.right {
|
||||
float: left;
|
||||
width: 480px;
|
||||
height: 100%;
|
||||
box-shadow: -1px 0 0 #eee;
|
||||
}
|
||||
</style>
|
||||
@@ -1,50 +1,32 @@
|
||||
<template>
|
||||
<el-row class="wrapper">
|
||||
<el-col :span="22" :offset="1">
|
||||
<div class="left">
|
||||
<api-list />
|
||||
</div>
|
||||
<div class="main">
|
||||
<h2>{{ $t('common.title.documentIntroduction') }}</h2>
|
||||
</div>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<div class="center">
|
||||
<h2>{{ $t('common.title.documentIntroduction') }}</h2>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent } from 'vue';
|
||||
import ApiList from '@/components/document/ApiList.vue';
|
||||
|
||||
export default defineComponent({
|
||||
components: {
|
||||
ApiList
|
||||
},
|
||||
data() {
|
||||
return {};
|
||||
},
|
||||
components: {},
|
||||
data() {},
|
||||
computed: {},
|
||||
mounted() {},
|
||||
methods: {}
|
||||
mounted() {}
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.wrapper {
|
||||
width: 100%;
|
||||
overflow: hidden;
|
||||
.center {
|
||||
float: left;
|
||||
width: calc(100% - 760px);
|
||||
height: 100%;
|
||||
padding: 30px;
|
||||
}
|
||||
|
||||
.left {
|
||||
float: left;
|
||||
width: 280px;
|
||||
height: 100%;
|
||||
box-shadow: 1px 0 0 #eee;
|
||||
}
|
||||
|
||||
.main {
|
||||
float: left;
|
||||
width: calc(100% - 280px);
|
||||
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