解决路由跳转传参问题

This commit is contained in:
haifeng414 2020-02-13 22:49:39 +08:00
parent 416553217a
commit c9f185366c
5 changed files with 123 additions and 72 deletions

View File

@ -19,13 +19,15 @@ import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;
@RestController
@RequestMapping(value = "/testplan")
public class TestPlanController {
private static List<LoadTestDTO> loadTests = new ArrayList<>();
private static List<LoadTestDTO> loadTests = Collections.synchronizedList(new ArrayList<LoadTestDTO>());
static {
// 模拟数据
@ -63,7 +65,13 @@ public class TestPlanController {
@PostMapping("/delete")
public void delete(@RequestBody DeleteTestPlanRequest request) {
System.out.println(String.format("delete test plan: %s", request.getName()));
final Iterator<LoadTestDTO> iterator = loadTests.iterator();
while (iterator.hasNext()) {
if (iterator.next().getId().equals(request.getId())) {
iterator.remove();
return;
}
}
}
@PostMapping("/file/upload")

View File

@ -1,10 +1,20 @@
package io.metersphere.controller.request.testplan;
public class TestPlanRequest {
private String id;
private String fileId;
private String project;
private String name;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getFileId() {
return fileId;
}

View File

@ -56,12 +56,23 @@ const router = new VueRouter({
]
},
{
path: "/createTest", components: {
path: "/createTest",
name: "createTest",
components: {
content: CreateTestPlan
},
props: {
content: (route) => {
window.console.log("route.params: " + route.params);
return {
...route.params
}
}
}
},
{
path: "/allTest", components: {
path: "/allTest",
components: {
content: AllTestPlan
}
},

View File

@ -1,4 +1,5 @@
<template>
<div class="testplan-container">
<div>
<el-row>
<el-col :span="22" :offset="1">
@ -49,18 +50,21 @@
</el-table>
</el-col>
</el-row>
<div class="block">
<div class="block">
<el-row>
<el-col :span="22" :offset="1">
<div class="table-page">
<el-pagination
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
:current-page.sync="currentPage"
:page-sizes="[10, 20, 50, 100]"
:page-sizes="[5, 10, 20, 50, 100]"
:page-size="pageSize"
layout="total, sizes, prev, pager, next, jumper"
:total="total">
</el-pagination>
</div>
</el-col>
</el-row>
</div>
</div>
</template>
@ -74,7 +78,7 @@
tableData: [],
multipleSelection: [],
currentPage: 1,
pageSize: 10,
pageSize: 5,
total: 0,
}
},
@ -111,8 +115,12 @@
this.multipleSelection = val;
},
handleEdit(testPlan) {
/// todo:
window.console.log(testPlan);
this.$router.push({
name: 'createTest',
params: {
testPlanObj: testPlan
}
})
},
handleDelete(testPlan) {
this.$alert('确认删除测试: ' + testPlan.name + "", '', {
@ -124,7 +132,7 @@
},
_handleDelete(testPlan) {
let data = {
name: testPlan.name
id: testPlan.id
};
this.$post(this.deletePath, data).then(response => {
@ -133,6 +141,7 @@
message: '删除成功!',
type: 'success'
});
this.initTableData();
} else {
this.$message.error(response.message);
}
@ -143,7 +152,13 @@
</script>
<style scoped>
.el-row {
.testplan-container {
background: white;
}
.table-page {
padding-top: 20px;
margin-right: -9px;
float: right;
}
</style>

View File

@ -44,10 +44,11 @@
TestPlanPressureConfig,
TestPlanAdvancedConfig,
},
props: ['testPlanObj'],
data() {
return {
savePath: "/testplan/save",
testPlan: {},
savePath: "/testplan/save",
projects: [{
id: '选项1',
name: '黄金糕'
@ -80,6 +81,12 @@
}]
}
},
created() {
window.console.log("testPlanObj: " + this.testPlanObj);
if (this.testPlanObj) {
this.testPlan = this.testPlanObj;
}
},
methods: {
save() {
if (!this.validTestPlan()) {