refactor: 代码规范
This commit is contained in:
parent
c169f66dad
commit
47f0333392
|
@ -119,8 +119,8 @@
|
|||
return new Promise((resolve) => {
|
||||
this.$post("/api/automation/getApiScenarioEnv", {definition: definition}, res => {
|
||||
if (res.data) {
|
||||
this.$emit("update:projectIds", new Set(res.data.projectIds))
|
||||
this.$emit("update:isFullUrl", res.data.fullUrl)
|
||||
this.$emit("update:projectIds", new Set(res.data.projectIds));
|
||||
this.$emit("update:isFullUrl", res.data.fullUrl);
|
||||
}
|
||||
resolve();
|
||||
})
|
||||
|
|
|
@ -35,7 +35,7 @@ export default {
|
|||
data() {
|
||||
return {
|
||||
visible: false
|
||||
}
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
showPopover() {
|
||||
|
|
|
@ -48,7 +48,7 @@ export default {
|
|||
environments: [],
|
||||
dialogVisible: false,
|
||||
isFullUrl: true,
|
||||
}
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
init() {
|
||||
|
@ -68,7 +68,7 @@ export default {
|
|||
let envId = this.envMap.get(id);
|
||||
// 选中环境是否存在
|
||||
temp.selectEnv = envs.filter(e => e.id === envId).length === 0 ? null : envId;
|
||||
})
|
||||
});
|
||||
}
|
||||
})
|
||||
},
|
||||
|
@ -106,122 +106,6 @@ export default {
|
|||
this.$emit('setProjectEnvMap', map);
|
||||
this.$emit('close');
|
||||
},
|
||||
getApiInfo(request) {
|
||||
if (request.id && request.referenced === 'REF') {
|
||||
let requestResult = request.requestResult;
|
||||
let url = request.refType && request.refType === 'CASE' ? "/api/testcase/get/" : "/api/definition/get/";
|
||||
let enable = request.enable;
|
||||
this.$get(url + request.id, response => {
|
||||
if (response.data) {
|
||||
Object.assign(request, JSON.parse(response.data.request));
|
||||
request.name = response.data.name;
|
||||
request.enable = enable;
|
||||
if (response.data.path && response.data.path != null) {
|
||||
request.path = response.data.path;
|
||||
request.url = response.data.url;
|
||||
this.setUrl(request.path);
|
||||
}
|
||||
if (response.data.method && response.data.method != null) {
|
||||
request.method = response.data.method;
|
||||
}
|
||||
request.requestResult = requestResult;
|
||||
request.id = response.data.id;
|
||||
request.disabled = true;
|
||||
request.root = true;
|
||||
if (!request.projectId) {
|
||||
request.projectId = response.data.projectId;
|
||||
}
|
||||
this.reload();
|
||||
this.sort();
|
||||
} else {
|
||||
request.referenced = "Deleted";
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
getScenario(scenario) {
|
||||
this.result = this.$get("/api/automation/getApiScenario/" + scenario.id, response => {
|
||||
if (response.data) {
|
||||
scenario.loaded = true;
|
||||
let obj = {};
|
||||
if (response.data.scenarioDefinition) {
|
||||
obj = JSON.parse(response.data.scenarioDefinition);
|
||||
scenario.hashTree = obj.hashTree;
|
||||
}
|
||||
//scenario.disabled = true;
|
||||
scenario.name = response.data.name;
|
||||
if (!scenario.projectId) {
|
||||
scenario.projectId = response.data.projectId;
|
||||
}
|
||||
scenario.headers = obj.headers;
|
||||
scenario.variables = obj.variables;
|
||||
scenario.environmentMap = obj.environmentMap;
|
||||
this.$emit('refReload');
|
||||
} else {
|
||||
scenario.referenced = "Deleted";
|
||||
}
|
||||
})
|
||||
},
|
||||
recursiveSorting(arr) {
|
||||
for (let i in arr) {
|
||||
if (arr[i].referenced === 'REF') {
|
||||
// 分场景和接口
|
||||
if (arr[i].type === "HTTPSamplerProxy") {
|
||||
// 获取源头内容
|
||||
this.getApiInfo(arr[i]);
|
||||
// 校验是否是全路径
|
||||
if (!arr[i].url || (!arr[i].url.startsWith("http://") && !arr[i].url.startsWith("https://"))) {
|
||||
this.isFullUrl = false;
|
||||
}
|
||||
} else if (arr[i].type === "scenario") {
|
||||
this.getScenario(arr[i]);
|
||||
}
|
||||
|
||||
} else {
|
||||
if (arr[i].type === "HTTPSamplerProxy") {
|
||||
// 校验是否是全路径
|
||||
if (arr[i].enable) {
|
||||
if (!arr[i].url || (!arr[i].url.startsWith("http://") && !arr[i].url.startsWith("https://"))) {
|
||||
this.isFullUrl = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (arr[i].hashTree != undefined && arr[i].hashTree.length > 0) {
|
||||
this.recursiveSorting(arr[i].hashTree);
|
||||
}
|
||||
}
|
||||
},
|
||||
checkFullUrl(scenarioDefinition) {
|
||||
for (let i in scenarioDefinition) {
|
||||
// 设置项目ID
|
||||
let request = scenarioDefinition[i];
|
||||
if (request.referenced === 'REF') {
|
||||
if (request.type === "HTTPSamplerProxy") {
|
||||
this.getApiInfo(request);
|
||||
// 校验是否是全路径
|
||||
if (!request.url || (!request.url.startsWith("http://") && !request.url.startsWith("https://"))) {
|
||||
this.isFullUrl = false;
|
||||
}
|
||||
} else if (request.type === "scenario") {
|
||||
this.getScenario(request);
|
||||
}
|
||||
} else {
|
||||
if (request.type === "HTTPSamplerProxy") {
|
||||
// 校验是否是全路径
|
||||
|
||||
if (request.enable) {
|
||||
if (!request.url || (!request.url.startsWith("http://") && !request.url.startsWith("https://"))) {
|
||||
this.isFullUrl = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (scenarioDefinition[i].hashTree != undefined && scenarioDefinition[i].hashTree.length > 0) {
|
||||
this.recursiveSorting(scenarioDefinition[i].hashTree);
|
||||
}
|
||||
}
|
||||
},
|
||||
checkEnv() {
|
||||
let sign = true;
|
||||
this.isFullUrl = true;
|
||||
|
@ -244,9 +128,6 @@ export default {
|
|||
} else {
|
||||
sign = false;
|
||||
}
|
||||
// 校验是否全是全路径
|
||||
//this.checkFullUrl(data);
|
||||
//sign = this.isFullUrl;
|
||||
}
|
||||
|
||||
if (!sign) {
|
||||
|
|
Loading…
Reference in New Issue