refactor(系统设置):重构环境列表显示

This commit is contained in:
黎龙鑫 2021-04-28 18:27:06 +08:00 committed by jianxing
parent 01171820a2
commit 23749780d9
4 changed files with 86 additions and 40 deletions

View File

@ -1,8 +1,13 @@
package io.metersphere.api.controller; package io.metersphere.api.controller;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import io.metersphere.api.service.ApiTestEnvironmentService; import io.metersphere.api.service.ApiTestEnvironmentService;
import io.metersphere.base.domain.ApiTestEnvironmentWithBLOBs; import io.metersphere.base.domain.ApiTestEnvironmentWithBLOBs;
import io.metersphere.commons.constants.RoleConstants; import io.metersphere.commons.constants.RoleConstants;
import io.metersphere.commons.utils.PageUtils;
import io.metersphere.commons.utils.Pager;
import io.metersphere.controller.request.EnvironmentRequest;
import io.metersphere.service.CheckPermissionService; import io.metersphere.service.CheckPermissionService;
import org.apache.shiro.authz.annotation.Logical; import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles; import org.apache.shiro.authz.annotation.RequiresRoles;
@ -27,6 +32,23 @@ public class ApiTestEnvironmentController {
return apiTestEnvironmentService.list(projectId); return apiTestEnvironmentService.list(projectId);
} }
/**
* 查询指定项目和指定名称的环境
* @param goPage
* @param pageSize
* @param environmentRequest
* @return
*/
@PostMapping("/list/{goPage}/{pageSize}")
public Pager<List<ApiTestEnvironmentWithBLOBs>> listByCondition(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody EnvironmentRequest environmentRequest) {
List<String> projectIds = environmentRequest.getProjectIds();
for (String projectId : projectIds) {
checkPermissionService.checkProjectOwner(projectId);
}
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
return PageUtils.setPageInfo(page, apiTestEnvironmentService.listByConditions(environmentRequest));
}
@GetMapping("/get/{id}") @GetMapping("/get/{id}")
public ApiTestEnvironmentWithBLOBs get(@PathVariable String id) { public ApiTestEnvironmentWithBLOBs get(@PathVariable String id) {
return apiTestEnvironmentService.get(id); return apiTestEnvironmentService.get(id);

View File

@ -7,6 +7,7 @@ import io.metersphere.base.domain.ApiTestEnvironmentExample;
import io.metersphere.base.domain.ApiTestEnvironmentWithBLOBs; import io.metersphere.base.domain.ApiTestEnvironmentWithBLOBs;
import io.metersphere.base.mapper.ApiTestEnvironmentMapper; import io.metersphere.base.mapper.ApiTestEnvironmentMapper;
import io.metersphere.commons.exception.MSException; import io.metersphere.commons.exception.MSException;
import io.metersphere.controller.request.EnvironmentRequest;
import io.metersphere.i18n.Translator; import io.metersphere.i18n.Translator;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -31,6 +32,17 @@ public class ApiTestEnvironmentService {
return apiTestEnvironmentMapper.selectByExampleWithBLOBs(example); return apiTestEnvironmentMapper.selectByExampleWithBLOBs(example);
} }
public List<ApiTestEnvironmentWithBLOBs> listByConditions(EnvironmentRequest environmentRequest) {
ApiTestEnvironmentExample example = new ApiTestEnvironmentExample();
ApiTestEnvironmentExample.Criteria criteria = example.createCriteria();
criteria.andProjectIdIn(environmentRequest.getProjectIds());
if (StringUtils.isNotBlank(environmentRequest.getName())) {
environmentRequest.setName(StringUtils.wrapIfMissing(environmentRequest.getName(),'%')); //使搜索文本变成数据库中的正则表达式
criteria.andNameLike(environmentRequest.getName());
}
return apiTestEnvironmentMapper.selectByExampleWithBLOBs(example);
}
public List<ApiTestEnvironmentWithBLOBs> selectByExampleWithBLOBs(ApiTestEnvironmentExample example) { public List<ApiTestEnvironmentWithBLOBs> selectByExampleWithBLOBs(ApiTestEnvironmentExample example) {
return apiTestEnvironmentMapper.selectByExampleWithBLOBs(example); return apiTestEnvironmentMapper.selectByExampleWithBLOBs(example);
} }

View File

@ -0,0 +1,14 @@
package io.metersphere.controller.request;
import lombok.Getter;
import lombok.Setter;
import java.util.List;
@Getter
@Setter
public class EnvironmentRequest {
private String name; //查询时的环境名称条件
private List<String> projectIds;
}

View File

@ -14,9 +14,8 @@
</ms-table-header> </ms-table-header>
</template> </template>
<!-- 环境列表内容 --> <!-- 环境列表内容 -->
<!-- 实现搜索,根据搜索内容变换显示的环境列表 --> <el-table border :data="environments"
<el-table border :data="environments.filter(env => !searchText || env.name.toLowerCase().includes(searchText.toLowerCase()))" @selection-change="handleSelectionChange" class="adjust-table" style="width: 100%" ref="table">
@selection-change="handleSelectionChange" max-height="515" class="adjust-table" style="width: 100%" ref="table">
<el-table-column type="selection"></el-table-column> <el-table-column type="selection"></el-table-column>
<el-table-column :label="$t('commons.project')" width="250" show-overflow-tooltip> <el-table-column :label="$t('commons.project')" width="250" show-overflow-tooltip>
<template v-slot="scope"> <template v-slot="scope">
@ -42,9 +41,8 @@
</template> </template>
</el-table-column> </el-table-column>
</el-table> </el-table>
<el-row type="flex" justify="end"> <ms-table-pagination :change="list" :current-page.sync="currentPage" :page-size.sync="pageSize"
<el-pagination layout="total" :total="total"></el-pagination> :total="total"/>
</el-row>
</el-card> </el-card>
<!-- 创建编辑复制环境时的对话框 --> <!-- 创建编辑复制环境时的对话框 -->
@ -126,7 +124,7 @@
return { return {
btnTips: this.$t('api_test.environment.create'), btnTips: this.$t('api_test.environment.create'),
projectList: [], projectList: [],
condition: {envName: ''}, // condition: {}, //
environments: [], environments: [],
currentEnvironment: new Environment(), currentEnvironment: new Environment(),
result: {}, result: {},
@ -138,20 +136,21 @@
isTesterPermission: false, isTesterPermission: false,
domainVisible: false, domainVisible: false,
conditions: [], conditions: [],
currentPage: 1,
pageSize: 10,
total: 0,
projectIds: [], //id
} }
}, },
computed: { created() {
searchText() { // this.isTesterPermission = checkoutTestManagerOrTestUser();
return this.condition.name;
},
/*
搜索后对应的总条目搜索内容为空的话就是全部记录条数搜索内容不为空的话就是匹配的记录条数
*/
total() {
return this.environments
.filter(env => !this.searchText || env.name.toLowerCase().includes(this.searchText.toLowerCase())).length;
},
}, },
activated() {
this.list();
},
watch: { watch: {
//projectId //projectId
currentProjectId() { currentProjectId() {
@ -203,22 +202,26 @@
} }
}, },
list() { list() {
this.environments = []; if (!this.projectList || this.projectList.length === 0) { //
let url = "/project/listAll"; this.$get("/project/listAll", (response) => {
this.result = this.$get(url, (response) => { // this.projectList = response.data; //,
this.projectList = response.data; //, this.projectList.forEach(project => {
this.projectList.forEach(project => { this.idNameMap.set(project.id, project.name);
this.idNameMap.set(project.id, project.name); this.projectIds.push(project.id);
}); });
// this.getEnvironments();
this.projectList.map((project) => {
this.$get('/api/environment/list/' + project.id, response => {
let envData = response.data;
envData.forEach(env => {
this.environments.push(env);
})
})
}) })
} else {
this.getEnvironments()
}
},
getEnvironments(){
this.environments = [];
this.condition.projectIds = this.projectIds;
let url = '/api/environment/list/' + this.currentPage + '/' + this.pageSize;
this.result = this.$post(url, this.condition, response => {
this.environments = response.data.listObject;
this.total = response.data.itemCount;
}) })
}, },
createEnv() { createEnv() {
@ -227,7 +230,8 @@
this.dialogVisible = true; this.dialogVisible = true;
this.currentEnvironment = new Environment(); this.currentEnvironment = new Environment();
}, },
search(searchText) { search() {
this.list()
}, },
editEnv(environment) { editEnv(environment) {
this.dialogTitle = this.$t('api_test.environment.config_environment'); this.dialogTitle = this.$t('api_test.environment.config_environment');
@ -334,13 +338,7 @@
} }
}, },
created() {
this.isTesterPermission = checkoutTestManagerOrTestUser();
},
activated() {
this.list();
},
} }