Merge branch 'v1.8' into master

This commit is contained in:
Captain.B 2021-03-31 08:17:27 +08:00
commit 13386da0af
9 changed files with 239 additions and 115 deletions

View File

@ -447,7 +447,7 @@ export default {
this.$nextTick(function () { this.$nextTick(function () {
if (this.$refs.scenarioTable) { if (this.$refs.scenarioTable) {
this.$refs.scenarioTable.doLayout(); setTimeout(this.$refs.scenarioTable.doLayout, 200)
} }
this.checkTableRowIsSelect(); this.checkTableRowIsSelect();
}) })

View File

@ -767,7 +767,7 @@
}, },
runDebug() { runDebug() {
/*触发执行操作*/ /*触发执行操作*/
let sign = this.$refs.envPopover.checkEnv(); let sign = this.$refs.envPopover.checkEnv(this.scenarioDefinition);
if (!sign) { if (!sign) {
return; return;
} }

View File

@ -44,8 +44,8 @@ export default {
setProjectEnvMap(map) { setProjectEnvMap(map) {
this.$emit("setProjectEnvMap", map); this.$emit("setProjectEnvMap", map);
}, },
checkEnv() { checkEnv(data) {
return this.$refs.envSelect.checkEnv(); return this.$refs.envSelect.checkEnv(data);
} }
} }

View File

@ -29,133 +29,257 @@
</template> </template>
<script> <script>
import {parseEnvironment} from "@/business/components/api/test/model/EnvironmentModel"; import {parseEnvironment} from "@/business/components/api/test/model/EnvironmentModel";
import ApiEnvironmentConfig from "@/business/components/api/definition/components/environment/ApiEnvironmentConfig"; import ApiEnvironmentConfig from "@/business/components/api/definition/components/environment/ApiEnvironmentConfig";
import {ELEMENTS} from "./Setting";
export default { export default {
name: "EnvironmentSelect", name: "EnvironmentSelect",
components: {ApiEnvironmentConfig}, components: {ApiEnvironmentConfig},
props: { props: {
envMap: Map, envMap: Map,
projectIds: Set, projectIds: Set,
projectList: Array projectList: Array
}, },
data() { data() {
return { return {
data: [], data: [],
result: {}, result: {},
projects: [], projects: [],
environments: [], environments: [],
dialogVisible: false dialogVisible: false,
} isFullUrl: true,
}, }
methods: { },
init() { methods: {
this.projectIds.forEach(id => { init() {
let item = {id: id, envs: [], selectEnv: ""}; this.projectIds.forEach(id => {
this.data.push(item); let item = {id: id, envs: [], selectEnv: ""};
this.result = this.$get('/api/environment/list/' + id, res => { this.data.push(item);
let envs = res.data; this.result = this.$get('/api/environment/list/' + id, res => {
envs.forEach(environment => { let envs = res.data;
parseEnvironment(environment); envs.forEach(environment => {
}); parseEnvironment(environment);
// });
let temp = this.data.find(dt => dt.id === id); //
temp.envs = envs; let temp = this.data.find(dt => dt.id === id);
let envId = this.envMap.get(id); temp.envs = envs;
// let envId = this.envMap.get(id);
temp.selectEnv = envs.filter(e =>e.id === envId).length === 0 ? null : envId; //
temp.selectEnv = envs.filter(e => e.id === envId).length === 0 ? null : envId;
})
}) })
}) },
}, open() {
open() { this.data = [];
this.data = []; if (this.projectIds.size > 0) {
if (this.projectIds.size > 0) { this.init();
this.init(); }
} },
}, getProjectName(id) {
getProjectName(id) { const project = this.projectList.find(p => p.id === id);
const project = this.projectList.find(p => p.id === id); return project ? project.name : "";
return project ? project.name : ""; },
}, openEnvironmentConfig(projectId, envId) {
openEnvironmentConfig(projectId, envId) { if (!projectId) {
if (!projectId) { this.$error(this.$t('api_test.select_project'));
this.$error(this.$t('api_test.select_project'));
return;
}
this.$refs.environmentConfig.open(projectId, envId);
},
handleConfirm() {
let map = new Map();
let sign = true;
this.data.forEach(dt => {
if (!dt.selectEnv) {
sign = false;
return; return;
} }
map.set(dt.id, dt.selectEnv); this.$refs.environmentConfig.open(projectId, envId);
}) },
if (!sign) { handleConfirm() {
this.$warning("请为每个项目选择一个运行环境!"); let map = new Map();
return; let sign = true;
}
this.$emit('setProjectEnvMap', map);
this.$emit('close');
},
checkEnv() {
let sign = true;
if (this.data.length > 0) {
this.data.forEach(dt => { this.data.forEach(dt => {
if (!dt.selectEnv) { if (!dt.selectEnv) {
sign = false; sign = false;
return false; return;
}
map.set(dt.id, dt.selectEnv);
})
if (!sign) {
this.$warning("请为每个项目选择一个运行环境!");
return;
}
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";
} }
}) })
} else { },
// recursiveSorting(arr) {
if (this.envMap && this.envMap.size > 0) { for (let i in arr) {
this.projectIds.forEach(id => { if (arr[i].referenced === 'REF') {
if (!this.envMap.get(id)) { //
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(data) {
let sign = true;
this.isFullUrl = true;
if (this.data.length > 0) {
this.data.forEach(dt => {
if (!dt.selectEnv) {
sign = false; sign = false;
return false; return false;
} }
}) })
} else { } else {
sign = false; //
} if (this.envMap && this.envMap.size > 0) {
} this.projectIds.forEach(id => {
if (!this.envMap.get(id)) {
sign = false;
return false;
}
})
} else {
// this.checkFullUrl(data);
// sign = this.isFullUrl;
sign = false;
}
if (!sign) { //
this.$warning("请为每个项目选择一个运行环境!");
return false; }
if (!sign) {
this.$warning("请为每个项目选择一个运行环境!");
return false;
}
return true;
},
environmentConfigClose() {
// todo
} }
return true;
},
environmentConfigClose() {
// todo
} }
} }
}
</script> </script>
<style scoped> <style scoped>
.ms-scenario-button { .ms-scenario-button {
margin-left: 20px; margin-left: 20px;
} }
.env-confirm { .env-confirm {
margin-left: 20px; margin-left: 20px;
width: 360px; width: 360px;
margin-top: 10px; margin-top: 10px;
} }
.project-name { .project-name {
display:inline-block; display: inline-block;
white-space: nowrap; white-space: nowrap;
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;
width: 150px; width: 150px;
margin-left: 8px; margin-left: 8px;
vertical-align:middle; vertical-align: middle;
} }
</style> </style>

View File

@ -354,7 +354,7 @@ export default {
this.$nextTick(function () { this.$nextTick(function () {
if (this.$refs.caseTable) { if (this.$refs.caseTable) {
this.$refs.caseTable.doLayout(); setTimeout(this.$refs.caseTable.doLayout, 200)
} }
this.checkTableRowIsSelect(); this.checkTableRowIsSelect();
}) })

View File

@ -463,7 +463,7 @@ export default {
// nexttick: // nexttick:
this.$nextTick(function () { this.$nextTick(function () {
if (this.$refs.apiDefinitionTable) { if (this.$refs.apiDefinitionTable) {
this.$refs.apiDefinitionTable.doLayout(); setTimeout(this.$refs.apiDefinitionTable.doLayout, 200)
} }
this.checkTableRowIsSelect(); this.checkTableRowIsSelect();
}) })

View File

@ -397,7 +397,7 @@ export default {
this.$nextTick(() => { this.$nextTick(() => {
if (this.$refs.table) { if (this.$refs.table) {
this.$refs.table.doLayout(); setTimeout(this.$refs.table.doLayout, 200)
} }
this.checkTableRowIsSelect(); this.checkTableRowIsSelect();
}) })

View File

@ -473,7 +473,7 @@ export default {
} }
this.selectRows.clear(); this.selectRows.clear();
if (this.$refs.table) { if (this.$refs.table) {
this.$refs.table.doLayout(); setTimeout(this.$refs.table.doLayout, 200)
} }
}); });
} }

@ -1 +1 @@
Subproject commit afb50f22464b832e4f458f3f7947e6d8f982707e Subproject commit a37e6bb56ffaa7ecc4ee128640e9415304ad41b6