From 3edaefef087e9393ef8d87d678f5cf8895dd2dbe Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Mon, 25 Apr 2022 18:06:41 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=8E=A5=E5=8F=A3=E6=88=96=E7=94=A8=E4=BE=8B?= =?UTF-8?q?=E5=90=8C=E5=90=8D=E6=95=B0=E6=8D=AE=E6=BA=90=E5=8C=B9=E9=85=8D?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1012653 --user=赵勇 【接口测试】接口定义-接口case-添加前后置sql-切换运行环境-未使用同名的数据源 https://www.tapd.cn/55049933/s/1146978 --- .../scenario/common/JDBCProcessorContent.vue | 44 ++++++++----- .../components/case/ApiCaseHeader.vue | 5 +- .../components/case/ApiCaseList.vue | 41 ++++++++++++ .../environment/EnvironmentSelect.vue | 40 +++++++++++- .../request/database/BasisParameters.vue | 65 +++++++++++++++---- 5 files changed, 163 insertions(+), 32 deletions(-) diff --git a/frontend/src/business/components/api/automation/scenario/common/JDBCProcessorContent.vue b/frontend/src/business/components/api/automation/scenario/common/JDBCProcessorContent.vue index 85aeca6825..498365587d 100644 --- a/frontend/src/business/components/api/automation/scenario/common/JDBCProcessorContent.vue +++ b/frontend/src/business/components/api/automation/scenario/common/JDBCProcessorContent.vue @@ -117,9 +117,6 @@ export default { } }, created() { - if (!this.scenarioId) { - this.request.environmentId = this.$store.state.useEnvironment; - } this.getEnvironments(); }, computed: { @@ -128,16 +125,23 @@ export default { }, }, watch: { + // 场景环境监听 '$store.state.scenarioEnvMap': { handler(v) { this.getEnvironments(); }, deep: true }, + // 接口/用例 右上角公共环境监听 '$store.state.useEnvironment': function () { if (!this.scenarioId) { - this.request.environmentId = this.$store.state.useEnvironment; - this.getEnvironments(); + this.getEnvironments(this.$store.state.useEnvironment); + } + }, + // 接口/用例 自身环境监听 + 'request.environmentId': function () { + if (!this.scenarioId) { + this.initDataSource(undefined, undefined, this.request.targetDataSourceName); } }, }, @@ -173,29 +177,40 @@ export default { runTest() { }, - itselfEnvironment() { + itselfEnvironment(environmentId) { let id = this.request.projectId ? this.request.projectId : this.projectId; this.result = this.$get('/api/environment/list/' + id, response => { this.environments = response.data; + let targetDataSourceName = undefined; this.environments.forEach(environment => { parseEnvironment(environment); + // 找到原始环境和数据源名称 + if (environment.id === this.request.environmentId) { + if (environment.config && environment.config.databaseConfigs) { + environment.config.databaseConfigs.forEach(item => { + if (item.id === this.request.dataSourceId) { + targetDataSourceName = item.name; + } + }); + } + } }) - this.initDataSource(); + if (environmentId) { + this.request.environmentId = environmentId; + } + this.initDataSource(undefined, undefined, targetDataSourceName); }); }, - getEnvironments() { + getEnvironments(environmentId) { let envId = ""; let id = this.request.projectId ? this.request.projectId : this.projectId; - let scenarioEnvId = this.scenarioId ? (this.scenarioId + "_" + id) : id; + let scenarioEnvId = this.scenarioId !== "" ? (this.scenarioId + "_" + id) : id; if (this.$store.state.scenarioEnvMap && this.$store.state.scenarioEnvMap instanceof Map && this.$store.state.scenarioEnvMap.has(scenarioEnvId)) { envId = this.$store.state.scenarioEnvMap.get(scenarioEnvId); } - if (this.request.referenced === 'Created' && this.scenarioId && !this.request.isRefEnvironment) { - this.itselfEnvironment(); - return; - } else if (!this.scenarioId && !this.request.customizeReq) { - this.itselfEnvironment(); + if (!this.scenarioId && !this.request.customizeReq) { + this.itselfEnvironment(environmentId); return; } this.environments = []; @@ -292,7 +307,6 @@ export default { break; } } - this.databaseConfigsOptions = []; if (environment.config && environment.config.databaseConfigs) { environment.config.databaseConfigs.forEach(item => { diff --git a/frontend/src/business/components/api/definition/components/case/ApiCaseHeader.vue b/frontend/src/business/components/api/definition/components/case/ApiCaseHeader.vue index 31f22592b6..a9898d5a4e 100644 --- a/frontend/src/business/components/api/definition/components/case/ApiCaseHeader.vue +++ b/frontend/src/business/components/api/definition/components/case/ApiCaseHeader.vue @@ -20,7 +20,7 @@ :project-id="projectId" :is-read-only="isReadOnly" :useEnvironment='useEnvironment' - @setEnvironment="setEnvironment" ref="environmentSelect" v-if="api.protocol==='HTTP'"/> + @setEnvironment="setEnvironment" ref="environmentSelect" v-if="api.protocol==='HTTP' || api.protocol ==='TCP'"/> @@ -100,10 +100,9 @@ export default { setEnvironment(data) { if (data) { this.$emit('setEnvironment', data.id); - this.$store.state.scenarioEnvMap = new Map(); - this.$store.state.scenarioEnvMap.set(getCurrentProjectID(), data.id); } }, + open() { this.$refs.searchBar.open(); }, 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 b659a3b42e..2b1fe054c7 100644 --- a/frontend/src/business/components/api/definition/components/case/ApiCaseList.vue +++ b/frontend/src/business/components/api/definition/components/case/ApiCaseList.vue @@ -58,6 +58,7 @@ import {getCurrentProjectID, getUUID} from "@/common/js/utils"; import MsDrawer from "../../../../common/components/MsDrawer"; import {CASE_ORDER} from "../../model/JsonData"; import {API_CASE_CONFIGS} from "@/business/components/common/components/search/search-components"; +import {parseEnvironment} from "@/business/components/api/definition/model/EnvironmentModel"; export default { name: 'ApiCaseList', @@ -223,6 +224,13 @@ export default { }); }, setEnvironment(environment) { + if (this.environment !== environment) { + if (this.apiCaseList && this.apiCaseList.length > 0) { + if (this.apiCaseList[0].request && this.apiCaseList[0].request.hashTree) { + this.setOwnEnvironment(this.apiCaseList[0].request.hashTree, environment); + } + } + } this.environment = environment; }, sysAddition(apiCase) { @@ -281,6 +289,39 @@ export default { refreshModule() { this.$emit('refreshModule'); }, + setEnvironments(obj) { + this.$get('/api/environment/list/' + this.projectId, response => { + let environments = response.data; + this.getTargetSource(environments, obj); + }); + }, + getTargetSource(environments, obj) { + environments.forEach(environment => { + parseEnvironment(environment); + // 找到原始环境和数据源名称 + if (environment.id === obj.environmentId) { + if (environment.config && environment.config.databaseConfigs) { + environment.config.databaseConfigs.forEach(item => { + if (item.id === obj.dataSourceId) { + obj.targetDataSourceName = item.name; + } + }); + } + } + }); + }, + setOwnEnvironment(scenarioDefinition, env) { + 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; + } + if (scenarioDefinition[i].hashTree !== undefined && scenarioDefinition[i].hashTree.length > 0) { + this.setOwnEnvironment(scenarioDefinition[i].hashTree, env); + } + } + }, runRefresh(data) { this.batchLoadingIds = []; this.singleLoading = false; diff --git a/frontend/src/business/components/api/definition/components/environment/EnvironmentSelect.vue b/frontend/src/business/components/api/definition/components/environment/EnvironmentSelect.vue index 54dfc17d56..574abb3531 100644 --- a/frontend/src/business/components/api/definition/components/environment/EnvironmentSelect.vue +++ b/frontend/src/business/components/api/definition/components/environment/EnvironmentSelect.vue @@ -92,11 +92,45 @@ this.currentData.environmentId = value; if (this.currentData.request) { this.currentData.request.useEnvironment = value; + // 更改当前步骤中含SQL前后置步骤对应的数据源 + if(this.currentData.request.hashTree) { + // 找到原始环境和数据源名称 + let environment = this.environments[i]; + this.setOwnEnvironment(this.currentData.request.hashTree, environment); + } } break; } } }, + getTargetSource(obj){ + this.environments.forEach(environment => { + parseEnvironment(environment); + // 找到原始环境和数据源名称 + if (environment.id === obj.environmentId) { + if (environment.config && environment.config.databaseConfigs) { + environment.config.databaseConfigs.forEach(item => { + if (item.id === obj.dataSourceId) { + obj.targetDataSourceName = item.name; + } + }); + } + } + }); + }, + setOwnEnvironment(scenarioDefinition,env) { + for (let i in scenarioDefinition) { + let typeArray = ["JDBCPostProcessor", "JDBCSampler", "JDBCPreProcessor"] + if (typeArray.indexOf(scenarioDefinition[i].type) !== -1) { + // 找到原始数据源名称 + this.getTargetSource(scenarioDefinition[i]) + scenarioDefinition[i].environmentId = env.id; + } + if (scenarioDefinition[i].hashTree !== undefined && scenarioDefinition[i].hashTree.length > 0) { + this.setOwnEnvironment(scenarioDefinition[i].hashTree,env); + } + } + }, openEnvironmentConfig() { if (!this.projectId) { this.$error(this.$t('api_test.select_project')); @@ -104,10 +138,10 @@ } this.$refs.environmentConfig.open(this.projectId); }, - setEnvironment(enviromentId){ - this.currentData.environmentId = enviromentId; + setEnvironment(environmentId){ + this.currentData.environmentId = environmentId; if (this.currentData.request) { - this.currentData.request.useEnvironment = enviromentId; + this.currentData.request.useEnvironment = environmentId; } } } diff --git a/frontend/src/business/components/api/definition/components/request/database/BasisParameters.vue b/frontend/src/business/components/api/definition/components/request/database/BasisParameters.vue index 5dc3abf04b..0256547d2f 100644 --- a/frontend/src/business/components/api/definition/components/request/database/BasisParameters.vue +++ b/frontend/src/business/components/api/definition/components/request/database/BasisParameters.vue @@ -176,9 +176,8 @@ export default { deep: true }, '$store.state.useEnvironment': function () { - if (!this.scenarioId) { - this.request.environmentId = this.$store.state.useEnvironment; - this.getEnvironments(); + if (this.scenarioId !== "") { + this.getEnvironments(this.$store.state.useEnvironment); } }, '$store.state.scenarioEnvMap': { @@ -263,17 +262,32 @@ export default { runTest() { }, - itselfEnvironment() { + itselfEnvironment(environmentId) { let id = this.request.projectId ? this.request.projectId : this.projectId; this.result = this.$get('/api/environment/list/' + id, response => { this.environments = response.data; + let targetDataSourceName = undefined; + let currentEnvironment = undefined; this.environments.forEach(environment => { parseEnvironment(environment); + // 找到原始环境和数据源名称 + if (environment.id === environmentId) { + currentEnvironment = environment; + } + if (environment.id === this.request.environmentId) { + if (environment.config && environment.config.databaseConfigs) { + environment.config.databaseConfigs.forEach(item => { + if (item.id === this.request.dataSourceId) { + targetDataSourceName = item.name; + } + }); + } + } }) - this.initDataSource(); + this.initDataSource(environmentId, currentEnvironment, targetDataSourceName); }); }, - getEnvironments() { + getEnvironments(environmentId) { let envId = ""; let id = this.request.projectId ? this.request.projectId : this.projectId; let scenarioEnvId = this.request.currentScenarioId ? (this.request.currentScenarioId + "_" + id) : id; @@ -281,13 +295,11 @@ export default { && this.$store.state.scenarioEnvMap.has(scenarioEnvId)) { envId = this.$store.state.scenarioEnvMap.get(scenarioEnvId); } - if (this.request.referenced === 'Created' && this.scenarioId && !this.request.isRefEnvironment) { - alert(2222) - this.itselfEnvironment(); + if (this.request.referenced === 'Created' && this.scenarioId !== "" && !this.request.isRefEnvironment) { + this.itselfEnvironment(environmentId); return; } else if (!this.scenarioId && !this.request.customizeReq) { - alert(333) - this.itselfEnvironment(); + this.itselfEnvironment(environmentId); return; } this.environments = []; @@ -384,10 +396,41 @@ export default { this.environments[i].config.databaseConfigs.forEach(item => { this.databaseConfigsOptions.push(item); }) + if (this.request.hashTree && !this.scenarioId) { + this.setOwnEnvironment(this.request.hashTree, value) + } break; } } }, + setOwnEnvironment(scenarioDefinition, env) { + for (let i in scenarioDefinition) { + let typeArray = ["JDBCPostProcessor", "JDBCSampler", "JDBCPreProcessor"] + if (typeArray.indexOf(scenarioDefinition[i].type) !== -1) { + // 找到原始数据源名称 + this.getTargetSource(scenarioDefinition[i]) + scenarioDefinition[i].environmentId = env; + } + if (scenarioDefinition[i].hashTree !== undefined && scenarioDefinition[i].hashTree.length > 0) { + this.setOwnEnvironment(scenarioDefinition[i].hashTree, env); + } + } + }, + getTargetSource(obj) { + this.environments.forEach(environment => { + parseEnvironment(environment); + // 找到原始环境和数据源名称 + if (environment.id === obj.environmentId) { + if (environment.config && environment.config.databaseConfigs) { + environment.config.databaseConfigs.forEach(item => { + if (item.id === obj.dataSourceId) { + obj.targetDataSourceName = item.name; + } + }); + } + } + }); + }, environmentConfigClose() { this.getEnvironments(); },