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, customNum: false,
//API //API
initApiTableOpretion: 'init', initApiTableOpretion: 'init',
isLeave: false,
isSave: false, isSave: false,
isAsideHidden: true, isAsideHidden: true,
}; };
@ -332,27 +331,10 @@ export default {
let message = ""; let message = "";
if (!this.isSave) { if (!this.isSave) {
this.tabs.forEach(t => { this.tabs.forEach(t => {
if (t.currentScenario.type !== "add") { this.diff(t);
let v1 = t.currentScenario.scenarioDefinitionOrg; if (t && this.isSave) {
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 + ""; message += t.currentScenario.name + "";
} this.isSave = false;
} }
}); });
if (message !== "") { if (message !== "") {
@ -363,10 +345,8 @@ export default {
if (action === 'confirm') { if (action === 'confirm') {
this.tabs = []; this.tabs = [];
this.activeName = "default"; this.activeName = "default";
this.refresh();
this.isSave = false; this.isSave = false;
} else { } else {
this.isLeave = false;
this.isSave = false; this.isSave = false;
} }
} }
@ -376,14 +356,12 @@ export default {
this.activeName = "default"; this.activeName = "default";
this.refresh(); this.refresh();
this.isSave = false; this.isSave = false;
this.isLeave = false;
} }
} else { } else {
this.tabs = []; this.tabs = [];
this.activeName = "default"; this.activeName = "default";
this.refresh(); this.refresh();
this.isSave = false; this.isSave = false;
this.isLeave = false;
} }
if (this.tabs && this.tabs.length === 0) { if (this.tabs && this.tabs.length === 0) {
this.refreshAll(); this.refreshAll();
@ -411,61 +389,134 @@ export default {
this.activeName = "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) { deleteResourceIds(array) {
array.forEach(item => { array.forEach(item => {
if (item.resourceId) { if (item.resourceId) {
delete 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) { if (item.id) {
delete 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) { if (item.hashTree && item.hashTree.length > 0) {
this.deleteResourceIds(item.hashTree); this.deleteResourceIds(item.hashTree);
} }
}) })
}, },
closeConfirm(targetName) { closeConfirm(targetName) {
let t = this.tabs.filter(tab => tab.name === targetName); let message = "";
if (!this.isSave && t[0].currentScenario.type !== 'add') { let tab = this.tabs.filter(tab => tab.name === targetName);
let v1 = t[0].currentScenario.scenarioDefinitionOrg; if (!this.isSave) {
let v2 = { tab.forEach(t => {
apiScenarioModuleId: t[0].currentScenario.apiScenarioModuleId, this.diff(t);
name: t[0].currentScenario.name, if (t && this.isSave) {
status: t[0].currentScenario.status, message += t.currentScenario.name + "";
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'), '', { if (message !== "") {
this.$alert(this.$t('commons.scenario') + " [ " + message.substr(0, message.length - 1) + " ] " + this.$t('commons.confirm_info'), '', {
confirmButtonText: this.$t('commons.confirm'), confirmButtonText: this.$t('commons.confirm'),
cancelButtonText: this.$t('commons.cancel'), cancelButtonText: this.$t('commons.cancel'),
callback: (action) => { callback: (action) => {
if (action === 'confirm') { if (action === 'confirm') {
this.isLeave = false;
this.removeTab(targetName); this.removeTab(targetName);
this.isSave = false; this.isSave = false;
} else { } else {
this.isLeave = false;
this.isSave = false; this.isSave = false;
} }
} }
}); });
} else { } else {
this.isLeave = false;
this.isSave = false; this.isSave = false;
this.removeTab(targetName); this.removeTab(targetName);
} }
} else { } else {
this.isLeave = false;
this.isSave = false; this.isSave = false;
this.removeTab(targetName); this.removeTab(targetName);
} }

View File

@ -1572,10 +1572,10 @@ export default {
level: this.currentScenario.level, level: this.currentScenario.level,
tags: this.currentScenario.tags, tags: this.currentScenario.tags,
description: this.currentScenario.description, 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.currentScenario.scenarioDefinition = this.scenarioDefinition;
this.$nextTick(() => { this.$nextTick(() => {
this.sort(); this.sort();