From d3b41b1caa08199c9379d077eac345b6e3f15be6 Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Tue, 26 Apr 2022 10:39:47 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=8E=A5=E5=8F=A3=E5=AE=9A=E4=B9=89=E5=92=8C?= =?UTF-8?q?=E7=94=A8=E4=BE=8B=E6=B7=BB=E5=8A=A0=E6=AD=A5=E9=AA=A4=E6=97=B6?= =?UTF-8?q?=E7=BB=A7=E6=89=BF=E5=BD=93=E5=89=8D=E8=AF=B7=E6=B1=82=E7=9A=84?= =?UTF-8?q?=E7=8E=AF=E5=A2=83=E5=92=8C=E6=95=B0=E6=8D=AE=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/case/ApiCaseList.vue | 48 +++++++++++++++---- .../definition/components/step/JmxStep.vue | 13 +++++ 2 files changed, 52 insertions(+), 9 deletions(-) diff --git a/frontend/src/business/components/api/definition/components/case/ApiCaseList.vue b/frontend/src/business/components/api/definition/components/case/ApiCaseList.vue index 2b1fe054c7..51119a8603 100644 --- a/frontend/src/business/components/api/definition/components/case/ApiCaseList.vue +++ b/frontend/src/business/components/api/definition/components/case/ApiCaseList.vue @@ -100,11 +100,12 @@ export default { api: {}, envMap: new Map, maintainerOptions: [], + environments: [] }; }, watch: { '$store.state.useEnvironment': function () { - this.environment = this.$store.state.useEnvironment; + this.setEnvironment(this.$store.state.useEnvironment); }, refreshSign() { this.api = this.currentApi; @@ -289,13 +290,43 @@ export default { refreshModule() { this.$emit('refreshModule'); }, - setEnvironments(obj) { - this.$get('/api/environment/list/' + this.projectId, response => { - let environments = response.data; - this.getTargetSource(environments, obj); - }); + setNewSource(environment, obj) { + if (environment.config && environment.config.databaseConfigs) { + let dataSources = environment.config.databaseConfigs.filter(item => item.name === obj.targetDataSourceName); + if (dataSources && dataSources.length > 0) { + obj.dataSourceId = dataSources[0].id; + } else { + obj.dataSourceId = environment.config.databaseConfigs[0].id; + } + } }, - getTargetSource(environments, obj) { + getEnvironments(obj, env) { + if (this.environments.length === 0) { + this.$get('/api/environment/list/' + this.projectId, response => { + this.environments = response.data; + // 获取原数据源名称 + this.getTargetSourceName(this.environments, obj); + // 设置新环境 + obj.environmentId = env; + // 设置新数据源 + let envs = this.environments.filter(tab => tab.id === env); + if (envs && envs.length > 0) { + this.setNewSource(envs[0], obj); + } + }); + } else { + // 获取原数据源名称 + this.getTargetSourceName(this.environments, obj); + // 设置新环境 + obj.environmentId = env; + // 设置新数据源 + let envs = this.environments.filter(tab => tab.id === env); + if (envs && envs.length > 0) { + this.setNewSource(envs[0], obj); + } + } + }, + getTargetSourceName(environments, obj) { environments.forEach(environment => { parseEnvironment(environment); // 找到原始环境和数据源名称 @@ -314,8 +345,7 @@ export default { for (let i in scenarioDefinition) { let typeArray = ["JDBCPostProcessor", "JDBCSampler", "JDBCPreProcessor"] if (typeArray.indexOf(scenarioDefinition[i].type) !== -1) { - this.setEnvironments(scenarioDefinition[i]); - scenarioDefinition[i].environmentId = env; + this.getEnvironments(scenarioDefinition[i], env); } if (scenarioDefinition[i].hashTree !== undefined && scenarioDefinition[i].hashTree.length > 0) { this.setOwnEnvironment(scenarioDefinition[i].hashTree, env); diff --git a/frontend/src/business/components/api/definition/components/step/JmxStep.vue b/frontend/src/business/components/api/definition/components/step/JmxStep.vue index 17ff6d739d..55b5d034da 100644 --- a/frontend/src/business/components/api/definition/components/step/JmxStep.vue +++ b/frontend/src/business/components/api/definition/components/step/JmxStep.vue @@ -249,9 +249,22 @@ export default { } else { this.addAssertions(); } + // 继承请求中的环境和数据源 + if (this.request.hashTree && this.request.hashTree.length > 0) { + this.setOwnEnvironment(this.request.hashTree); + } this.sort(); this.reload(); }, + setOwnEnvironment(scenarioDefinition) { + for (let i in scenarioDefinition) { + let typeArray = ["JDBCPostProcessor", "JDBCSampler", "JDBCPreProcessor"] + if (typeArray.indexOf(scenarioDefinition[i].type) !== -1) { + scenarioDefinition[i].environmentId = this.request.environmentId; + scenarioDefinition[i].dataSourceId = this.request.dataSourceId; + } + } + }, filterNode(value, data) { if (data.type && value.indexOf(data.type) !== -1) { return true;