高级设置 +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); return loadTestService.get(testId);
} }
@GetMapping("/get-advanced-config/{testId}")
public String getAdvancedConfiguration(@PathVariable String testId) {
return loadTestService.getAdvancedConfiguration(testId);
}
@PostMapping("/delete") @PostMapping("/delete")
public void delete(@RequestBody DeleteTestPlanRequest request) { public void delete(@RequestBody DeleteTestPlanRequest request) {
loadTestService.delete(request); loadTestService.delete(request);

View File

@ -20,6 +20,7 @@ import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
import java.util.Optional;
import java.util.UUID; import java.util.UUID;
@Service @Service
@ -124,6 +125,7 @@ public class LoadTestService {
loadTest.setScenarioDefinition("todo"); loadTest.setScenarioDefinition("todo");
loadTest.setDescription("todo"); loadTest.setDescription("todo");
loadTest.setLoadConfiguration(request.getLoadConfiguration()); loadTest.setLoadConfiguration(request.getLoadConfiguration());
loadTest.setAdvancedConfiguration(request.getAdvancedConfiguration());
loadTestMapper.updateByPrimaryKeySelective(loadTest); loadTestMapper.updateByPrimaryKeySelective(loadTest);
} }
@ -184,4 +186,9 @@ public class LoadTestService {
} }
return null; 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', 'params': 'Parameters',
'param_name': 'Name', 'param_name': 'Name',
'param_value': 'Value', '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: { i18n: {
'home': 'Home', 'home': 'Home',

View File

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

View File

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

View File

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