refactor(接口测试): 优化场景提示未保存的方法

This commit is contained in:
wxg0103 2022-03-11 16:10:00 +08:00 committed by xiaomeinvG
parent aa1d53b96e
commit b35a0468ab
2 changed files with 104 additions and 53 deletions

View File

@ -161,7 +161,6 @@ export default {
customNum: false,
//API
initApiTableOpretion: 'init',
isLeave: false,
isSave: false,
isAsideHidden: true,
};
@ -332,27 +331,10 @@ export default {
let message = "";
if (!this.isSave) {
this.tabs.forEach(t => {
if (t.currentScenario.type !== "add") {
let v1 = t.currentScenario.scenarioDefinitionOrg;
let v2 = {
apiScenarioModuleId: t.currentScenario.apiScenarioModuleId,
name: t.currentScenario.name,
status: t.currentScenario.status,
principal: t.currentScenario.principal,
level: t.currentScenario.level,
tags: t.currentScenario.tags,
description: t.currentScenario.description,
scenarioDefinition: t.currentScenario.scenarioDefinition
};
this.deleteResourceIds(v1.scenarioDefinition);
this.deleteResourceIds(v2.scenarioDefinition);
let delta = jsondiffpatch.diff(JSON.parse(JSON.stringify(v1)), JSON.parse(JSON.stringify(v2)));
if (delta) {
this.isLeave = true;
}
if (t && this.isLeave) {
message += t.currentScenario.name + "";
}
this.diff(t);
if (t && this.isSave) {
message += t.currentScenario.name + "";
this.isSave = false;
}
});
if (message !== "") {
@ -363,10 +345,8 @@ export default {
if (action === 'confirm') {
this.tabs = [];
this.activeName = "default";
this.refresh();
this.isSave = false;
} else {
this.isLeave = false;
this.isSave = false;
}
}
@ -376,14 +356,12 @@ export default {
this.activeName = "default";
this.refresh();
this.isSave = false;
this.isLeave = false;
}
} else {
this.tabs = [];
this.activeName = "default";
this.refresh();
this.isSave = false;
this.isLeave = false;
}
if (this.tabs && this.tabs.length === 0) {
this.refreshAll();
@ -411,61 +389,134 @@ export default {
this.activeName = "default";
}
},
diff(t) {
if (t.currentScenario.type !== "add") {
let v1 = t.currentScenario.scenarioDefinitionOrg;
let v2 = {
apiScenarioModuleId: t.currentScenario.apiScenarioModuleId,
name: t.currentScenario.name,
status: t.currentScenario.status,
principal: t.currentScenario.principal,
level: t.currentScenario.level,
tags: t.currentScenario.tags,
description: t.currentScenario.description,
scenarioDefinition: t.currentScenario.scenarioDefinition
};
let v3 = JSON.parse(JSON.stringify(v2));
this.deleteResourceIds(v1.scenarioDefinition);
this.deleteResourceIds(v3.scenarioDefinition);
let delta = jsondiffpatch.diff(JSON.parse(JSON.stringify(v1)), JSON.parse(JSON.stringify(v3)));
if (delta) {
this.isSave = true;
}
}
},
deleteResourceIds(array) {
array.forEach(item => {
if (item.resourceId) {
delete item.resourceId;
}
if (item.method) {
delete item.method;
}
if (item.timeout >= 0) {
delete item.timeout;
}
if (item.ctimeout >= 0) {
delete item.ctimeout;
}
if (item.rest && item.rest.length === 0) {
delete item.rest;
}
if (item.arguments && item.arguments.length === 0) {
delete item.arguments;
}
if (item.id) {
delete item.id;
}
if (!item.checkBox) {
delete item.checkBox;
}
if (!item.isBatchProcess) {
delete item.isBatchProcess;
}
if (!item.isLeaf || item.isLeaf) {
delete item.isLeaf;
}
if (item.maxThreads) {
delete item.maxThreads;
}
if (item.parentIndex) {
delete item.parentIndex
}
if (item.connectTimeout) {
delete item.connectTimeout;
}
if (item.index) {
delete item.index;
}
if (item.postSize >= 0) {
delete item.postSize;
}
if (item.preSize >= 0) {
delete item.preSize;
}
if (item.requestResult) {
delete item.requestResult;
}
if (item.responseTimeout) {
delete item.responseTimeout;
}
if (item.root) {
delete item.root;
}
if (item.ruleSize >= 0) {
delete item.ruleSize;
}
if (item.body && item.body.kvs) {
item.body.kvs.forEach(v => {
if (v.files) {
delete v.files;
}
})
}
if (item.body && ((item.body.binary && item.body.binary.length === 0) || (item.body.kvs && item.body.kvs.length === 0))) {
delete item.body;
}
delete item.projectId;
if (item.hashTree && item.hashTree.length > 0) {
this.deleteResourceIds(item.hashTree);
}
})
},
closeConfirm(targetName) {
let t = this.tabs.filter(tab => tab.name === targetName);
if (!this.isSave && t[0].currentScenario.type !== 'add') {
let v1 = t[0].currentScenario.scenarioDefinitionOrg;
let v2 = {
apiScenarioModuleId: t[0].currentScenario.apiScenarioModuleId,
name: t[0].currentScenario.name,
status: t[0].currentScenario.status,
principal: t[0].currentScenario.principal,
level: t[0].currentScenario.level,
tags: t[0].currentScenario.tags,
description: t[0].currentScenario.description,
scenarioDefinition: t[0].currentScenario.scenarioDefinition
};
this.deleteResourceIds(v1.scenarioDefinition);
this.deleteResourceIds(v2.scenarioDefinition);
let delta = jsondiffpatch.diff(JSON.parse(JSON.stringify(v1)), JSON.parse(JSON.stringify(v2)));
if (delta) {
this.isLeave = true;
}
if (this.isLeave) {
this.$alert(this.$t('commons.scenario') + " [ " + t[0].currentScenario.name + " ] " + this.$t('commons.confirm_info'), '', {
let message = "";
let tab = this.tabs.filter(tab => tab.name === targetName);
if (!this.isSave) {
tab.forEach(t => {
this.diff(t);
if (t && this.isSave) {
message += t.currentScenario.name + "";
}
});
if (message !== "") {
this.$alert(this.$t('commons.scenario') + " [ " + message.substr(0, message.length - 1) + " ] " + this.$t('commons.confirm_info'), '', {
confirmButtonText: this.$t('commons.confirm'),
cancelButtonText: this.$t('commons.cancel'),
callback: (action) => {
if (action === 'confirm') {
this.isLeave = false;
this.removeTab(targetName);
this.isSave = false;
} else {
this.isLeave = false;
this.isSave = false;
}
}
});
} else {
this.isLeave = false;
this.isSave = false;
this.removeTab(targetName);
}
} else {
this.isLeave = false;
this.isSave = false;
this.removeTab(targetName);
}

View File

@ -1572,10 +1572,10 @@ export default {
level: this.currentScenario.level,
tags: this.currentScenario.tags,
description: this.currentScenario.description,
scenarioDefinition: this.scenarioDefinition
scenarioDefinition: JSON.parse(JSON.stringify(this.scenarioDefinition))
};
this.currentScenario.scenarioDefinitionOrg = JSON.parse(JSON.stringify(v1));
this.currentScenario.scenarioDefinitionOrg = v1;
this.currentScenario.scenarioDefinition = this.scenarioDefinition;
this.$nextTick(() => {
this.sort();