高级设置 +1

This commit is contained in:
Captain.B 2020-02-28 17:00:22 +08:00
parent 44743620d4
commit a7d27e8668
6 changed files with 110 additions and 47 deletions

View File

@ -69,6 +69,11 @@ public class LoadTestController {
return loadTestService.get(testId);
}
@GetMapping("/get-advanced-config/{testId}")
public String getAdvancedConfiguration(@PathVariable String testId) {
return loadTestService.getAdvancedConfiguration(testId);
}
@PostMapping("/delete")
public void delete(@RequestBody DeleteTestPlanRequest request) {
loadTestService.delete(request);

View File

@ -20,6 +20,7 @@ import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
@Service
@ -124,6 +125,7 @@ public class LoadTestService {
loadTest.setScenarioDefinition("todo");
loadTest.setDescription("todo");
loadTest.setLoadConfiguration(request.getLoadConfiguration());
loadTest.setAdvancedConfiguration(request.getAdvancedConfiguration());
loadTestMapper.updateByPrimaryKeySelective(loadTest);
}
@ -184,4 +186,9 @@ public class LoadTestService {
}
return null;
}
public String getAdvancedConfiguration(String testId) {
LoadTestWithBLOBs loadTestWithBLOBs = loadTestMapper.selectByPrimaryKey(testId);
return Optional.ofNullable(loadTestWithBLOBs).orElse(new LoadTestWithBLOBs()).getAdvancedConfiguration();
}
}

View File

@ -93,6 +93,10 @@ export default {
'params': 'Parameters',
'param_name': 'Name',
'param_value': 'Value',
'domain_is_duplicate': 'Domain is duplicated',
'param_is_duplicate': 'Parameter name is duplicate',
'domain_ip_is_empty': 'Domain and IP cannot be empty',
'param_name_value_is_empty': 'Parameters cannot be empty',
},
i18n: {
'home': 'Home',

View File

@ -93,6 +93,10 @@ export default {
'params': '自定义属性',
'param_name': '属性名',
'param_value': '属性值',
'domain_is_duplicate': '域名不能重复',
'param_is_duplicate': '参数名不能重复',
'domain_ip_is_empty': '域名和IP不能为空',
'param_name_value_is_empty': '参数名和参数值不能为空',
},
i18n: {
'home': '首页',

View File

@ -76,7 +76,6 @@
},
watch: {
'$route'(to) {
window.console.log(to);
//
if (to.name === 'createTest') {
window.location.reload();
@ -117,6 +116,7 @@
message: this.$t('commons.save_success'),
type: 'success'
});
this.$refs.advancedConfig.cancelAllEdit();
});
},
saveAndRun() {
@ -151,6 +151,9 @@
if (this.testPlan.loadConfigurationObj) {
this.testPlan.loadConfiguration = JSON.stringify(this.testPlan.loadConfigurationObj);
}
//
this.testPlan.advancedConfiguration = JSON.stringify(this.$refs.advancedConfig.configurations());
// filejson
let requestJson = JSON.stringify(this.testPlan, function (key, value) {
return key === "file" ? undefined : value
@ -201,10 +204,6 @@
}
if (!this.$refs.advancedConfig.validConfig()) {
this.$message({
message: this.$t('load_test.advanced_config_error'),
type: 'error'
});
return false;
}

View File

@ -1,5 +1,5 @@
<template>
<div class="el-tab-pane-box">
<div>
<el-row type="flex" justify="start">
<el-col :span="8">
@ -48,7 +48,7 @@
</template>
</el-table-column>
<el-table-column align="center">
<template slot-scope="{row}">
<template slot-scope="{row, $index}">
<template v-if="row.edit">
<el-button
class="cancel-btn"
@ -79,7 +79,7 @@
size="mini"
icon="el-icon-delete"
circle
@click="del(row, 'domains', 'domain')">
@click="del(row, 'domains', $index)">
</el-button>
</template>
</el-table-column>
@ -134,7 +134,7 @@
</template>
</el-table-column>
<el-table-column align="center">
<template slot-scope="{row}">
<template slot-scope="{row, $index}">
<template v-if="row.edit">
<el-button
class="cancel-btn"
@ -165,7 +165,7 @@
size="mini"
icon="el-icon-delete"
circle
@click="del(row, 'params', 'name')">
@click="del(row, 'params', $index)">
</el-button>
</template>
</el-table-column>
@ -174,12 +174,12 @@
<el-row>
<el-col :span="8">
建立连接超时时间 10 ms
建立连接超时时间 {{timeout}} ms
</el-col>
</el-row>
<el-row>
<el-col :span="8">
自定义 HTTP 响应成功状态码 302
自定义 HTTP 响应成功状态码 {{statusCode}}
</el-col>
</el-row>
</div>
@ -190,18 +190,25 @@
name: "MsTestPlanAdvancedConfig",
data() {
return {
domains: [
{domain: 'baidu.com0', enable: true, ip: '127.0.0.1', edit: false},
{domain: 'baidu.com1', enable: true, ip: '127.0.0.1', edit: false},
{domain: 'baidu.com2', enable: true, ip: '127.0.0.1', edit: false},
{domain: 'baidu.com3', enable: true, ip: '127.0.0.1', edit: false},
],
params: [
{name: 'param1', value: '13134', enable: true, edit: false},
{name: 'param2', value: '13134', enable: true, edit: false},
{name: 'param3', value: '13134', enable: true, edit: false},
{name: 'param4', value: '13134', enable: true, edit: false},
]
timeout: 10,
statusCode: [302],
domains: [],
params: [],
}
},
mounted() {
let testId = this.$route.path.split('/')[2];
if (testId) {
this.$get('/testplan/get-advanced-config/' + testId, response => {
let data = JSON.parse(response.data);
this.timeout = data.timeout;
this.statusCode = data.statusCode;
this.domains = data.domains;
this.params = data.params;
this.domains.forEach(d => d.edit = false);
this.params.forEach(d => d.edit = false);
});
}
},
methods: {
@ -215,21 +222,26 @@
row[key + 'Origin'] = row[key];
});
},
delOriginObject(row) {
Object.keys(row).forEach(function (key) {
delete row[key + 'Origin'];
});
},
add(dataName) {
if (dataName === 'domains') {
this[dataName].push({
domain: '',
domain: 'fit2cloud.com',
enable: true,
ip: '',
edit: false,
ip: '127.0.0.1',
edit: true,
});
}
if (dataName === 'params') {
this[dataName].push({
name: '',
name: 'param1',
enable: true,
value: '',
edit: false,
value: '0',
edit: true,
});
}
},
@ -237,30 +249,66 @@
this.saveOriginObject(row);
row.edit = !row.edit
},
del(row, dataName, id) {
this[dataName] = this[dataName].filter((d) => d[id] !== row[id]);
del(row, dataName, index) {
this[dataName].splice(index, 1);
},
cancelEdit(row) {
row.edit = false;
// rollback changes
this.revertObject(row);
this.$message({
message: 'The row has been restored to the original value',
type: 'warning'
})
},
confirmEdit(row) {
row.edit = false;
this.saveOriginObject(row);
this.$message({
message: 'The row has been edited',
type: 'success'
})
},
groupBy(data, key) {
return data.reduce((p, c) => {
let name = c[key];
if (!p.hasOwnProperty(name)) {
p[name] = 0;
}
p[name]++;
return p;
}, {});
},
validConfig() {
return this.domains.filter(d => !d.domain || !d.ip).length === 0
&&
this.params.filter(d => !d.name || !d.value).length === 0;
let counts = this.groupBy(this.domains, 'domain');
for (let c in counts) {
if (counts[c] > 1) {
this.$message.error(this.$t('load_test.domain_is_duplicate'));
return false;
}
}
counts = this.groupBy(this.params, 'name');
for (let c in counts) {
if (counts[c] > 1) {
this.$message.error(this.$t('load_test.param_is_duplicate'));
return false;
}
}
if (this.domains.filter(d => !d.domain || !d.ip).length > 0) {
this.$message.error(this.$t('load_test.domain_ip_is_empty'));
return false;
}
if (this.params.filter(d => !d.name || !d.value).length > 0) {
this.$message.error(this.$t('load_test.param_name_value_is_empty'));
return false;
}
return true;
},
cancelAllEdit() {
this.domains.forEach(d => d.edit = false);
this.params.forEach(d => d.edit = false);
},
configurations() {
this.domains.forEach(d => this.delOriginObject(d));
this.params.forEach(d => this.delOriginObject(d));
return {
timeout: this.timeout,
statusCode: this.statusCode,
params: this.params,
domains: this.domains,
}
},
}
}
@ -275,8 +323,4 @@
padding-right: 100px;
}
.container-tab >>> .el-tabs__content {
flex-grow: 1;
overflow-y: scroll;
}
</style>