diff --git a/src/components/api/Form.vue b/src/components/api/Form.vue index 2dc4809b..92d96f26 100644 --- a/src/components/api/Form.vue +++ b/src/components/api/Form.vue @@ -13,17 +13,31 @@
- + +

{{ $t('application.message.notApplied') }}

+ {{ $t('common.button.apply') }}
+ + + {{ appliedApplication?.api_key }} + {{ $t('application.message.yourApplication') }} + +
import { defineComponent } from 'vue'; import { ISchema } from '@/operators/api/models'; +import { IService } from '@/operators/service/models'; +import { applicationOperator, IApplication, IApplicationListResponse } from '@/operators'; +import application from '@/i18n/zh/application'; interface IData { value: { @@ -57,6 +74,14 @@ export default defineComponent({ schema: { type: Object as () => ISchema | undefined, required: true + }, + service: { + type: Object as () => IService | undefined, + required: true + }, + applications: { + type: Array as () => IApplication[], + required: true } }, emits: ['update:form'], @@ -65,6 +90,18 @@ export default defineComponent({ value: {} }; }, + computed: { + isApplied() { + return this.applications.filter((application) => application.service?.id === this.service?.id).length > 0; + }, + appliedApplication(): IApplication | undefined { + const applications = this.applications.filter((application) => application.service?.id === this.service?.id); + if (applications.length > 0) { + return applications[0]; + } + return undefined; + } + }, watch: { value: { handler() { @@ -146,4 +183,18 @@ export default defineComponent({ } } } +.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; + } + } +} diff --git a/src/components/api/Usage.vue b/src/components/api/Usage.vue index e069997f..6e18f62e 100644 --- a/src/components/api/Usage.vue +++ b/src/components/api/Usage.vue @@ -18,15 +18,30 @@

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

- +

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

- +

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

- +

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

@@ -41,9 +56,12 @@ 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 | undefined; + formValue: IForm; + applications: IApplication[]; } export default defineComponent({ @@ -67,9 +85,10 @@ export default defineComponent({ } }, emits: ['update:form'], - data() { + data(): IData { return { - formValue: this.form + formValue: this.form || {}, + applications: [] }; }, watch: { @@ -80,8 +99,20 @@ export default defineComponent({ deep: true } }, + mounted() { + this.getApplications(); + }, methods: { - urlJoin + urlJoin, + getApplications() { + applicationOperator + .getAll({ + user_id: this.$store.getters.user.id + }) + .then(({ data: data }: { data: IApplicationListResponse }) => { + this.applications = data.items; + }); + } } }); diff --git a/src/i18n/zh/application/message.ts b/src/i18n/zh/application/message.ts index 7dfe34bb..6437637f 100644 --- a/src/i18n/zh/application/message.ts +++ b/src/i18n/zh/application/message.ts @@ -1,4 +1,6 @@ export default { alreadyApplied: '已经申请过该服务,请到控制台查看', - applySuccessfully: '申请成功,即将跳转到控制台' + applySuccessfully: '申请成功,即将跳转到控制台', + notApplied: '你尚未申请过该服务,请先申请该服务之后使用', + yourApplication: '你的申请' }; diff --git a/src/operators/api/models.ts b/src/operators/api/models.ts index 108754cc..5cd930d4 100644 --- a/src/operators/api/models.ts +++ b/src/operators/api/models.ts @@ -1,3 +1,5 @@ +import { IService } from '../service'; + export interface IForm { queries?: { [key: string]: string; @@ -54,7 +56,8 @@ export interface IApi { responses: IResponse[]; response_ids: string[]; is_free?: boolean; - service?: string; + service?: IService; + service_id?: string; created_at?: string; updated_at?: string; }