From b55ace7c8e2bd8dce842d2eef947e540b3695e48 Mon Sep 17 00:00:00 2001
From: AceDataCloud
Date: Tue, 31 Jan 2023 16:37:49 +0800
Subject: [PATCH] fix error
---
src/components/api/Form.vue | 42 ++++++++++++++++++++----------------
src/components/api/Usage.vue | 11 +++-------
2 files changed, 26 insertions(+), 27 deletions(-)
diff --git a/src/components/api/Form.vue b/src/components/api/Form.vue
index 46c6563b..bd1a7cec 100644
--- a/src/components/api/Form.vue
+++ b/src/components/api/Form.vue
@@ -19,18 +19,7 @@
{{ $t('application.message.notApplied') }}
-
- {{ $t('common.button.apply') }}
-
+ {{ $t('common.button.apply') }}
import { defineComponent } from 'vue';
import { ISchema } from '@/operators/api/models';
-import { IService } from '@/operators/service/models';
-import { IApplication } from '@/operators';
+import { applicationOperator, IApi, IApplication, IApplicationType } from '@/operators';
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
-import { ElPopover, ElInput, ElSelect, ElButton, ElTooltip, ElOption } from 'element-plus';
+import { ElPopover, ElInput, ElSelect, ElButton, ElTooltip, ElOption, ElMessage } from 'element-plus';
+import { ERROR_CODE_DUPLICATION } from '@/constants/errorCode';
interface IData {
value: {
@@ -116,8 +105,8 @@ export default defineComponent({
type: Object as () => ISchema | undefined,
required: true
},
- service: {
- type: Object as () => IService | undefined,
+ api: {
+ type: Object as () => IApi | undefined,
required: true
},
applications: {
@@ -133,10 +122,10 @@ export default defineComponent({
},
computed: {
isApplied() {
- return this.applications.filter((application) => application.service?.id === this.service?.id).length > 0;
+ return this.applications.filter((application) => application.api?.id === this.api?.id).length > 0;
},
appliedApplication(): IApplication | undefined {
- const applications = this.applications.filter((application) => application.service?.id === this.service?.id);
+ const applications = this.applications.filter((application) => application.api?.id === this.api?.id);
if (applications.length > 0) {
return applications[0];
}
@@ -157,6 +146,21 @@ export default defineComponent({
},
onRefreshApplications() {
this.$emit('refresh-applications');
+ },
+ onApply() {
+ applicationOperator
+ .create({
+ type: IApplicationType.API,
+ api_id: this.api?.id
+ })
+ .then(() => {
+ this.$emit('refresh-applications');
+ })
+ .catch((error) => {
+ if (error?.response?.data?.code === ERROR_CODE_DUPLICATION) {
+ ElMessage.error(this.$t('application.message.alreadyApplied'));
+ }
+ });
}
}
});
diff --git a/src/components/api/Usage.vue b/src/components/api/Usage.vue
index 070acc48..230aa8f9 100644
--- a/src/components/api/Usage.vue
+++ b/src/components/api/Usage.vue
@@ -12,7 +12,7 @@
@@ -22,18 +22,13 @@
{{ $t('api.entity.requestBody') }}
-
+
{{ $t('api.entity.response') }}