From deac35704095223adba9a2637502ba43a4a98a11 Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Thu, 21 Jan 2021 18:26:31 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E5=AE=9A=E4=B9=89):=20?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E6=8E=A5=E5=8F=A3=E6=97=B6=E4=B8=8D=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E5=8E=9F=E6=8E=A5=E5=8F=A3=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/definition/ApiDefinition.vue | 13 +++++----- .../api/definition/components/ApiConfig.vue | 11 +++++---- .../complete/EditCompleteDubboApi.vue | 22 +++++++++++++++++ .../complete/EditCompleteHTTPApi.vue | 24 ++++++++++++++++++- .../complete/EditCompleteSQLApi.vue | 22 ++++++++++++++++- .../complete/EditCompleteTCPApi.vue | 24 +++++++++++++++++-- .../components/runtest/RunTestDubboPage.vue | 8 +++++-- .../components/runtest/RunTestHTTPPage.vue | 8 +++++-- .../components/runtest/RunTestSQLPage.vue | 8 +++++-- .../components/runtest/RunTestTCPPage.vue | 8 +++++-- 10 files changed, 125 insertions(+), 23 deletions(-) diff --git a/frontend/src/business/components/api/definition/ApiDefinition.vue b/frontend/src/business/components/api/definition/ApiDefinition.vue index 48b9496ea3..6629c9ae86 100644 --- a/frontend/src/business/components/api/definition/ApiDefinition.vue +++ b/frontend/src/business/components/api/definition/ApiDefinition.vue @@ -57,7 +57,7 @@
- @@ -76,13 +76,13 @@
- - - -
@@ -184,7 +184,8 @@ type: "list", closable: false }], - isApiListEnable: true + isApiListEnable: true, + syncTabs: [], } }, watch: { diff --git a/frontend/src/business/components/api/definition/components/ApiConfig.vue b/frontend/src/business/components/api/definition/components/ApiConfig.vue index 393c6e780a..e34b9a4838 100644 --- a/frontend/src/business/components/api/definition/components/ApiConfig.vue +++ b/frontend/src/business/components/api/definition/components/ApiConfig.vue @@ -3,16 +3,16 @@
+ :basisData="currentApi" :moduleOptions="moduleOptions" :syncTabs="syncTabs" v-if="currentProtocol === 'HTTP'"/> + :moduleOptions="moduleOptions" :syncTabs="syncTabs" v-if="currentProtocol === 'TCP'"/> + :moduleOptions="moduleOptions" :syncTabs="syncTabs" v-if="currentProtocol === 'DUBBO'"/> + :moduleOptions="moduleOptions" :syncTabs="syncTabs" v-if="currentProtocol === 'SQL'"/>
@@ -45,6 +45,7 @@ currentApi: {}, moduleOptions: {}, currentProtocol: String, + syncTabs: Array, }, created() { this.projectId = getCurrentProjectID(); @@ -75,7 +76,7 @@ this.$emit('runTest', data); }) }, - createRootModelInTree(){ + createRootModelInTree() { this.$emit("createRootModel"); }, getMaintainerOptions() { diff --git a/frontend/src/business/components/api/definition/components/complete/EditCompleteDubboApi.vue b/frontend/src/business/components/api/definition/components/complete/EditCompleteDubboApi.vue index d73e1ad2ba..ffecc7cd01 100644 --- a/frontend/src/business/components/api/definition/components/complete/EditCompleteDubboApi.vue +++ b/frontend/src/business/components/api/definition/components/complete/EditCompleteDubboApi.vue @@ -44,8 +44,30 @@ isReadOnly: { type: Boolean, default: false + }, + syncTabs: Array, + }, + watch: { + syncTabs() { + if (this.basisData && this.syncTabs && this.syncTabs.includes(this.basisData.id)) { + // 标示接口在其他地方更新过,当前页面需要同步 + let url = "/api/definition/get/"; + this.$get(url + this.basisData.id, response => { + if (response.data) { + let request = JSON.parse(response.data.request); + let index = this.syncTabs.findIndex(item => { + if (item === this.basisData.id) { + return true; + } + }) + this.syncTabs.splice(index, 1); + Object.assign(this.request, request); + } + }); + } } }, + data() { return {validated: false} }, diff --git a/frontend/src/business/components/api/definition/components/complete/EditCompleteHTTPApi.vue b/frontend/src/business/components/api/definition/components/complete/EditCompleteHTTPApi.vue index 9a7a4f74f7..6f4415ee65 100644 --- a/frontend/src/business/components/api/definition/components/complete/EditCompleteHTTPApi.vue +++ b/frontend/src/business/components/api/definition/components/complete/EditCompleteHTTPApi.vue @@ -149,7 +149,29 @@ options: API_STATUS, } }, - props: {moduleOptions: {}, request: {}, response: {}, basisData: {}}, + props: {moduleOptions: {}, request: {}, response: {}, basisData: {}, syncTabs: Array}, + watch: { + syncTabs() { + if (this.basisData && this.syncTabs && this.syncTabs.includes(this.basisData.id)) { + // 标示接口在其他地方更新过,当前页面需要同步 + let url = "/api/definition/get/"; + this.$get(url + this.basisData.id, response => { + if (response.data) { + let request = JSON.parse(response.data.request); + let index = this.syncTabs.findIndex(item => { + if (item === this.basisData.id) { + return true; + } + }) + this.syncTabs.splice(index, 1); + this.httpForm.path = response.data.path; + this.httpForm.method = response.data.method; + Object.assign(this.request, request); + } + }); + } + } + }, methods: { runTest() { this.$refs['httpForm'].validate((valid) => { diff --git a/frontend/src/business/components/api/definition/components/complete/EditCompleteSQLApi.vue b/frontend/src/business/components/api/definition/components/complete/EditCompleteSQLApi.vue index 2053db88bd..0b0bb5699e 100644 --- a/frontend/src/business/components/api/definition/components/complete/EditCompleteSQLApi.vue +++ b/frontend/src/business/components/api/definition/components/complete/EditCompleteSQLApi.vue @@ -43,9 +43,29 @@ export default { isReadOnly: { type: Boolean, default: false + }, + syncTabs:{}, + }, + watch: { + syncTabs() { + if (this.basisData && this.syncTabs && this.syncTabs.includes(this.basisData.id)) { + // 标示接口在其他地方更新过,当前页面需要同步 + let url = "/api/definition/get/"; + this.$get(url + this.basisData.id, response => { + if (response.data) { + let request = JSON.parse(response.data.request); + let index = this.syncTabs.findIndex(item => { + if (item === this.basisData.id) { + return true; + } + }) + this.syncTabs.splice(index, 1); + Object.assign(this.request, request); + } + }); + } } }, - data() { return {validated: false} }, diff --git a/frontend/src/business/components/api/definition/components/complete/EditCompleteTCPApi.vue b/frontend/src/business/components/api/definition/components/complete/EditCompleteTCPApi.vue index dcc4078c9c..e2f0eb4a61 100644 --- a/frontend/src/business/components/api/definition/components/complete/EditCompleteTCPApi.vue +++ b/frontend/src/business/components/api/definition/components/complete/EditCompleteTCPApi.vue @@ -42,14 +42,34 @@ export default { isReadOnly: { type: Boolean, default: false - } + }, + syncTabs:Array, }, data() { return { validated: false, } }, - + watch: { + syncTabs() { + if (this.basisData && this.syncTabs && this.syncTabs.includes(this.basisData.id)) { + // 标示接口在其他地方更新过,当前页面需要同步 + let url = "/api/definition/get/"; + this.$get(url + this.basisData.id, response => { + if (response.data) { + let request = JSON.parse(response.data.request); + let index = this.syncTabs.findIndex(item => { + if (item === this.basisData.id) { + return true; + } + }) + this.syncTabs.splice(index, 1); + Object.assign(this.request, request); + } + }); + } + } + }, methods: { callback() { this.validated = true; diff --git a/frontend/src/business/components/api/definition/components/runtest/RunTestDubboPage.vue b/frontend/src/business/components/api/definition/components/runtest/RunTestDubboPage.vue index 8d994e251c..8b1aa32bc4 100644 --- a/frontend/src/business/components/api/definition/components/runtest/RunTestDubboPage.vue +++ b/frontend/src/business/components/api/definition/components/runtest/RunTestDubboPage.vue @@ -89,7 +89,7 @@ reportId: "", } }, - props: {apiData: {}, currentProtocol: String,}, + props: {apiData: {}, currentProtocol: String,syncTabs: Array}, methods: { handleCommand(e) { switch (e) { @@ -173,6 +173,9 @@ let bodyFiles = this.getBodyUploadFiles(); this.$fileUpload(url, null, bodyFiles, this.api, () => { this.$success(this.$t('commons.save_success')); + if (this.syncTabs.indexOf(this.api.id) === -1) { + this.syncTabs.push(this.api.id); + } this.$emit('saveApi', this.api); }); }, @@ -228,7 +231,8 @@ } }, created() { - this.api = this.apiData; + // 深度复制 + this.api = JSON.parse(JSON.stringify(this.apiData)); this.api.protocol = this.currentProtocol; this.currentRequest = this.api.request; this.getEnvironments(); diff --git a/frontend/src/business/components/api/definition/components/runtest/RunTestHTTPPage.vue b/frontend/src/business/components/api/definition/components/runtest/RunTestHTTPPage.vue index 81196904cf..363ad44b8c 100644 --- a/frontend/src/business/components/api/definition/components/runtest/RunTestHTTPPage.vue +++ b/frontend/src/business/components/api/definition/components/runtest/RunTestHTTPPage.vue @@ -113,7 +113,7 @@ projectId: "", } }, - props: {apiData: {}, currentProtocol: String,}, + props: {apiData: {}, currentProtocol: String, syncTabs: Array}, methods: { handleCommand(e) { switch (e) { @@ -205,6 +205,9 @@ this.$fileUpload(url, null, bodyFiles, this.api, () => { this.$success(this.$t('commons.save_success')); this.$emit('saveApi', this.api); + if (this.syncTabs.indexOf(this.api.id) === -1) { + this.syncTabs.push(this.api.id); + } }); }, selectTestCase(item) { @@ -230,7 +233,8 @@ }, created() { this.projectId = getCurrentProjectID(); - this.api = this.apiData; + // 深度复制 + this.api = JSON.parse(JSON.stringify(this.apiData)); this.api.protocol = this.currentProtocol; this.currentRequest = this.api.request; this.getResult(); diff --git a/frontend/src/business/components/api/definition/components/runtest/RunTestSQLPage.vue b/frontend/src/business/components/api/definition/components/runtest/RunTestSQLPage.vue index 4a68528d77..c58872bb76 100644 --- a/frontend/src/business/components/api/definition/components/runtest/RunTestSQLPage.vue +++ b/frontend/src/business/components/api/definition/components/runtest/RunTestSQLPage.vue @@ -89,7 +89,7 @@ reportId: "", } }, - props: {apiData: {}, currentProtocol: String,}, + props: {apiData: {}, currentProtocol: String,syncTabs: Array}, methods: { handleCommand(e) { switch (e) { @@ -172,6 +172,9 @@ let bodyFiles = this.getBodyUploadFiles(); this.$fileUpload(url, null, bodyFiles, this.api, () => { this.$success(this.$t('commons.save_success')); + if (this.syncTabs.indexOf(this.api.id) === -1) { + this.syncTabs.push(this.api.id); + } this.$emit('saveApi', this.api); }); }, @@ -227,7 +230,8 @@ } }, created() { - this.api = this.apiData; + // 深度复制 + this.api = JSON.parse(JSON.stringify(this.apiData)); this.api.protocol = this.currentProtocol; this.currentRequest = this.api.request; this.getEnvironments(); diff --git a/frontend/src/business/components/api/definition/components/runtest/RunTestTCPPage.vue b/frontend/src/business/components/api/definition/components/runtest/RunTestTCPPage.vue index 50545940e1..3a5644a915 100644 --- a/frontend/src/business/components/api/definition/components/runtest/RunTestTCPPage.vue +++ b/frontend/src/business/components/api/definition/components/runtest/RunTestTCPPage.vue @@ -90,7 +90,7 @@ projectId: "" } }, - props: {apiData: {}, currentProtocol: String,}, + props: {apiData: {}, currentProtocol: String,syncTabs: Array}, methods: { handleCommand(e) { switch (e) { @@ -173,6 +173,9 @@ let bodyFiles = this.getBodyUploadFiles(); this.$fileUpload(url, null, bodyFiles, this.api, () => { this.$success(this.$t('commons.save_success')); + if (this.syncTabs.indexOf(this.api.id) === -1) { + this.syncTabs.push(this.api.id); + } this.$emit('saveApi', this.api); }); }, @@ -194,7 +197,8 @@ } }, created() { - this.api = this.apiData; + // 深度复制 + this.api = JSON.parse(JSON.stringify(this.apiData)); this.api.protocol = this.currentProtocol; this.currentRequest = this.api.request; this.projectId = getCurrentProjectID();