From c357870ece62276b045342b987c06ceef583d49b Mon Sep 17 00:00:00 2001 From: shiziyuan9527 Date: Fri, 13 Aug 2021 15:01:16 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E6=8E=A5=E5=8F=A3=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E6=B5=8B=E8=AF=95=E5=A2=9E=E5=8A=A0=E5=81=9C=E6=AD=A2?= =?UTF-8?q?=E6=8C=89=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/runtest/RunTestDubboPage.vue | 376 +++++++++--------- .../components/runtest/RunTestHTTPPage.vue | 25 +- .../components/runtest/RunTestSQLPage.vue | 23 +- .../components/runtest/RunTestTCPPage.vue | 27 +- 4 files changed, 256 insertions(+), 195 deletions(-) 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 b810a79874..f857010390 100644 --- a/frontend/src/business/components/api/definition/components/runtest/RunTestDubboPage.vue +++ b/frontend/src/business/components/api/definition/components/runtest/RunTestDubboPage.vue @@ -1,30 +1,30 @@ @@ -67,28 +67,29 @@ export default { MsRun, MsBasisParameters, MsJmxStep - }, - data() { - return { - visible: false, - api: {}, - loaded: false, - loading: false, - currentRequest: {}, - createCase: "", - refreshSign: "", - responseData: {type: 'HTTP', responseResult: {}, subRequestResults: []}, - reqOptions: REQ_METHOD, - environments: [], - rules: { - method: [{required: true, message: this.$t('test_track.case.input_maintainer'), trigger: 'change'}], - url: [{required: true, message: this.$t('api_test.definition.request.path_info'), trigger: 'blur'}], - environmentId: [{required: true, message: this.$t('api_test.definition.request.run_env'), trigger: 'change'}], - }, - runData: [], - reportId: "", - } - }, + }, + data() { + return { + visible: false, + api: {}, + loaded: false, + loading: false, + currentRequest: {}, + createCase: "", + refreshSign: "", + responseData: {type: 'HTTP', responseResult: {}, subRequestResults: []}, + reqOptions: REQ_METHOD, + environments: [], + rules: { + method: [{required: true, message: this.$t('test_track.case.input_maintainer'), trigger: 'change'}], + url: [{required: true, message: this.$t('api_test.definition.request.path_info'), trigger: 'blur'}], + environmentId: [{required: true, message: this.$t('api_test.definition.request.run_env'), trigger: 'change'}], + }, + runData: [], + reportId: "", + runLoading: false + } + }, props: {apiData: {}, currentProtocol: String, syncTabs: Array, projectId: String}, methods: { handleCommand(e) { @@ -100,169 +101,184 @@ export default { case "update_api": return this.updateApi(); case "save_as_api": - return this.saveAsApi(); - default: - return this.runTest(); - } - }, + return this.saveAsApi(); + default: + return this.runTest(); + } + }, refresh() { this.$emit('refresh'); }, - runTest() { - this.loading = true; - this.api.request.name = this.api.id; - this.api.protocol = this.currentProtocol; - this.runData = []; - this.runData.push(this.api.request); - /*触发执行操作*/ - this.reportId = getUUID().substring(0, 8); - }, - runRefresh(data) { - this.responseData = data; - this.loading = false; - }, - saveAs() { - this.$emit('saveAs', this.api); - }, - loadCase() { - this.refreshSign = getUUID(); - this.$refs.caseList.open(); - this.visible = true; - }, - apiCaseClose() { - this.visible = false; - }, - getBodyUploadFiles() { - let bodyUploadFiles = []; - this.api.bodyUploadIds = []; - let request = this.api.request; - if (request.body) { - request.body.kvs.forEach(param => { - if (param.files) { - param.files.forEach(item => { - if (item.file) { - let fileId = getUUID().substring(0, 8); - item.name = item.file.name; - item.id = fileId; - this.api.bodyUploadIds.push(fileId); - bodyUploadFiles.push(item.file); - } - }); - } - }); - } - return bodyUploadFiles; - }, - saveAsCase() { - //用于触发创建操作 - this.createCase = getUUID(); - this.$refs.caseList.open(); - this.loaded = false; - }, - saveAsApi() { - let data = {}; - let req = this.api.request; - req.id = getUUID(); - data.request = JSON.stringify(req); - data.method = this.api.method; - data.status = this.api.status; - data.userId = this.api.userId; - data.description = this.api.description; - this.$emit('saveAsApi', data); - this.$emit('refresh'); - }, - updateApi() { - let url = "/api/definition/update"; - let bodyFiles = this.getBodyUploadFiles(); - if (Object.prototype.toString.call(this.api.response).match(/\[object (\w+)\]/)[1].toLowerCase() !== 'object') { - this.api.response = JSON.parse(this.api.response); - } - if (this.api.tags instanceof Array) { - this.api.tags = JSON.stringify(this.api.tags); - } - 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); - }); - }, - selectTestCase(item) { - if (item != null) { - this.api.request = item.request; - } else { - this.api.request = this.currentRequest; - } - }, - getEnvironments() { - this.$get('/api/environment/list/' + this.projectId, response => { - this.environments = response.data; - this.environments.forEach(environment => { - parseEnvironment(environment); - }); - let hasEnvironment = false; - for (let i in this.environments) { - if (this.environments[i].id === this.api.environmentId) { - this.api.environment = this.environments[i]; - hasEnvironment = true; - break; - } - } - if (!hasEnvironment) { - this.api.environmentId = ''; - this.api.environment = undefined; + runTest() { + this.runLoading = true; + this.loading = true; + this.api.request.name = this.api.id; + this.api.protocol = this.currentProtocol; + this.runData = []; + this.runData.push(this.api.request); + /*触发执行操作*/ + this.reportId = getUUID().substring(0, 8); + }, + runRefresh(data) { + this.responseData = data; + this.loading = false; + this.runLoading = false; + }, + errorRefresh() { + this.loading = false; + this.runLoading = false; + }, + saveAs() { + this.$emit('saveAs', this.api); + }, + loadCase() { + this.refreshSign = getUUID(); + this.$refs.caseList.open(); + this.visible = true; + }, + apiCaseClose() { + this.visible = false; + }, + getBodyUploadFiles() { + let bodyUploadFiles = []; + this.api.bodyUploadIds = []; + let request = this.api.request; + if (request.body) { + request.body.kvs.forEach(param => { + if (param.files) { + param.files.forEach(item => { + if (item.file) { + let fileId = getUUID().substring(0, 8); + item.name = item.file.name; + item.id = fileId; + this.api.bodyUploadIds.push(fileId); + bodyUploadFiles.push(item.file); + } + }); } }); - }, - openEnvironmentConfig() { - this.$refs.environmentConfig.open(this.projectId); - }, - environmentChange(value) { + } + return bodyUploadFiles; + }, + saveAsCase() { + //用于触发创建操作 + this.createCase = getUUID(); + this.$refs.caseList.open(); + this.loaded = false; + }, + saveAsApi() { + let data = {}; + let req = this.api.request; + req.id = getUUID(); + data.request = JSON.stringify(req); + data.method = this.api.method; + data.status = this.api.status; + data.userId = this.api.userId; + data.description = this.api.description; + this.$emit('saveAsApi', data); + this.$emit('refresh'); + }, + updateApi() { + let url = "/api/definition/update"; + let bodyFiles = this.getBodyUploadFiles(); + if (Object.prototype.toString.call(this.api.response).match(/\[object (\w+)\]/)[1].toLowerCase() !== 'object') { + this.api.response = JSON.parse(this.api.response); + } + if (this.api.tags instanceof Array) { + this.api.tags = JSON.stringify(this.api.tags); + } + 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); + }); + }, + selectTestCase(item) { + if (item != null) { + this.api.request = item.request; + } else { + this.api.request = this.currentRequest; + } + }, + getEnvironments() { + this.$get('/api/environment/list/' + this.projectId, response => { + this.environments = response.data; + this.environments.forEach(environment => { + parseEnvironment(environment); + }); + let hasEnvironment = false; for (let i in this.environments) { - if (this.environments[i].id === value) { - this.api.request.useEnvironment = this.environments[i].id; + if (this.environments[i].id === this.api.environmentId) { + this.api.environment = this.environments[i]; + hasEnvironment = true; break; } } - }, - environmentConfigClose() { - this.getEnvironments(); - }, - getResult() { - if (this.api.id) { - let url = "/api/definition/report/getReport/" + this.api.id; - this.$get(url, response => { - if (response.data) { - let data = JSON.parse(response.data.content); - this.responseData = data; - } - }); + if (!hasEnvironment) { + this.api.environmentId = ''; + this.api.environment = undefined; + } + }); + }, + openEnvironmentConfig() { + this.$refs.environmentConfig.open(this.projectId); + }, + environmentChange(value) { + for (let i in this.environments) { + if (this.environments[i].id === value) { + this.api.request.useEnvironment = this.environments[i].id; + break; } } }, - created() { - // 深度复制 - this.api = JSON.parse(JSON.stringify(this.apiData)); - this.api.protocol = this.currentProtocol; - this.currentRequest = this.api.request; + environmentConfigClose() { this.getEnvironments(); - this.getResult(); - } + }, + getResult() { + if (this.api.id) { + let url = "/api/definition/report/getReport/" + this.api.id; + this.$get(url, response => { + if (response.data) { + let data = JSON.parse(response.data.content); + this.responseData = data; + } + }); + } + }, + stop() { + let url = "/api/automation/stop/" + this.reportId; + this.$get(url, () => { + this.runLoading = false; + this.loading = false; + this.$success(this.$t('report.test_stop_success')); + }); + }, + }, + created() { + // 深度复制 + this.api = JSON.parse(JSON.stringify(this.apiData)); + this.api.protocol = this.currentProtocol; + this.currentRequest = this.api.request; + this.runLoading = false; + this.getEnvironments(); + this.getResult(); } +} 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 270fcde2fc..721b67ad0d 100644 --- a/frontend/src/business/components/api/definition/components/runtest/RunTestHTTPPage.vue +++ b/frontend/src/business/components/api/definition/components/runtest/RunTestHTTPPage.vue @@ -1,7 +1,7 @@