From 983dff4ab31e44e7c9bef31c0a66d77bba50f93d Mon Sep 17 00:00:00 2001 From: AceDataCloud Date: Sat, 21 Jan 2023 12:40:45 +0800 Subject: [PATCH] add api try --- src/components/document/ApiCode.vue | 38 ++++++++++++++++++ src/components/document/ApiForm.vue | 7 +--- src/components/document/ApiTry.vue | 55 ++++++++++++++++++-------- src/components/document/ApiUsage.vue | 59 ++++++++++++---------------- src/i18n/zh/common/button.ts | 3 +- src/operators/api/models.ts | 12 ++++++ src/pages/document/Detail.vue | 47 +++++++++++++++++++--- 7 files changed, 159 insertions(+), 62 deletions(-) create mode 100644 src/components/document/ApiCode.vue diff --git a/src/components/document/ApiCode.vue b/src/components/document/ApiCode.vue new file mode 100644 index 00000000..b4671d5a --- /dev/null +++ b/src/components/document/ApiCode.vue @@ -0,0 +1,38 @@ + + + diff --git a/src/components/document/ApiForm.vue b/src/components/document/ApiForm.vue index 210de969..654bcd25 100644 --- a/src/components/document/ApiForm.vue +++ b/src/components/document/ApiForm.vue @@ -36,7 +36,7 @@ export default defineComponent({ required: true } }, - emits: ['change'], + emits: ['update:form'], data(): IData { return { value: {} @@ -46,7 +46,7 @@ export default defineComponent({ value: { handler() { console.log('change', this.value); - this.$emit('change', { ...this.value }); + this.$emit('update:form', { ...this.value }); }, deep: true } @@ -55,9 +55,6 @@ export default defineComponent({ onChange(key: string, val: string) { console.log('key', key, val); this.value[key] = val; - this.$emit('change', { - ...this.value - }); } } }); diff --git a/src/components/document/ApiTry.vue b/src/components/document/ApiTry.vue index b4671d5a..36785504 100644 --- a/src/components/document/ApiTry.vue +++ b/src/components/document/ApiTry.vue @@ -1,38 +1,61 @@ + + diff --git a/src/components/document/ApiUsage.vue b/src/components/document/ApiUsage.vue index 565ad3d4..3bcda3ad 100644 --- a/src/components/document/ApiUsage.vue +++ b/src/components/document/ApiUsage.vue @@ -18,15 +18,15 @@

{{ $t('api.entity.requestQueries') }}

- +

{{ $t('api.entity.requestHeaders') }}

- +

{{ $t('api.entity.requestBody') }}

- +

{{ $t('api.entity.response') }}

@@ -37,15 +37,13 @@ diff --git a/src/i18n/zh/common/button.ts b/src/i18n/zh/common/button.ts index ad177047..2d54a0e5 100644 --- a/src/i18n/zh/common/button.ts +++ b/src/i18n/zh/common/button.ts @@ -15,5 +15,6 @@ export default { profile: '个人信息', console: '控制台', learn: '学习', - buy: '购买' + buy: '购买', + try: '测试' }; diff --git a/src/operators/api/models.ts b/src/operators/api/models.ts index 594f889c..6b0f0e4f 100644 --- a/src/operators/api/models.ts +++ b/src/operators/api/models.ts @@ -1,3 +1,15 @@ +export interface IForm { + queries?: { + [key: string]: string; + }; + headers?: { + [key: string]: string; + }; + body?: { + [key: string]: string | object | number | object[]; + }; +} + export interface ISchema { properties: { [key: string]: ISchema; diff --git a/src/pages/document/Detail.vue b/src/pages/document/Detail.vue index 8fd1a853..0607d4a7 100644 --- a/src/pages/document/Detail.vue +++ b/src/pages/document/Detail.vue @@ -4,11 +4,11 @@
-
- +
+
- +
@@ -19,6 +19,14 @@ 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'; + +export interface IData { + api: IApi | undefined; + loading: boolean; + form: IForm; +} export default defineComponent({ components: { @@ -26,9 +34,11 @@ export default defineComponent({ ApiUsage, ApiTry }, - data() { + data(): IData { return { - apiKey: '' + api: undefined, + loading: false, + form: {} }; }, computed: { @@ -36,7 +46,32 @@ export default defineComponent({ return this.$route.params.id.toString(); } }, - methods: {} + watch: { + id: { + handler() { + this.getApi(this.id); + } + } + }, + mounted() { + this.getApi(this.id); + }, + methods: { + 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); + }); + } + } });