add api try
This commit is contained in:
1 parent
bdfaf84b15
commit
983dff4ab3
7 files changed
+159
-62
No files matched your search
@@ -0,0 +1,38 @@
|
|||||||
|
<template>
|
||||||
|
<div class="authentication">
|
||||||
|
<div class="title">
|
||||||
|
{{ $t('api.entity.requestHeader') }}
|
||||||
|
</div>
|
||||||
|
<el-input v-model="apiKeyValue" placeholder="x-api-key">
|
||||||
|
<template #prepend>x-api-key</template>
|
||||||
|
</el-input>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts">
|
||||||
|
import { defineComponent } from 'vue';
|
||||||
|
|
||||||
|
export default defineComponent({
|
||||||
|
name: 'ApiTry',
|
||||||
|
props: {
|
||||||
|
apiKey: {
|
||||||
|
type: String,
|
||||||
|
required: false,
|
||||||
|
default: ''
|
||||||
|
}
|
||||||
|
},
|
||||||
|
emits: ['update:api-key'],
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
apiKeyValue: this.apiKey
|
||||||
|
};
|
||||||
|
},
|
||||||
|
watch: {
|
||||||
|
apiKeyValue: {
|
||||||
|
handler(val) {
|
||||||
|
this.$emit('update:api-key', val);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
@@ -36,7 +36,7 @@ export default defineComponent({
|
|||||||
required: true
|
required: true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
emits: ['change'],
|
emits: ['update:form'],
|
||||||
data(): IData {
|
data(): IData {
|
||||||
return {
|
return {
|
||||||
value: {}
|
value: {}
|
||||||
@@ -46,7 +46,7 @@ export default defineComponent({
|
|||||||
value: {
|
value: {
|
||||||
handler() {
|
handler() {
|
||||||
console.log('change', this.value);
|
console.log('change', this.value);
|
||||||
this.$emit('change', { ...this.value });
|
this.$emit('update:form', { ...this.value });
|
||||||
},
|
},
|
||||||
deep: true
|
deep: true
|
||||||
}
|
}
|
||||||
@@ -55,9 +55,6 @@ export default defineComponent({
|
|||||||
onChange(key: string, val: string) {
|
onChange(key: string, val: string) {
|
||||||
console.log('key', key, val);
|
console.log('key', key, val);
|
||||||
this.value[key] = val;
|
this.value[key] = val;
|
||||||
this.$emit('change', {
|
|
||||||
...this.value
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,38 +1,61 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="authentication">
|
<div class="wrapper">
|
||||||
<div class="title">
|
<div class="operation">
|
||||||
{{ $t('api.entity.requestHeader') }}
|
<el-button class="btn-try" type="primary" @click="onTry">{{ $t('common.button.try') }}</el-button>
|
||||||
|
</div>
|
||||||
|
<div class="result">
|
||||||
|
<div class="title">{{ $t('api.entity.response') }}</div>
|
||||||
</div>
|
</div>
|
||||||
<el-input v-model="apiKeyValue" placeholder="x-api-key">
|
|
||||||
<template #prepend>x-api-key</template>
|
|
||||||
</el-input>
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { IApi, IForm, IRequest } from '@/operators/api/models';
|
||||||
import { defineComponent } from 'vue';
|
import { defineComponent } from 'vue';
|
||||||
|
import axios, { Method } from 'axios';
|
||||||
|
import urlJoin from 'url-join';
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: 'ApiTry',
|
name: 'ApiTry',
|
||||||
props: {
|
props: {
|
||||||
apiKey: {
|
api: {
|
||||||
type: String,
|
type: Object as () => IApi,
|
||||||
required: false,
|
required: true
|
||||||
default: ''
|
},
|
||||||
|
form: {
|
||||||
|
type: Object as () => IForm,
|
||||||
|
required: true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
emits: ['update:api-key'],
|
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
apiKeyValue: this.apiKey
|
apiKeyValue: this.apiKey
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
watch: {
|
methods: {
|
||||||
apiKeyValue: {
|
onTry() {
|
||||||
handler(val) {
|
console.log('try', this.api, this.form);
|
||||||
this.$emit('update:api-key', val);
|
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', config);
|
||||||
|
axios(config).then((response) => {
|
||||||
|
console.log('response', response);
|
||||||
|
// response.data.pipe(fs.createWriteStream('ada_lovelace.jpg'));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
.wrapper {
|
||||||
|
padding: 15px;
|
||||||
|
.btn-try {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -18,15 +18,15 @@
|
|||||||
<el-divider />
|
<el-divider />
|
||||||
<div class="queries">
|
<div class="queries">
|
||||||
<h2 class="title">{{ $t('api.entity.requestQueries') }}</h2>
|
<h2 class="title">{{ $t('api.entity.requestQueries') }}</h2>
|
||||||
<api-form :schema="api?.request.queries" />
|
<api-form v-model:form="formValue.queries" :schema="api?.request.queries" />
|
||||||
</div>
|
</div>
|
||||||
<div class="headers">
|
<div class="headers">
|
||||||
<h2 class="title">{{ $t('api.entity.requestHeaders') }}</h2>
|
<h2 class="title">{{ $t('api.entity.requestHeaders') }}</h2>
|
||||||
<api-form :schema="api?.request.headers" />
|
<api-form v-model:form="formValue.headers" :schema="api?.request.headers" />
|
||||||
</div>
|
</div>
|
||||||
<div class="body">
|
<div class="body">
|
||||||
<h2 class="title">{{ $t('api.entity.requestBody') }}</h2>
|
<h2 class="title">{{ $t('api.entity.requestBody') }}</h2>
|
||||||
<api-form :schema="api?.request.body" />
|
<api-form v-model:form="formValue.body" :schema="api?.request.body" />
|
||||||
</div>
|
</div>
|
||||||
<div v-if="api?.responses" class="responses">
|
<div v-if="api?.responses" class="responses">
|
||||||
<h2 class="title">{{ $t('api.entity.response') }}</h2>
|
<h2 class="title">{{ $t('api.entity.response') }}</h2>
|
||||||
@@ -37,15 +37,13 @@
|
|||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { defineComponent } from 'vue';
|
import { defineComponent } from 'vue';
|
||||||
import { IApi, IApiDetailResponse } from '@/operators/api/models';
|
import { IApi, IApiDetailResponse, IForm } from '@/operators/api/models';
|
||||||
import { apiOperator } from '@/operators/api/operator';
|
|
||||||
import ApiForm from './ApiForm.vue';
|
import ApiForm from './ApiForm.vue';
|
||||||
import ApiResult from './ApiResult.vue';
|
import ApiResult from './ApiResult.vue';
|
||||||
import urlJoin from 'url-join';
|
import urlJoin from 'url-join';
|
||||||
|
|
||||||
export interface IData {
|
export interface IData {
|
||||||
api: IApi | undefined;
|
formValue: IForm | undefined;
|
||||||
loading: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
@@ -55,43 +53,36 @@ export default defineComponent({
|
|||||||
ApiResult
|
ApiResult
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
id: {
|
api: {
|
||||||
type: String,
|
type: Object as () => IApi,
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
loading: {
|
||||||
|
type: Boolean,
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
form: {
|
||||||
|
type: Object as () => IForm,
|
||||||
required: true
|
required: true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
data(): IData {
|
emits: ['update:form'],
|
||||||
|
data() {
|
||||||
return {
|
return {
|
||||||
api: undefined,
|
formValue: this.form
|
||||||
loading: false
|
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
id: {
|
formValue: {
|
||||||
handler() {
|
handler(val) {
|
||||||
this.getApi(this.id);
|
console.log('formValue changeddd');
|
||||||
}
|
this.$emit('update:form', { ...val });
|
||||||
|
},
|
||||||
|
deep: true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted() {
|
|
||||||
this.getApi(this.id);
|
|
||||||
},
|
|
||||||
methods: {
|
methods: {
|
||||||
urlJoin,
|
urlJoin
|
||||||
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>
|
</script>
|
||||||
|
|||||||
@@ -15,5 +15,6 @@ export default {
|
|||||||
profile: '个人信息',
|
profile: '个人信息',
|
||||||
console: '控制台',
|
console: '控制台',
|
||||||
learn: '学习',
|
learn: '学习',
|
||||||
buy: '购买'
|
buy: '购买',
|
||||||
|
try: '测试'
|
||||||
};
|
};
|
||||||
@@ -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 {
|
export interface ISchema {
|
||||||
properties: {
|
properties: {
|
||||||
[key: string]: ISchema;
|
[key: string]: ISchema;
|
||||||
|
|||||||
@@ -4,11 +4,11 @@
|
|||||||
<div class="left">
|
<div class="left">
|
||||||
<api-list />
|
<api-list />
|
||||||
</div>
|
</div>
|
||||||
<div class="main">
|
<div v-if="api" class="main">
|
||||||
<api-usage :id="id" />
|
<api-usage v-model:form="form" :api="api" :loading="loading" />
|
||||||
</div>
|
</div>
|
||||||
<div class="right">
|
<div class="right">
|
||||||
<api-try v-model:api-key="apiKey" />
|
<api-try :form="form" :api="api" />
|
||||||
</div>
|
</div>
|
||||||
</el-col>
|
</el-col>
|
||||||
</el-row>
|
</el-row>
|
||||||
@@ -19,6 +19,14 @@ import { defineComponent } from 'vue';
|
|||||||
import ApiList from '@/components/document/ApiList.vue';
|
import ApiList from '@/components/document/ApiList.vue';
|
||||||
import ApiUsage from '@/components/document/ApiUsage.vue';
|
import ApiUsage from '@/components/document/ApiUsage.vue';
|
||||||
import ApiTry from '@/components/document/ApiTry.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({
|
export default defineComponent({
|
||||||
components: {
|
components: {
|
||||||
@@ -26,9 +34,11 @@ export default defineComponent({
|
|||||||
ApiUsage,
|
ApiUsage,
|
||||||
ApiTry
|
ApiTry
|
||||||
},
|
},
|
||||||
data() {
|
data(): IData {
|
||||||
return {
|
return {
|
||||||
apiKey: ''
|
api: undefined,
|
||||||
|
loading: false,
|
||||||
|
form: {}
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@@ -36,7 +46,32 @@ export default defineComponent({
|
|||||||
return this.$route.params.id.toString();
|
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);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user