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
|
||||
}
|
||||
},
|
||||
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
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,38 +1,61 @@
|
||||
<template>
|
||||
<div class="authentication">
|
||||
<div class="title">
|
||||
{{ $t('api.entity.requestHeader') }}
|
||||
<div class="wrapper">
|
||||
<div class="operation">
|
||||
<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>
|
||||
<el-input v-model="apiKeyValue" placeholder="x-api-key">
|
||||
<template #prepend>x-api-key</template>
|
||||
</el-input>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { IApi, IForm, IRequest } from '@/operators/api/models';
|
||||
import { defineComponent } from 'vue';
|
||||
import axios, { Method } from 'axios';
|
||||
import urlJoin from 'url-join';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'ApiTry',
|
||||
props: {
|
||||
apiKey: {
|
||||
type: String,
|
||||
required: false,
|
||||
default: ''
|
||||
api: {
|
||||
type: Object as () => IApi,
|
||||
required: true
|
||||
},
|
||||
form: {
|
||||
type: Object as () => IForm,
|
||||
required: true
|
||||
}
|
||||
},
|
||||
emits: ['update:api-key'],
|
||||
data() {
|
||||
return {
|
||||
apiKeyValue: this.apiKey
|
||||
};
|
||||
},
|
||||
watch: {
|
||||
apiKeyValue: {
|
||||
handler(val) {
|
||||
this.$emit('update:api-key', val);
|
||||
}
|
||||
methods: {
|
||||
onTry() {
|
||||
console.log('try', this.api, this.form);
|
||||
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>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.wrapper {
|
||||
padding: 15px;
|
||||
.btn-try {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -18,15 +18,15 @@
|
||||
<el-divider />
|
||||
<div class="queries">
|
||||
<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 class="headers">
|
||||
<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 class="body">
|
||||
<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 v-if="api?.responses" class="responses">
|
||||
<h2 class="title">{{ $t('api.entity.response') }}</h2>
|
||||
@@ -37,15 +37,13 @@
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent } from 'vue';
|
||||
import { IApi, IApiDetailResponse } from '@/operators/api/models';
|
||||
import { apiOperator } from '@/operators/api/operator';
|
||||
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 {
|
||||
api: IApi | undefined;
|
||||
loading: boolean;
|
||||
formValue: IForm | undefined;
|
||||
}
|
||||
|
||||
export default defineComponent({
|
||||
@@ -55,43 +53,36 @@ export default defineComponent({
|
||||
ApiResult
|
||||
},
|
||||
props: {
|
||||
id: {
|
||||
type: String,
|
||||
api: {
|
||||
type: Object as () => IApi,
|
||||
required: true
|
||||
},
|
||||
loading: {
|
||||
type: Boolean,
|
||||
required: true
|
||||
},
|
||||
form: {
|
||||
type: Object as () => IForm,
|
||||
required: true
|
||||
}
|
||||
},
|
||||
data(): IData {
|
||||
emits: ['update:form'],
|
||||
data() {
|
||||
return {
|
||||
api: undefined,
|
||||
loading: false
|
||||
formValue: this.form
|
||||
};
|
||||
},
|
||||
watch: {
|
||||
id: {
|
||||
handler() {
|
||||
this.getApi(this.id);
|
||||
}
|
||||
formValue: {
|
||||
handler(val) {
|
||||
console.log('formValue changeddd');
|
||||
this.$emit('update:form', { ...val });
|
||||
},
|
||||
deep: true
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.getApi(this.id);
|
||||
},
|
||||
methods: {
|
||||
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);
|
||||
});
|
||||
}
|
||||
urlJoin
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
Reference in new issue
Block a user