remove unused

This commit is contained in:
AceDataCloud committed 2023-04-07 13:05:35 +08:00
1 parent 301dab1ca5
commit ea1c3413a5
88 files changed
+29 -5766

No files matched your search

-272
View File
@@ -1,272 +0,0 @@
<template>
<div class="wrapper">
<div class="options mb-2">
<div
v-for="(option, optionKey) in options"
:key="optionKey"
:class="{
option: true,
active: lang === option.name
}"
@click="lang = option.name"
>
<el-image :src="option.icon" class="icon" />
<p class="name">{{ option.name }}</p>
</div>
</div>
<div v-if="code" class="code">
<code-snippet :code="code" :lang="lang" />
</div>
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import javascript from 'programming-languages-logos/src/javascript/javascript.svg';
import python from 'programming-languages-logos/src/python/python.svg';
import java from 'programming-languages-logos/src/java/java.svg';
import php from 'programming-languages-logos/src/php/php.svg';
import { IApi, IForm, IRequest } from '@/operators/api/models';
import urlJoin from 'url-join';
import Mustache from 'mustache';
import pythonTemplate from '@/assets/templates/python.tpl';
import javascriptTemplate from '@/assets/templates/javascript.tpl';
import phpTemplate from '@/assets/templates/php.tpl';
import javaTemplate from '@/assets/templates/java.tpl';
import CodeSnippet from '../common/CodeSnippet.vue';
import queryString from 'query-string';
import { ElImage } from 'element-plus';
interface IOption {
name: ILang;
icon: string;
}
const LANG_PYTHON = 'Python';
const LANG_JAVA = 'Java';
const LANG_JAVASCRIPT = 'JavaScript';
const LANG_PHP = 'PHP';
type ILang = typeof LANG_PYTHON | typeof LANG_JAVA | typeof LANG_JAVASCRIPT | typeof LANG_PHP;
interface IData {
lang: ILang | undefined;
options: IOption[];
}
interface IRenderData {
headers: {
key: string;
value: string;
}[];
body: {
key: string;
value: string | object | number | object[] | boolean;
}[];
method: IRequest['method'] | Lowercase<IRequest['method']> | Uppercase<IRequest['method']>;
url: string;
}
export default defineComponent({
name: 'ApiCode',
components: {
CodeSnippet,
ElImage
},
props: {
api: {
type: Object as () => IApi,
required: true
},
form: {
type: Object as () => IForm,
required: true
}
},
data(): IData {
return {
lang: undefined,
options: [
{
name: LANG_PYTHON,
icon: python
},
{
name: LANG_JAVASCRIPT,
icon: javascript
},
{
name: LANG_JAVA,
icon: java
},
{
name: LANG_PHP,
icon: php
}
]
};
},
computed: {
method() {
return this.api.request.method;
},
url() {
const getQueryString = () => {
if (this.form.queries) {
return `?${queryString.stringify(this.form?.queries)}`;
}
return '';
};
return urlJoin(this.api?.endpoint, this.api?.path, getQueryString());
},
headers() {
let result = [];
for (const key in this.form.headers) {
result.push({
key,
value: this.form.headers[key]
});
}
if (result.length > 0) {
const last = result[result.length - 1];
result[result.length - 1] = {
...last,
last: true
};
}
return result;
},
body() {
let result = [];
for (const key in this.form.body) {
const value = this.form.body[key];
result.push({
key,
value
});
}
if (result.length > 0) {
const last = result[result.length - 1];
result[result.length - 1] = {
...last,
last: true
};
}
return result;
},
code(): string | undefined {
let template = undefined;
let renderData: IRenderData = JSON.parse(
JSON.stringify({
headers: this.headers,
body: this.body,
url: this.url,
method: this.method
})
);
if (this.lang === LANG_PYTHON) {
template = pythonTemplate;
for (const item of renderData.headers) {
let value = item.value;
item.value = `'${value}'`;
}
for (const item of renderData.body) {
let value = item.value;
if (value === true || value === false) {
item.value = `${value.toString()[0].toUpperCase() + value.toString().substring(1)}`;
} else if (typeof value === 'string') {
item.value = `'${value}'`;
}
}
renderData = {
...renderData,
method: renderData.method.toLowerCase() as Lowercase<IRenderData['method']>
};
} else if (this.lang === LANG_JAVASCRIPT) {
template = javascriptTemplate;
for (const item of renderData.headers) {
let value = item.value;
item.value = `'${value}'`;
}
for (const item of renderData.body) {
let value = item.value;
if (typeof value === 'string') {
item.value = `'${value}'`;
}
}
} else if (this.lang === LANG_PHP) {
template = phpTemplate;
for (const item of renderData.headers) {
let value = item.value;
item.value = `'${value}'`;
}
for (const item of renderData.body) {
let value = item.value;
if (typeof value === 'string') {
item.value = `"${value}"`;
}
}
} else if (this.lang === LANG_JAVA) {
template = javaTemplate;
for (const item of renderData.headers) {
let value = item.value;
item.value = `"${value}"`;
}
for (const item of renderData.body) {
let value = item.value;
if (typeof value === 'string') {
item.value = `"${value}"`;
}
}
}
if (template) return Mustache.render(template, renderData);
return undefined;
}
},
mounted() {
this.lang = this.options[0].name;
}
});
</script>
<style lang="scss" scoped>
.wrapper {
width: 100%;
// padding: 15px;
padding-bottom: 0;
overflow-x: scroll;
.options {
width: fit-content;
overflow: hidden;
.option {
margin: 0 5px;
float: left;
width: 70px;
height: 70px;
text-align: center;
border: 1px solid transparent;
padding: 10px;
border-radius: 10px;
display: inline-flex;
flex-direction: column;
text-align: center;
align-items: center;
&:hover,
&.active {
border-color: #ccc;
cursor: pointer;
}
.icon {
width: 30px;
height: 30px;
margin-bottom: 10px;
}
.name {
color: #666;
font-size: 11px;
font-weight: bold;
}
}
}
}
</style>
-296
View File
@@ -1,296 +0,0 @@
<template>
<div v-if="schema" class="wrapper">
<div v-for="(item, itemKey) in schema?.properties" :key="itemKey" class="item">
<div class="left">
<div class="info">
<span class="key">{{ itemKey }}</span>
<span class="type">{{ item?.type }}</span>
<span v-if="!item?.optional" class="required">{{ $t('application.message.requiredParameter') }}</span>
</div>
<div class="description">
{{ item?.title }}
</div>
</div>
<div class="right">
<div v-if="itemKey === 'token'">
<div v-if="!applied === true">
<application-confirm
v-if="api"
v-model.visible="confirming"
:object="api"
:type="applicationType.API"
@apply="onApply"
/>
<el-popover placement="bottom" :width="200" :visible="applied === false">
<p class="text-center mb-2">
<small>{{ $t('application.message.notApplied') }}</small>
</p>
<p class="text-center">
<el-button size="small" type="primary" @click="confirming = true">{{
$t('common.button.apply')
}}</el-button>
</p>
<template #reference>
<el-input
v-model="value[itemKey?.toString()]"
:placeholder="$t('common.title.placeholderOfInput')"
class="inline-block w-2/3"
/>
</template>
</el-popover>
<el-button type="primary" class="inline-block ml-2" size="small" @click="$emit('refresh-applications')">
{{ $t('common.button.acquire') }}
</el-button>
</div>
<el-select
v-else
v-model="value[itemKey?.toString()]"
:clearable="true"
:filterable="true"
:allow-create="true"
class="w-full"
:placeholder="$t('common.title.placeholderOfSelect')"
>
<el-option
v-if="appliedApplication?.credential?.token"
:label="appliedApplication?.credential?.token"
:value="appliedApplication?.credential?.token"
class="select-option"
>
<span class="select-option-main">{{ appliedApplication?.credential?.token }}</span>
<span class="select-option-description">{{ $t('application.message.yourApplication') }}</span>
</el-option>
</el-select>
</div>
<div v-else>
<el-select
v-if="item?.enum"
v-model="value[itemKey?.toString()]"
:default-first-option="item?.enum?.length === 1"
clearable
class="w-full"
:placeholder="$t('common.title.placeholderOfSelect')"
>
<el-option v-for="e in item?.enum" :key="e" :label="e" :value="e" />
</el-select>
<el-select
v-else-if="item?.type === 'boolean'"
v-model="value[itemKey?.toString()]"
clearable
class="w-full"
:placeholder="$t('common.title.placeholderOfSelect')"
>
<el-option key="true" :label="'true'" :value="true" />
<el-option key="false" :label="'false'" :value="false" />
</el-select>
<div v-else-if="item?.example">
<el-input
v-model="value[itemKey?.toString()]"
class="inline-block w-2/3"
:placeholder="$t('common.title.placeholderOfInput')"
/>
<el-button
type="primary"
class="inline-block ml-2"
size="small"
@click="value[itemKey?.toString()] = item.example!"
>
{{ $t('common.button.fillExample') }}
</el-button>
</div>
<el-input v-else v-model="value[itemKey?.toString()]" />
</div>
</div>
</div>
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import { ISchema } from '@/operators/api/models';
import { applicationOperator, IApi, IApplication, IApplicationType } from '@/operators';
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
import { ElPopover, ElInput, ElSelect, ElButton, ElTooltip, ElOption, ElMessage } from 'element-plus';
import { ERROR_CODE_DUPLICATION, ERROR_CODE_UNVERIFIED } from '@/constants/errorCode';
import { getVerificationUrl } from '@/utils';
import ApplicationConfirm from '@/components/application/Confirm.vue';
interface IData {
value: {
[key: string]: string | number;
};
confirming: boolean;
applicationType: typeof IApplicationType;
}
export default defineComponent({
name: 'ApiForm',
components: {
ElPopover,
ElInput,
ElSelect,
ElButton,
ElOption,
ApplicationConfirm
},
props: {
schema: {
type: Object as () => ISchema | undefined,
required: true
},
api: {
type: Object as () => IApi | undefined,
required: true
},
applications: {
type: Array as () => IApplication[],
required: true
},
applied: {
type: Boolean,
required: false
}
},
emits: ['update:form', 'refresh-applications'],
data(): IData {
return {
value: {},
confirming: false,
applicationType: IApplicationType
};
},
computed: {
appliedApplication(): IApplication | undefined {
const applications = this.applications.filter((application) => application.api?.id === this.api?.id);
if (applications.length > 0) {
return applications[0];
}
return undefined;
}
},
watch: {
value: {
handler() {
this.$emit('update:form', { ...this.value });
},
deep: true
}
},
methods: {
onChange(key: string, val: string) {
this.value[key] = val;
},
onRefreshApplications() {
this.$emit('refresh-applications');
},
onApply() {
this.confirming = false;
applicationOperator
.create({
type: IApplicationType.API,
api_id: this.api?.id
})
.then(() => {
ElMessage.success(this.$t('application.message.applySuccessfully'));
this.$emit('refresh-applications');
})
.catch((error) => {
if (error?.response?.data?.code === ERROR_CODE_DUPLICATION) {
ElMessage.error(this.$t('application.message.alreadyApplied'));
}
if (error?.response?.data?.code === ERROR_CODE_UNVERIFIED) {
ElMessage({
dangerouslyUseHTMLString: true,
duration: 0,
showClose: true,
message: `${this.$t(
'application.message.unverified'
)} <a class="underline" href="${getVerificationUrl()}">${this.$t('application.message.goVerify')}</a>`,
type: 'warning'
});
}
});
}
}
});
</script>
<style lang="scss" scoped>
.wrapper {
overflow: hidden;
.item {
display: block;
overflow: hidden;
background-color: rgb(248, 248, 248);
padding: 10px;
border-right: 1px solid rgba(0, 0, 0, 0.1);
border-left: 1px solid rgba(0, 0, 0, 0.1);
&:first-child {
border-top: 1px solid rgba(0, 0, 0, 0.1);
border-top-left-radius: 10px;
border-top-right-radius: 10px;
}
&:not(:first-child):not(:last-child) {
border-top: 1px solid rgba(0, 0, 0, 0.1);
}
&:last-child {
border-top: 1px solid rgba(0, 0, 0, 0.1);
border-bottom: 1px solid rgba(0, 0, 0, 0.1);
border-bottom-left-radius: 10px;
border-bottom-right-radius: 10px;
}
.left {
width: 70%;
float: left;
.info {
.key {
font-size: 14px;
font-weight: bold;
display: inline-block;
padding: 3px;
padding-left: 0;
}
.type {
font-size: 14px;
display: inline-block;
padding: 3px;
}
.required {
font-size: 12px;
color: #dd1e2e;
display: inline-block;
padding: 3px;
}
}
.description {
font-size: 12px;
color: #666;
}
}
.right {
width: 30%;
float: left;
padding-top: 6px;
}
}
}
.el-select-dropdown {
.select-option {
.select-option-main {
display: inline-block;
font-size: 14px;
}
.select-option-description {
display: inline-block;
font-size: 12px;
color: #999;
margin-left: 20px;
}
}
}
</style>
-61
View File
@@ -1,61 +0,0 @@
<template>
<div class="title">
{{ api?.title }}
</div>
<div class="url">
<el-tag class="method" 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>
</template>
<script lang="ts">
import { IApi } from '@/operators';
import { defineComponent } from 'vue';
import urlJoin from 'url-join';
import { ElTag } from 'element-plus';
export default defineComponent({
name: 'ApiInfo',
components: {
ElTag
},
props: {
api: {
type: Object as () => IApi,
required: true
}
},
methods: {
urlJoin
}
});
</script>
<style lang="scss" scoped>
.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);
transform-origin: left;
}
.endpoint {
font-size: 12px;
}
}
.introduction {
font-size: 16px;
font-weight: bold;
margin-bottom: 10px;
}
</style>
-158
View File
@@ -1,158 +0,0 @@
<template>
<div class="title">
<el-button type="primary" size="small" class="mb-1">{{ $t('application.field.api') }}</el-button>
{{ api?.title }}
</div>
<div class="introduction">
<p>{{ api?.introduction }}</p>
</div>
<div class="options">
<el-button
v-if="showFirstOption"
ref="option"
type="primary"
:plain="activeOption !== 'first'"
class="option"
@click="activeOption = 'first'"
>{{ $t('api.message.firstFree') }}</el-button
>
<el-button
v-for="(pkg, pkgIndex) in api?.packages"
ref="option"
:key="pkgIndex"
type="primary"
:plain="!(activeOption == 'package' && activePackage?.id === pkg.id)"
class="option"
@click="
activeOption = 'package';
activePackage = pkg;
"
>
{{ pkg.amount }}{{ $t(`api.unit.${api.unit}`) }}
</el-button>
<el-button
v-if="showCustomOption"
ref="option"
type="primary"
:plain="activeOption !== 'custom'"
class="option"
@click="activeOption = 'custom'"
>{{ $t('api.message.custom') }}</el-button
>
</div>
<div class="price">
<span v-if="activeOption === 'first'" class="value">¥0</span>
<span v-if="activeOption === 'first'" class="remark">
({{ $t('api.message.present') + `${api.free_amount}` + $t(`api.unit.${api.unit}`) }})
</span>
<span v-if="activeOption === 'custom'" class="value">¥{{ api?.price }}</span>
<span v-if="activeOption === 'custom'" class="remark">{{ '/' + $t(`api.unit.${api.unit}`) }}</span>
<span v-if="activeOption === 'package'" class="value"> ¥{{ activePackage?.price }} </span>
<span v-if="activeOption === 'package' && activePackage" class="remark">
({{
$t('api.message.around') +
'¥' +
(activePackage?.price / activePackage?.amount).toFixed(4) +
'/' +
$t(`api.unit.${api.unit}`)
}})
</span>
</div>
</template>
<script lang="ts">
import { IApi, IPackage } from '@/operators';
import { defineComponent } from 'vue';
import urlJoin from 'url-join';
import { ElButton } from 'element-plus';
interface IData {
activeOption: string | undefined;
activePackage: IPackage | undefined;
}
export default defineComponent({
name: 'ApiPreview',
components: {
ElButton
},
props: {
api: {
type: Object as () => IApi,
required: true
}
},
data(): IData {
return {
activeOption: undefined,
activePackage: undefined
};
},
computed: {
showFirstOption() {
return this.api.free_amount !== 0;
},
showPackageOption() {
return this.api && this.api.packages && this.api?.packages?.length > 0;
},
showCustomOption() {
return this.api.price === 0 || this.api?.price;
}
},
mounted() {
if (this.showFirstOption) {
this.activeOption = 'first';
} else if (this.showPackageOption) {
this.activeOption = 'package';
// @ts-ignore
this.activePackage = this.api.packages[0];
} else if (this.showCustomOption) {
this.activeOption = 'custom';
}
},
methods: {
urlJoin,
onSelect(option: string, pkg?: IPackage) {
this.activeOption = option;
this.activePackage = pkg;
}
}
});
</script>
<style lang="scss" scoped>
.title {
font-size: 26px;
font-weight: 500;
line-height: 1.2;
margin-bottom: 10px;
}
.introduction {
font-size: 14px;
margin-bottom: 15px;
color: #666;
}
.options {
.option {
border-radius: 5px !important;
}
margin-bottom: 10px;
}
.price {
.value {
font-weight: bold;
color: #ff5441;
font-size: 24px;
}
.remark {
font-size: 14px;
color: #999;
display: inline-block;
margin-left: 5px;
}
}
</style>
-86
View File
@@ -1,86 +0,0 @@
<template>
<div v-if="schema" class="body">
<div v-if="schema.items && schema.type === 'array'" class="items">
<h2 class="title">{{ $t('api.entity.arrayOf') }}</h2>
<div v-for="(item, itemKey) in schema.items" :key="itemKey" class="item">
<response-body :schema="item" />
</div>
</div>
<div class="properties">
<div v-for="(item, itemKey) in schema.properties" :key="itemKey" class="property">
<div class="info">
<span class="key">{{ itemKey }}</span>
<span class="type">{{ item?.type }}</span>
</div>
<div class="description">
{{ item?.title }}
</div>
</div>
</div>
</div>
</template>
<script lang="ts">
import { ISchema } from '@/operators';
import { defineComponent } from 'vue';
export default defineComponent({
name: 'ResponseBody',
props: {
schema: {
type: Object as () => ISchema,
required: true
}
}
});
</script>
<style lang="scss">
.items {
padding: 10px;
border-radius: 10px;
border: 1px solid rgba(0, 0, 0, 0.1);
.title {
margin-bottom: 5px;
}
}
.properties {
margin-bottom: 10px;
.property {
padding: 10px;
border-right: 1px solid rgba(0, 0, 0, 0.1);
border-left: 1px solid rgba(0, 0, 0, 0.1);
&:first-of-type {
border-top: 1px solid rgba(0, 0, 0, 0.1);
border-top-left-radius: 10px;
border-top-right-radius: 10px;
}
&:not(:first-of-type):not(:last-of-type) {
border-top: 1px solid rgba(0, 0, 0, 0.1);
}
&:last-of-type {
border-top: 1px solid rgba(0, 0, 0, 0.1);
border-bottom: 1px solid rgba(0, 0, 0, 0.1);
border-bottom-left-radius: 10px;
border-bottom-right-radius: 10px;
}
.info {
.key {
font-size: 14px;
font-weight: bold;
display: inline-block;
padding: 3px;
padding-left: 0;
}
.type {
font-size: 14px;
display: inline-block;
padding: 3px;
}
}
}
}
</style>
-185
View File
@@ -1,185 +0,0 @@
<template>
<el-collapse v-if="responses" id="document-response-item" class="wrapper" accordion>
<el-collapse-item v-for="(response, responseKey) in responses" :key="responseKey" class="item" :name="responseKey">
<template #title>
<span class="badge">
<el-tag v-if="response?.is_success" class="ml-2" type="success">{{ $t('api.entity.success') }}</el-tag>
<el-tag v-else class="ml-2" type="danger">{{ $t('api.entity.failure') }}</el-tag>
</span>
<span class="status-code">
{{ response?.status_code }}
</span>
<span class="error-code">
{{ response?.error_code }}
</span>
</template>
<div class="item-body">
<div>
{{ response.description }}
</div>
<el-divider class="my-3" />
<div v-if="response?.headers?.properties" class="headers">
<h2 class="title">{{ $t('api.entity.responseHeaders') }}</h2>
<div class="properties">
<div v-for="(item, itemKey) in response?.headers?.properties" :key="itemKey" class="property">
<div class="info">
<span class="key">{{ itemKey }}</span>
<span class="type">{{ item?.type }}</span>
</div>
<div class="description">
{{ item?.title }}
</div>
</div>
</div>
</div>
<div v-if="response?.body" class="body">
<h2 class="title">{{ $t('api.entity.responseBody') }}</h2>
<response-body :schema="response?.body" />
</div>
<div v-if="response?.example" class="example">
<h2 class="title">{{ $t('api.entity.responseExample') }}</h2>
<code-snippet :code="response?.example" />
</div>
</div>
</el-collapse-item>
</el-collapse>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import { IResponse } from '@/operators/api/models';
import CodeSnippet from '../common/CodeSnippet.vue';
import { ElCollapse, ElCollapseItem, ElTag, ElDivider } from 'element-plus';
import ResponseBody from './ResponseBody.vue';
interface IData {
value: {
[key: string]: string | number;
};
}
export default defineComponent({
name: 'ApiResult',
components: {
CodeSnippet,
ElCollapse,
ElCollapseItem,
ElTag,
ResponseBody,
ElDivider
},
props: {
responses: {
type: Object as () => IResponse[] | [],
required: true
}
},
data(): IData {
return {
value: {}
};
}
});
</script>
<style lang="scss" scoped>
.wrapper {
overflow: hidden;
border: none;
.item {
display: block;
overflow: hidden;
background-color: #f8f8f8;
border-right: 1px solid rgba(0, 0, 0, 0.1);
border-left: 1px solid rgba(0, 0, 0, 0.1);
.status-code,
.error-code {
display: inline-block;
padding-left: 5px;
}
&.el-collapse-item:last-child {
margin-bottom: 0;
}
&:first-child {
border-top: 1px solid rgba(0, 0, 0, 0.1);
border-top-left-radius: 10px;
border-top-right-radius: 10px;
}
&:not(:first-child):not(:last-child) {
border-top: 1px solid rgba(0, 0, 0, 0.1);
}
&:last-child {
border-top: 1px solid rgba(0, 0, 0, 0.1);
border-bottom: 1px solid rgba(0, 0, 0, 0.1);
border-bottom-left-radius: 10px;
border-bottom-right-radius: 10px;
}
.item-body {
padding: 15px;
.body,
.headers,
.example {
.title {
font-size: 12px;
font-weight: bold;
margin-bottom: 10px;
}
.properties {
margin-bottom: 10px;
.property {
padding: 10px;
border-right: 1px solid rgba(0, 0, 0, 0.1);
border-left: 1px solid rgba(0, 0, 0, 0.1);
&:first-of-type {
border-top: 1px solid rgba(0, 0, 0, 0.1);
border-top-left-radius: 10px;
border-top-right-radius: 10px;
}
&:not(:first-of-type):not(:last-of-type) {
border-top: 1px solid rgba(0, 0, 0, 0.1);
}
&:last-of-type {
border-top: 1px solid rgba(0, 0, 0, 0.1);
border-bottom: 1px solid rgba(0, 0, 0, 0.1);
border-bottom-left-radius: 10px;
border-bottom-right-radius: 10px;
}
.info {
.key {
font-size: 14px;
font-weight: bold;
display: inline-block;
padding: 3px;
padding-left: 0;
}
.type {
font-size: 14px;
display: inline-block;
padding: 3px;
}
}
}
}
}
}
}
}
</style>
<style lang="scss">
#document-response-item {
.el-collapse-item__header {
border: none;
background: none;
}
}
</style>
-93
View File
@@ -1,93 +0,0 @@
<template>
<div class="wrapper">
<div class="operation mb-2">
<el-button class="btn-try" type="primary" :loading="loading" @click="onTry">{{
$t('common.button.try')
}}</el-button>
</div>
<div v-if="responseData" class="result">
<div class="title">{{ $t('api.entity.response') }}</div>
<code-snippet :code="responseData" />
</div>
<div v-if="loading">
<el-skeleton animated />
</div>
</div>
</template>
<script lang="ts">
import { IApi, IForm } from '@/operators/api/models';
import { defineComponent } from 'vue';
import axios, { Method } from 'axios';
import urlJoin from 'url-join';
import CodeSnippet from '../common/CodeSnippet.vue';
import { ElButton, ElSkeleton } from 'element-plus';
export default defineComponent({
name: 'ApiTry',
components: {
CodeSnippet,
ElButton,
ElSkeleton
},
props: {
api: {
type: Object as () => IApi,
required: true
},
form: {
type: Object as () => IForm,
required: true
}
},
data() {
return {
apiKeyValue: this.apiKey,
responseData: '',
loading: false
};
},
methods: {
onTry() {
this.loading = true;
this.responseData = '';
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 }
};
axios(config)
.then((response) => {
this.loading = false;
this.responseData = JSON.stringify(response?.data, null, ' ');
})
.catch((error) => {
this.loading = false;
this.responseData = JSON.stringify(error?.response?.data, null, ' ');
});
}
}
});
</script>
<style lang="scss" scoped>
.wrapper {
margin-top: 15px;
padding-bottom: 0;
.operation {
margin-bottom: 10px;
.btn-try {
width: 100%;
}
}
.result {
margin-bottom: 10px;
.title {
font-size: 12px;
margin-bottom: 10px;
}
}
}
</style>
-132
View File
@@ -1,132 +0,0 @@
<template>
<div class="item">
<div v-if="api?.request?.queries" class="queries">
<h2 class="title">{{ $t('api.entity.requestQueries') }}</h2>
<api-form
v-model:form="formValue.queries"
:schema="api?.request?.queries"
:api="api"
:applied="applied"
:applications="applications"
@refresh-applications="getApplications"
/>
</div>
<div v-if="api?.request?.headers" class="headers">
<h2 class="title">{{ $t('api.entity.requestHeaders') }}</h2>
<api-form
v-model:form="formValue.headers"
:schema="api?.request?.headers"
:api="api"
:applications="applications"
/>
</div>
<div v-if="api?.request?.body" class="body">
<h2 class="title">{{ $t('api.entity.requestBody') }}</h2>
<api-form v-model:form="formValue.body" :schema="api?.request?.body" :api="api" :applications="applications" />
</div>
<div v-if="api?.responses" class="responses">
<h2 class="title">{{ $t('api.entity.response') }}</h2>
<api-responses :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 ApiResponses from './Responses.vue';
import { applicationOperator } from '@/operators/application/operator';
import { IApplication, IApplicationListResponse } from '@/operators/application/models';
export interface IData {
formValue: IForm;
applications: IApplication[];
applied: boolean | undefined;
}
export default defineComponent({
name: 'ApiUsage',
components: {
ApiForm,
ApiResponses
},
props: {
api: {
type: Object as () => IApi,
required: true
},
form: {
type: Object as () => IForm,
required: true
}
},
emits: ['update:form'],
data(): IData {
return {
formValue: this.form || {},
applications: [],
applied: undefined
};
},
watch: {
formValue: {
handler(val) {
this.$emit('update:form', { ...val });
},
deep: true
}
},
mounted() {},
methods: {
getApplications() {
applicationOperator
.getAll({
user_id: this.$store.getters.user?.id,
api_id: this.api.id
})
.then(({ data: data }: { data: IApplicationListResponse }) => {
this.applications = data.items;
this.applied = this.applications.filter((item) => item?.api?.id === this.api.id).length > 0;
})
.catch((error) => {});
}
}
});
</script>
<style lang="scss" scoped>
.item {
.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>