Files
Nexior/src/components/api/Usage.vue
T
2023-01-25 16:16:34 +08:00

180 lines
3.8 KiB
Vue

<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"
:service="api?.service"
:applications="applications"
@refresh-applications="getApplications"
/>
</div>
<div class="headers">
<h2 class="title">{{ $t('api.entity.requestHeaders') }}</h2>
<api-form
v-model:form="formValue.headers"
:schema="api?.request?.headers"
:service="api?.service"
:applications="applications"
/>
</div>
<div class="body">
<h2 class="title">{{ $t('api.entity.requestBody') }}</h2>
<api-form
v-model:form="formValue.body"
:schema="api?.request?.body"
:service="api?.service"
:applications="applications"
/>
</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, IForm } from '@/operators/api/models';
import ApiForm from './Form.vue';
import ApiResult from './Result.vue';
import urlJoin from 'url-join';
import { applicationOperator } from '@/operators/application/operator';
import { IApplication, IApplicationListResponse } from '@/operators/application/models';
export interface IData {
formValue: IForm;
applications: IApplication[];
}
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(): IData {
return {
formValue: this.form || {},
applications: []
};
},
watch: {
formValue: {
handler(val) {
this.$emit('update:form', { ...val });
},
deep: true
}
},
mounted() {
this.getApplications();
},
methods: {
urlJoin,
getApplications() {
applicationOperator
.getAll({
user_id: this.$store.getters.user?.id
})
.then(({ data: data }: { data: IApplicationListResponse }) => {
this.applications = data.items;
});
}
}
});
</script>
<style lang="scss" scoped>
.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>