fix(项目管理): 修复环境保存全局参数无效的缺陷

This commit is contained in:
wxg0103 2024-05-21 13:55:05 +08:00 committed by 刘瑞斌
parent 9bcc87934e
commit 1c197dd589
2 changed files with 91 additions and 0 deletions

View File

@ -459,6 +459,18 @@ export default {
this.$warning(message); this.$warning(message);
return; return;
} }
if (environment.config.assertions && environment.config.assertions.document && environment.config.assertions.document.originalData) {
this.mergeEnvDocumentData(
environment.config.assertions.document.originalData,
environment.config.assertions.document.tableData,
environment.config.assertions.document.rootData
);
if (environment.config.assertions.document.type === 'JSON') {
environment.config.assertions.document.data.json = environment.config.assertions.document.originalData;
} else {
environment.config.assertions.document.data.xml = environment.config.assertions.document.originalData;
}
}
let bodyFiles = this.geFiles(environment); let bodyFiles = this.geFiles(environment);
let variablesFiles = this.getVariablesFiles(environment); let variablesFiles = this.getVariablesFiles(environment);
@ -513,6 +525,39 @@ export default {
clearValidate() { clearValidate() {
this.$refs["environment"].clearValidate(); this.$refs["environment"].clearValidate();
}, },
mergeEnvDocumentData(originalData, childMap, rootData) {
originalData.forEach((item) => {
if (item.id === "root" && rootData) {
item.type = rootData.type;
item.name = rootData.name;
item.typeVerification = rootData.typeVerification;
item.arrayVerification = rootData.arrayVerification;
item.contentVerification = rootData.contentVerification;
item.jsonPath = rootData.jsonPath;
item.expectedOutcome = rootData.expectedOutcome;
item.include = rootData.include;
item.conditions = rootData.conditions;
}
if (
childMap &&
childMap.size !== 0 &&
childMap instanceof Map &&
childMap.has(item.id)
) {
let sourceData = JSON.parse(JSON.stringify(item.children));
item.children = JSON.parse(JSON.stringify(childMap.get(item.id)));
item.children.forEach((target) => {
let index = sourceData.findIndex((source) => source.id === target.id);
if (index !== -1) {
target.children = sourceData[index].children;
}
});
if (item.children && item.children.length > 0) {
this.mergeEnvDocumentData(item.children, childMap);
}
}
});
}
}, },
} }
</script> </script>

View File

@ -473,6 +473,19 @@ export default {
formData.append("variablesFiles", f); formData.append("variablesFiles", f);
}) })
} }
if (environment.config.assertions && environment.config.assertions.document && environment.config.assertions.document.originalData) {
this.mergeDocumentData(
environment.config.assertions.document.originalData,
environment.config.assertions.document.tableData,
environment.config.assertions.document.rootData
);
if (environment.config.assertions.document.type === 'JSON') {
environment.config.assertions.document.data.json = environment.config.assertions.document.originalData;
} else {
environment.config.assertions.document.data.xml = environment.config.assertions.document.originalData;
}
}
let param = this.buildParam(environment); let param = this.buildParam(environment);
formData.append('request', new Blob([JSON.stringify(param)], {type: "application/json"})); formData.append('request', new Blob([JSON.stringify(param)], {type: "application/json"}));
editEnv(formData, param).then((response) => { editEnv(formData, param).then((response) => {
@ -484,6 +497,39 @@ export default {
}); });
}, },
mergeDocumentData(originalData, childMap, rootData) {
originalData.forEach((item) => {
if (item.id === "root" && rootData) {
item.type = rootData.type;
item.name = rootData.name;
item.typeVerification = rootData.typeVerification;
item.arrayVerification = rootData.arrayVerification;
item.contentVerification = rootData.contentVerification;
item.jsonPath = rootData.jsonPath;
item.expectedOutcome = rootData.expectedOutcome;
item.include = rootData.include;
item.conditions = rootData.conditions;
}
if (
childMap &&
childMap.size !== 0 &&
childMap instanceof Map &&
childMap.has(item.id)
) {
let sourceData = JSON.parse(JSON.stringify(item.children));
item.children = JSON.parse(JSON.stringify(childMap.get(item.id)));
item.children.forEach((target) => {
let index = sourceData.findIndex((source) => source.id === target.id);
if (index !== -1) {
target.children = sourceData[index].children;
}
});
if (item.children && item.children.length > 0) {
this.mergeDocumentData(item.children, childMap);
}
}
});
},
buildParam: function (environment) { buildParam: function (environment) {
let param = {}; let param = {};
Object.assign(param, environment); Object.assign(param, environment);