fix(接口自动化): 跨项目添加场景

This commit is contained in:
shiziyuan9527 2021-02-25 11:22:01 +08:00
parent ef08532187
commit 6417a131b0
5 changed files with 49 additions and 34 deletions

View File

@ -32,7 +32,7 @@ public class ServiceUtils {
* @return
*/
public static<T> void getSelectAllIds( T batchRequest, BaseQueryRequest queryRequest, Function<BaseQueryRequest, List<String>> func) {
if (queryRequest.isSelectAll()) {
if (queryRequest != null && queryRequest.isSelectAll()) {
List<String> ids = func.apply(queryRequest);
if (!ids.isEmpty()) {
ids = ids.stream()

View File

@ -3,21 +3,23 @@
title="环境选择"
:visible.sync="dialogVisible"
width="30%"
:destroy-on-close="true"
:before-close="handleClose">
<div v-for="pe in data" :key="pe.id">
<div>
{{ getProjectName(pe.id) }}
<el-select v-model="pe['selectEnv']" placeholder="请选择环境" style="margin-left:10px; margin-top: 10px;" size="small">
<el-select v-model="pe['selectEnv']" placeholder="请选择环境" style="margin-left:10px; margin-top: 10px;"
size="small">
<el-option v-for="(environment, index) in pe.envs" :key="index"
:label="environment.name + (environment.config.httpConfig.socket ? (': ' + environment.config.httpConfig.protocol + '://' + environment.config.httpConfig.socket) : '')"
:value="environment.id"/>
<el-button class="ms-scenario-button" size="mini" type="primary" @click="openEnvironmentConfig">
<el-button class="ms-scenario-button" size="mini" type="primary" @click="openEnvironmentConfig(pe.id)">
{{ $t('api_test.environment.environment_config') }}
</el-button>
<template v-slot:empty>
<div class="empty-environment">
<el-button class="ms-scenario-button" size="mini" type="primary" @click="openEnvironmentConfig">
<el-button class="ms-scenario-button" size="mini" type="primary" @click="openEnvironmentConfig(pe.id)">
{{ $t('api_test.environment.environment_config') }}
</el-button>
</div>
@ -30,14 +32,16 @@
<el-button @click="dialogVisible = false" size="small"> </el-button>
<el-button type="primary" @click="handleConfirm" size="small"> </el-button>
</span>
<api-environment-config ref="environmentConfig" @close="environmentConfigClose"/>
</el-dialog>
</template>
<script>
import {parseEnvironment} from "@/business/components/api/test/model/EnvironmentModel";
import ApiEnvironmentConfig from "@/business/components/api/definition/components/environment/ApiEnvironmentConfig";
export default {
name: "ApiScenarioEnv",
components: {ApiEnvironmentConfig},
props: {
projectIds: Set,
envMap: Map
@ -55,13 +59,8 @@ export default {
this.getWsProjects();
},
methods: {
handleClose(done) {
this.$confirm('确认关闭?')
.then(_ => {
done();
})
.catch(_ => {
});
handleClose() {
this.dialogVisible = false;
},
init() {
this.projectIds.forEach(id => {
@ -92,20 +91,14 @@ export default {
},
getProjectName(id) {
const project = this.projects.find(p => p.id === id);
if (project) {
return project.name;
}
return '';
return project ? project.name : "";
},
openEnvironmentConfig() {
if (!this.projectId) {
openEnvironmentConfig(projectId) {
if (!projectId) {
this.$error(this.$t('api_test.select_project'));
return;
}
this.$refs.environmentConfig.open(this.projectId);
},
getProjectEnvMap() {
this.$refs.environmentConfig.open(projectId);
},
handleConfirm() {
let map = new Map();
@ -123,6 +116,23 @@ export default {
}
this.$emit('setProjectEnvMap', map);
this.dialogVisible = false;
},
checkEnv() {
let sign = true;
this.data.forEach(dt => {
if (!dt.selectEnv) {
sign = false;
return;
}
})
if (!sign) {
this.$warning("请为每个项目选择一个运行环境!");
return false;
}
return true;
},
environmentConfigClose(id) {
// todo
}
}
}

View File

@ -593,7 +593,7 @@
scenarioIds.push(row.id);
run.id = getUUID();
run.projectId = getCurrentProjectID();
run.scenarioIds = scenarioIds;
run.ids = scenarioIds;
this.$post(url, run, response => {
let data = response.data;
this.runVisible = true;

View File

@ -662,6 +662,9 @@ export default {
const index = hashTree.findIndex(d => d.resourceId != undefined && row.resourceId != undefined && d.resourceId === row.resourceId)
if (hashTree[index] && hashTree[index].projectId) {
this.projectIds.delete(hashTree[index].projectId);
if (this.projectEnvMap.has(hashTree[index].projectId)) {
this.projectEnvMap.delete(hashTree[index].projectId);
}
}
hashTree.splice(index, 1);
this.sort();
@ -701,12 +704,9 @@ export default {
// this.$error(this.$t('api_test.environment.select_environment'));
// return;
// }
let iter = this.projectEnvMap.values();
for (let i of iter) {
if (!i) {
this.$warning("请为每个项目选择一个运行环境!");
return;
}
let sign = this.$refs.apiScenarioEnv.checkEnv();
if (!sign) {
return;
}
this.$refs['currentScenario'].validate((valid) => {
if (valid) {

View File

@ -17,7 +17,7 @@
<el-tag size="mini" style="margin-left: 20px" v-if="scenario.referenced==='Copy'">{{ $t('commons.copy') }}</el-tag>
<el-tag size="mini" style="margin-left: 20px" v-if="scenario.referenced==='REF'">{{ $t('api_test.scenario.reference') }}</el-tag>
<span style="margin-left: 20px;">{{scenario.projectName}}</span>
<span style="margin-left: 20px;">{{getProjectName(scenario.projectId)}}</span>
</template>
</api-base-component>
@ -44,8 +44,9 @@
},
watch: {},
created() {
this.getWsProjects();
getProject.$emit('addProjectEnv', this.scenario.projectId, this.currentEnvironmentId);
if (this.scenario.id && this.scenario.referenced === 'REF' && !this.scenario.loaded) {
this.getWsProjects();
this.result = this.$get("/api/automation/getApiScenario/" + this.scenario.id, response => {
if (response.data) {
this.scenario.loaded = true;
@ -57,9 +58,6 @@
}
this.scenario.disabled = true;
this.scenario.name = response.data.name;
const project = this.projects.find(p => p.id === this.scenario.projectId);
getProject.$emit('addProjectEnv', this.scenario.projectId, this.currentEnvironmentId);
this.scenario.projectName = project ? project.name : '';
this.$emit('refReload');
} else {
this.scenario.referenced = "Deleted";
@ -122,6 +120,13 @@
this.$get("/project/listAll", res => {
this.projects = res.data;
})
},
getProjectName(id) {
const project = this.projects.find(p => p.id === id);
if (project) {
return project.name;
}
return '';
}
}
}