feat(接口定义):完成回收站功能

This commit is contained in:
fit2-zhao 2020-11-27 11:30:47 +08:00
parent 4871c9864a
commit e081448183
10 changed files with 120 additions and 47 deletions

View File

@ -57,6 +57,12 @@ public class ApiDefinitionController {
apiDefinitionService.deleteBatch(ids); apiDefinitionService.deleteBatch(ids);
} }
@PostMapping("/removeToGc")
public void removeToGc(@RequestBody List<String> ids) {
apiDefinitionService.removeToGc(ids);
}
@GetMapping("/get/{id}") @GetMapping("/get/{id}")
public ApiDefinition get(@PathVariable String id) { public ApiDefinition get(@PathVariable String id) {
return apiDefinitionService.get(id); return apiDefinitionService.get(id);

View File

@ -22,7 +22,7 @@ public class ApiDefinitionRequest {
private String userId; private String userId;
private boolean recent = false; private boolean recent = false;
private List<OrderRequest> orders; private List<OrderRequest> orders;
private Map<String, List<String>> filters; private List<String> filters;
private Map<String, Object> combine; private Map<String, Object> combine;
private List<String> ids; private List<String> ids;
} }

View File

@ -52,6 +52,7 @@ public class ApiDefinitionService {
private ApiDefinitionExecResultMapper apiDefinitionExecResultMapper; private ApiDefinitionExecResultMapper apiDefinitionExecResultMapper;
@Resource @Resource
private JMeterService jMeterService; private JMeterService jMeterService;
private static Cache cache = Cache.newHardMemoryCache(0, 3600 * 24); private static Cache cache = Cache.newHardMemoryCache(0, 3600 * 24);
private static final String BODY_FILE_DIR = "/opt/metersphere/data/body"; private static final String BODY_FILE_DIR = "/opt/metersphere/data/body";
@ -118,7 +119,7 @@ public class ApiDefinitionService {
} }
public void delete(String apiId) { public void delete(String apiId) {
apiTestCaseService.checkIsRelateTest(apiId); apiTestCaseService.deleteTestCase(apiId);
deleteFileByTestId(apiId); deleteFileByTestId(apiId);
apiDefinitionExecResultMapper.deleteByResourceId(apiId); apiDefinitionExecResultMapper.deleteByResourceId(apiId);
apiDefinitionMapper.deleteByPrimaryKey(apiId); apiDefinitionMapper.deleteByPrimaryKey(apiId);
@ -132,6 +133,9 @@ public class ApiDefinitionService {
}); });
} }
public void removeToGc(List<String> apiIds) {
apiDefinitionMapper.removeToGc(apiIds);
}
public void deleteBodyFiles(String apiId) { public void deleteBodyFiles(String apiId) {
File file = new File(BODY_FILE_DIR + "/" + apiId); File file = new File(BODY_FILE_DIR + "/" + apiId);

View File

@ -104,6 +104,17 @@ public class ApiTestCaseService {
deleteBodyFiles(testId); deleteBodyFiles(testId);
} }
public void deleteTestCase(String apiId) {
ApiTestCaseExample testCaseExample = new ApiTestCaseExample();
testCaseExample.createCriteria().andApiDefinitionIdEqualTo(apiId);
List<ApiTestCase> testCases = apiTestCaseMapper.selectByExample(testCaseExample);
if (testCases.size() > 0) {
for (ApiTestCase testCase : testCases) {
this.delete(testCase.getId());
}
}
}
/** /**
* 是否已经创建了测试用例 * 是否已经创建了测试用例
*/ */

View File

@ -36,4 +36,7 @@ public interface ApiDefinitionMapper {
int updateByPrimaryKeyWithBLOBs(ApiDefinition record); int updateByPrimaryKeyWithBLOBs(ApiDefinition record);
int updateByPrimaryKey(ApiDefinition record); int updateByPrimaryKey(ApiDefinition record);
int removeToGc(@Param("ids") List<String> ids);
} }

View File

@ -219,7 +219,6 @@
<property name="name" value="request.name"/> <property name="name" value="request.name"/>
</include> </include>
</if> </if>
<if test="request.name != null"> <if test="request.name != null">
and api_definition.name like CONCAT('%', #{request.name},'%') and api_definition.name like CONCAT('%', #{request.name},'%')
</if> </if>
@ -251,17 +250,11 @@
</foreach> </foreach>
</if> </if>
<if test="request.filters != null and request.filters.size() > 0"> <if test="request.filters != null and request.filters.size() > 0">
<foreach collection="request.filters.entrySet()" index="key" item="values">
<if test="values != null and values.size() > 0">
and api_definition.status in and api_definition.status in
<foreach collection="values" item="value" separator="," open="(" close=")"> <foreach collection="request.filters" item="value" separator="," open="(" close=")">
#{value} #{value}
</foreach> </foreach>
</if> </if>
</foreach>
</if>
</where> </where>
<if test="request.orders != null and request.orders.size() > 0"> <if test="request.orders != null and request.orders.size() > 0">
order by order by
@ -411,4 +404,14 @@
update_time = #{updateTime,jdbcType=BIGINT} update_time = #{updateTime,jdbcType=BIGINT}
where id = #{id,jdbcType=VARCHAR} where id = #{id,jdbcType=VARCHAR}
</update> </update>
<update id="removeToGc">
update api_definition
set
status = 'Trash'
where id in
<foreach collection="ids" item="v" separator="," open="(" close=")">
#{v}
</foreach>
</update>
</mapper> </mapper>

View File

@ -252,6 +252,7 @@
/deep/ .el-tabs__header { /deep/ .el-tabs__header {
margin: 0 0 5px; margin: 0 0 5px;
width: calc(100% - 90px);
} }
/deep/ .el-main { /deep/ .el-main {

View File

@ -24,12 +24,10 @@
:label="$t('api_test.definition.api_status')" :label="$t('api_test.definition.api_status')"
show-overflow-tooltip> show-overflow-tooltip>
<template v-slot:default="scope"> <template v-slot:default="scope">
<ms-tag v-if="scope.row.status == 'Prepare'" type="info" <ms-tag v-if="scope.row.status == 'Prepare'" type="info" :content="$t('test_track.plan.plan_status_prepare')"/>
:content="$t('test_track.plan.plan_status_prepare')"/> <ms-tag v-if="scope.row.status == 'Underway'" type="primary" :content="$t('test_track.plan.plan_status_running')"/>
<ms-tag v-if="scope.row.status == 'Underway'" type="primary" <ms-tag v-if="scope.row.status == 'Completed'" type="success" :content="$t('test_track.plan.plan_status_completed')"/>
:content="$t('test_track.plan.plan_status_running')"/> <ms-tag v-if="scope.row.status == 'Trash'" type="danger" content="废弃"/>
<ms-tag v-if="scope.row.status == 'Completed'" type="success"
:content="$t('test_track.plan.plan_status_completed')"/>
</template> </template>
</el-table-column> </el-table-column>
@ -38,9 +36,8 @@
:label="$t('api_test.definition.api_type')" :label="$t('api_test.definition.api_type')"
show-overflow-tooltip> show-overflow-tooltip>
<template v-slot:default="scope" class="request-method"> <template v-slot:default="scope" class="request-method">
<el-tag size="mini" <el-tag size="mini" :style="{'background-color': getColor(true, scope.row.method)}" class="api-el-tag">
:style="{'background-color': getColor(true, scope.row.method)}" class="api-el-tag"> {{ scope.row.method {{ scope.row.method}}
}}
</el-tag> </el-tag>
</template> </template>
</el-table-column> </el-table-column>
@ -112,7 +109,7 @@
import MsContainer from "../../../common/components/MsContainer"; import MsContainer from "../../../common/components/MsContainer";
import MsBottomContainer from "./BottomContainer"; import MsBottomContainer from "./BottomContainer";
import ShowMoreBtn from "../../../../components/track/case/components/ShowMoreBtn"; import ShowMoreBtn from "../../../../components/track/case/components/ShowMoreBtn";
import {API_METHOD_COLOUR} from "../model/JsonData"; import {API_METHOD_COLOUR, FILTER_MAP_1, FILTER_MAP_2} from "../model/JsonData";
export default { export default {
name: "ApiList", name: "ApiList",
@ -172,10 +169,15 @@
}, },
methods: { methods: {
initApiTable() { initApiTable() {
this.condition.filters = ["Prepare", "Underway", "Completed"];
if (this.currentModule != null) { if (this.currentModule != null) {
if (this.currentModule.id == "root") { if (this.currentModule.id == "root") {
this.condition.moduleIds = []; this.condition.moduleIds = [];
} else { } else if (this.currentModule.id == "gc") {
this.condition.moduleIds = [];
this.condition.filters = ["Trash"];
}
else {
this.condition.moduleIds = this.currentModule.ids; this.condition.moduleIds = this.currentModule.ids;
} }
} }
@ -238,6 +240,7 @@
this.$emit('editApi', row); this.$emit('editApi', row);
}, },
handleDeleteBatch() { handleDeleteBatch() {
if (this.currentModule != undefined && this.currentModule.id == "gc") {
this.$alert(this.$t('api_test.definition.request.delete_confirm') + "", '', { this.$alert(this.$t('api_test.definition.request.delete_confirm') + "", '', {
confirmButtonText: this.$t('commons.confirm'), confirmButtonText: this.$t('commons.confirm'),
callback: (action) => { callback: (action) => {
@ -251,6 +254,21 @@
} }
} }
}); });
} else {
this.$alert(this.$t('api_test.definition.request.delete_confirm') + "", '', {
confirmButtonText: this.$t('commons.confirm'),
callback: (action) => {
if (action === 'confirm') {
let ids = Array.from(this.selectRows).map(row => row.id);
this.$post('/api/definition/removeToGc/', ids, () => {
this.selectRows.clear();
this.initApiTable();
this.$success(this.$t('commons.delete_success'));
});
}
}
});
}
}, },
handleTestCase(testCase) { handleTestCase(testCase) {
let h = window.screen.height; let h = window.screen.height;
@ -266,11 +284,26 @@
this.selectApi.url = request.path; this.selectApi.url = request.path;
this.isHide = false; this.isHide = false;
}, },
handleDelete(testCase) { handleDelete(api) {
this.$get('/api/definition/delete/' + testCase.id, () => { if (this.currentModule != undefined && this.currentModule.id == "gc") {
this.$get('/api/definition/delete/' + api.id, () => {
this.$success(this.$t('commons.delete_success')); this.$success(this.$t('commons.delete_success'));
this.initApiTable(); this.initApiTable();
}); });
return;
}
this.$alert(this.$t('api_test.definition.request.delete_confirm') + ' ' + api.name + " ", '', {
confirmButtonText: this.$t('commons.confirm'),
callback: (action) => {
if (action === 'confirm') {
let ids = [api.id];
this.$post('/api/definition/removeToGc/', ids, () => {
this.$success(this.$t('commons.delete_success'));
this.initApiTable();
});
}
}
});
}, },
apiCaseClose() { apiCaseClose() {
let h = window.screen.height; let h = window.screen.height;

View File

@ -54,11 +54,15 @@
class="ms-el-input" size="mini"></el-input> class="ms-el-input" size="mini"></el-input>
</template> </template>
<!-- 如果不是编辑状态 --> <!-- 如果不是编辑状态 -->
<span class="node-title" v-else v-text="data.name"></span> <div v-else>
<i class="el-icon-delete" v-if="data.id==='gc'"/>
<i class="el-icon-folder" v-else/>
<span class="node-title" v-text="data.name"></span>
</div>
<span class="node-operate child"> <span class="node-operate child">
<el-tooltip <el-tooltip
v-if="data.id!='root'" v-if="data.id!='root' && data.id!='gc'"
class="item" class="item"
effect="dark" effect="dark"
:open-delay="200" :open-delay="200"
@ -68,6 +72,7 @@
</el-tooltip> </el-tooltip>
<el-tooltip <el-tooltip
v-if="data.id!='gc'"
class="item" class="item"
effect="dark" effect="dark"
:open-delay="200" :open-delay="200"
@ -77,7 +82,7 @@
</el-tooltip> </el-tooltip>
<el-tooltip <el-tooltip
v-if="data.id!='root'" v-if="data.id!='root' && data.id!='gc'"
class="item" class="item"
effect="dark" effect="dark"
:open-delay="200" :open-delay="200"
@ -114,7 +119,7 @@
options: OPTIONS, options: OPTIONS,
protocol: OPTIONS[0].value, protocol: OPTIONS[0].value,
httpVisible: false, httpVisible: false,
expandedNode: ["root"], expandedNode: [],
filterText: "", filterText: "",
nextFlag: true, nextFlag: true,
currentProject: {}, currentProject: {},
@ -139,17 +144,19 @@
methods: { methods: {
getApiModuleTree() { getApiModuleTree() {
if (this.currentProject) { if (this.currentProject) {
if (this.expandedNode.length === 0) {
this.expandedNode.push("root");
}
this.$get("/api/module/list/" + this.currentProject.id + "/" + this.protocol, response => { this.$get("/api/module/list/" + this.currentProject.id + "/" + this.protocol, response => {
if (response.data != undefined && response.data != null) { if (response.data != undefined && response.data != null) {
this.data[0].children = response.data; this.data[1].children = response.data;
let moduleOptions = []; let moduleOptions = [];
this.data[0].children.forEach(node => { this.data[1].children.forEach(node => {
this.buildNodePath(node, {path: ''}, moduleOptions); this.buildNodePath(node, {path: ''}, moduleOptions);
}); });
this.$emit('getApiModuleTree', moduleOptions); this.$emit('getApiModuleTree', moduleOptions);
} }
}); });
} }
}, },
handleCommand(e) { handleCommand(e) {

View File

@ -14,6 +14,11 @@ export const OPTIONS = [
] ]
export const DEFAULT_DATA = [{ export const DEFAULT_DATA = [{
"id": "gc",
"name": "回收站",
"level": 1,
"children": [],
},{
"id": "root", "id": "root",
"name": "默认模块", "name": "默认模块",
"level": 0, "level": 0,