diff --git a/frontend/src/business/components/api/automation/ApiAutomation.vue b/frontend/src/business/components/api/automation/ApiAutomation.vue index 6da49bc742..1417165eba 100644 --- a/frontend/src/business/components/api/automation/ApiAutomation.vue +++ b/frontend/src/business/components/api/automation/ApiAutomation.vue @@ -345,6 +345,8 @@ export default { this.tabs = []; this.activeName = "default"; this.isSave = false; + // 清除vuex中缓存的环境 + this.$store.state.scenarioEnvMap = new Map(); } else { this.isSave = false; } @@ -384,7 +386,6 @@ export default { }, diff(t) { if (t.currentScenario.type !== "add") { - let v1 = t.currentScenario.scenarioDefinitionOrg; let v2 = { apiScenarioModuleId: t.currentScenario.apiScenarioModuleId, @@ -506,11 +507,6 @@ export default { if (tab && this.isSave) { message += tab.currentScenario.name + ","; } - if (tab) { - let index = this.tabs.filter(t => t === tab); - index.splice(0, 1); - tab = undefined; - } } }) if (message !== "") { @@ -535,6 +531,22 @@ export default { } }, removeTab(targetName) { + let index = this.tabs.findIndex(item => item.name === targetName); + if (index !== -1) { + // 清除vuex中缓存的环境 + let tab = this.tabs[index]; + if (tab && tab.currentScenario && this.$store.state.scenarioEnvMap && this.$store.state.scenarioEnvMap instanceof Map) { + this.$store.state.scenarioEnvMap.forEach((v, k) => { + if (k.indexOf(tab.currentScenario.id) !== -1) { + this.$store.state.scenarioEnvMap.delete(k); + } + }) + } + this.tabs.splice(index, 1); + if (tab) { + tab = undefined; + } + } this.tabs = this.tabs.filter(tab => tab.name !== targetName); if (this.tabs.length > 0) { this.activeName = this.tabs[this.tabs.length - 1].name; @@ -542,10 +554,6 @@ export default { } else { this.activeName = "default"; } - let index = this.tabs.findIndex(item => item.name === targetName); - if (index !== -1) { - this.tabs.splice(index, 1); - } }, setTabLabel(data) { for (const tab of this.tabs) { diff --git a/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue b/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue index 242610b811..323c994914 100644 --- a/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue +++ b/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue @@ -1583,7 +1583,12 @@ export default { // 兼容历史数据 this.projectEnvMap.set(this.projectId, obj.environmentId); } - this.$store.state.scenarioEnvMap = this.projectEnvMap; + if (!this.$store.state.scenarioEnvMap || !(this.$store.state.scenarioEnvMap instanceof Map)) { + this.$store.state.scenarioEnvMap = new Map(); + } + this.projectEnvMap.forEach((v, k) => { + this.$store.state.scenarioEnvMap.set(this.currentScenario.id + "_" + k, v); + }) this.envGroupId = response.data.environmentGroupId; if (response.data.environmentType) { this.environmentType = response.data.environmentType; @@ -1777,7 +1782,15 @@ export default { }, setProjectEnvMap(projectEnvMap) { this.projectEnvMap = projectEnvMap; - this.$store.state.scenarioEnvMap = projectEnvMap; + if (!this.$store.state.scenarioEnvMap) { + this.$store.state.scenarioEnvMap = new Map(); + } + let map = objToStrMap(JSON.parse(JSON.stringify(this.$store.state.scenarioEnvMap))); + this.projectEnvMap.forEach((v, k) => { + let key = this.currentScenario.id + "_" + k; + map.set(key, v); + }); + this.$store.state.scenarioEnvMap = map; this.setDomain(true); }, setEnvGroup(id) { 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 092ed14bf8..343d814e9c 100644 --- a/frontend/src/business/components/api/automation/scenario/common/JDBCProcessorContent.vue +++ b/frontend/src/business/components/api/automation/scenario/common/JDBCProcessorContent.vue @@ -99,10 +99,7 @@ export default { type: Boolean, default: true, }, - isScenario: { - type: Boolean, - default: false, - }, + isScenario: String, isReadOnly: { type: Boolean, default: false @@ -189,9 +186,10 @@ export default { getEnvironments() { let envId = ""; let id = this.request.projectId ? this.request.projectId : this.projectId; + let scenarioEnvId = this.isScenario ? (this.isScenario + "_" + id) : id; if (this.$store.state.scenarioEnvMap && this.$store.state.scenarioEnvMap instanceof Map - && this.$store.state.scenarioEnvMap.has(id)) { - envId = this.$store.state.scenarioEnvMap.get(id); + && this.$store.state.scenarioEnvMap.has(scenarioEnvId)) { + envId = this.$store.state.scenarioEnvMap.get(scenarioEnvId); } if (this.request.referenced === 'Created' && this.isScenario && !this.request.isRefEnvironment) { this.itselfEnvironment(); diff --git a/frontend/src/business/components/api/automation/scenario/component/ApiComponent.vue b/frontend/src/business/components/api/automation/scenario/component/ApiComponent.vue index 5d6b272470..79781ef6c2 100644 --- a/frontend/src/business/components/api/automation/scenario/component/ApiComponent.vue +++ b/frontend/src/business/components/api/automation/scenario/component/ApiComponent.vue @@ -84,7 +84,7 @@ :isShowEnable="true" :response="response" :referenced="true" - :isScenario="true" + :isScenario="currentScenario.id" :headers="request.headers " :is-read-only="isCompReadOnly" :request="request"/> @@ -101,21 +101,21 @@ :is-read-only="isCompReadOnly" :response="response" :show-pre-script="true" - :isScenario="true" + :isScenario="currentScenario.id" :show-script="true" :request="request"/> @@ -252,7 +252,11 @@ export default { this.request.projectId = getCurrentProjectID(); } this.request.customizeReq = this.isCustomizeReq; - + this.request.currentScenarioId = this.currentScenario.id; + // 传递场景ID + if (this.request.hashTree) { + this.setOwnEnvironment(this.request.hashTree); + } if (this.request.num) { this.isShowNum = true; this.request.root = true; @@ -357,6 +361,17 @@ export default { }, }, methods: { + setOwnEnvironment(scenarioDefinition) { + for (let i in scenarioDefinition) { + let typeArray = ["JDBCPostProcessor", "JDBCSampler", "JDBCPreProcessor"] + if (typeArray.indexOf(scenarioDefinition[i].type) !== -1) { + scenarioDefinition[i].currentScenarioId = this.currentScenario.id; + } + if (scenarioDefinition[i].hashTree !== undefined && scenarioDefinition[i].hashTree.length > 0) { + this.setOwnEnvironment(scenarioDefinition[i].hashTree); + } + } + }, forStatus() { this.reqSuccess = true; if (this.request.result && this.request.result.length > 0) { diff --git a/frontend/src/business/components/api/automation/scenario/component/JDBCProcessor.vue b/frontend/src/business/components/api/automation/scenario/component/JDBCProcessor.vue index 6ea6dc231d..d66633f2b3 100644 --- a/frontend/src/business/components/api/automation/scenario/component/JDBCProcessor.vue +++ b/frontend/src/business/components/api/automation/scenario/component/JDBCProcessor.vue @@ -35,10 +35,7 @@ export default { ApiBaseComponent, MsDropdown, MsInstructionsIcon, MsCodeEdit }, props: { - isScenario: { - type: Boolean, - default: false, - }, + isScenario: String, draggable: { type: Boolean, default: false, 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 56d000a52c..9cfedd4b60 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 @@ -149,10 +149,7 @@ export default { type: Boolean, default: false, }, - isScenario: { - type: Boolean, - default: false, - }, + isScenario: String, isReadOnly: { type: Boolean, default: false @@ -279,9 +276,10 @@ export default { getEnvironments() { let envId = ""; let id = this.request.projectId ? this.request.projectId : this.projectId; + let scenarioEnvId = this.request.currentScenarioId ? (this.request.currentScenarioId + "_" + id) : id; if (this.$store.state.scenarioEnvMap && this.$store.state.scenarioEnvMap instanceof Map - && this.$store.state.scenarioEnvMap.has(id)) { - envId = this.$store.state.scenarioEnvMap.get(id); + && this.$store.state.scenarioEnvMap.has(scenarioEnvId)) { + envId = this.$store.state.scenarioEnvMap.get(scenarioEnvId); } if (this.request.referenced === 'Created' && this.isScenario && !this.request.isRefEnvironment) { this.itselfEnvironment(); diff --git a/frontend/src/business/components/api/definition/components/request/dubbo/BasisParameters.vue b/frontend/src/business/components/api/definition/components/request/dubbo/BasisParameters.vue index 5905e8a5a2..dfb0840633 100644 --- a/frontend/src/business/components/api/definition/components/request/dubbo/BasisParameters.vue +++ b/frontend/src/business/components/api/definition/components/request/dubbo/BasisParameters.vue @@ -116,10 +116,7 @@ export default { MsJmxStep }, props: { - isScenario: { - type: Boolean, - default: false, - }, + isScenario: String, request: {}, basisData: {}, moduleOptions: Array, diff --git a/frontend/src/business/components/api/definition/components/request/http/ApiHttpRequestForm.vue b/frontend/src/business/components/api/definition/components/request/http/ApiHttpRequestForm.vue index 2483391a60..c039e60ab5 100644 --- a/frontend/src/business/components/api/definition/components/request/http/ApiHttpRequestForm.vue +++ b/frontend/src/business/components/api/definition/components/request/http/ApiHttpRequestForm.vue @@ -210,10 +210,7 @@ export default { return false; } }, - isScenario: { - type: Boolean, - default: false, - }, + isScenario: String, showScript: { type: Boolean, default: true, diff --git a/frontend/src/business/components/api/definition/components/request/tcp/TcpFormatParameters.vue b/frontend/src/business/components/api/definition/components/request/tcp/TcpFormatParameters.vue index 729702ab9a..78dd5e2f48 100644 --- a/frontend/src/business/components/api/definition/components/request/tcp/TcpFormatParameters.vue +++ b/frontend/src/business/components/api/definition/components/request/tcp/TcpFormatParameters.vue @@ -202,10 +202,7 @@ export default { MsJmxStep }, props: { - isScenario: { - type: Boolean, - default: false, - }, + isScenario: String, request: {}, basisData: {}, response: {}, 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 0ce6af2906..88e40520e9 100644 --- a/frontend/src/business/components/api/definition/components/step/JmxStep.vue +++ b/frontend/src/business/components/api/definition/components/step/JmxStep.vue @@ -139,10 +139,7 @@ export default { tabType: String, response: {}, apiId: String, - isScenario: { - type: Boolean, - default: false, - }, + isScenario: String, showScript: { type: Boolean, default: true,