解决路由跳转传参问题

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 javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@RestController @RestController
@RequestMapping(value = "/testplan") @RequestMapping(value = "/testplan")
public class TestPlanController { public class TestPlanController {
private static List<LoadTestDTO> loadTests = new ArrayList<>(); private static List<LoadTestDTO> loadTests = Collections.synchronizedList(new ArrayList<LoadTestDTO>());
static { static {
// 模拟数据 // 模拟数据
@ -63,7 +65,13 @@ public class TestPlanController {
@PostMapping("/delete") @PostMapping("/delete")
public void delete(@RequestBody DeleteTestPlanRequest request) { 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") @PostMapping("/file/upload")

View File

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

View File

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

View File

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

View File

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