feat(接口自动化): 完成场景变量基础存储功能

This commit is contained in:
fit2-zhao 2021-01-08 15:54:45 +08:00
parent 7c3b718863
commit 30762dae9f
9 changed files with 213 additions and 456 deletions

View File

@ -133,7 +133,7 @@ public class ApiAutomationController {
} }
@PostMapping("/file/download") @PostMapping("/file/download")
public ResponseEntity<byte[]> downloadJmx(@RequestBody FileOperationRequest fileOperationRequest) { public ResponseEntity<byte[]> download(@RequestBody FileOperationRequest fileOperationRequest) {
byte[] bytes = apiAutomationService.loadFileAsBytes(fileOperationRequest); byte[] bytes = apiAutomationService.loadFileAsBytes(fileOperationRequest);
return ResponseEntity.ok() return ResponseEntity.ok()
.contentType(MediaType.parseMediaType("application/octet-stream")) .contentType(MediaType.parseMediaType("application/octet-stream"))

View File

@ -234,7 +234,7 @@ public class ApiDefinitionService {
test.setResponse(JSONObject.toJSONString(request.getResponse())); test.setResponse(JSONObject.toJSONString(request.getResponse()));
test.setEnvironmentId(request.getEnvironmentId()); test.setEnvironmentId(request.getEnvironmentId());
test.setUserId(request.getUserId()); test.setUserId(request.getUserId());
test.setTags(JSON.toJSONString(new HashSet<>(request.getTags()))); test.setTags(request.getTags());
apiDefinitionMapper.updateByPrimaryKeySelective(test); apiDefinitionMapper.updateByPrimaryKeySelective(test);
return test; return test;
@ -265,7 +265,7 @@ public class ApiDefinitionService {
test.setUserId(request.getUserId()); test.setUserId(request.getUserId());
} }
test.setDescription(request.getDescription()); test.setDescription(request.getDescription());
test.setTags(JSON.toJSONString(new HashSet<>(request.getTags()))); test.setTags(request.getTags());
apiDefinitionMapper.insert(test); apiDefinitionMapper.insert(test);
return test; return test;
} }
@ -341,10 +341,11 @@ public class ApiDefinitionService {
/** /**
* 内部构建HashTree 定时任务发起的执行 * 内部构建HashTree 定时任务发起的执行
*
* @param request * @param request
* @return * @return
*/ */
public String run(RunDefinitionRequest request,ApiTestCaseWithBLOBs item) { public String run(RunDefinitionRequest request, ApiTestCaseWithBLOBs item) {
MsTestPlan testPlan = new MsTestPlan(); MsTestPlan testPlan = new MsTestPlan();
testPlan.setHashTree(new LinkedList<>()); testPlan.setHashTree(new LinkedList<>());
HashTree jmeterHashTree = new ListedHashTree(); HashTree jmeterHashTree = new ListedHashTree();
@ -361,12 +362,14 @@ public class ApiDefinitionService {
// 多态JSON普通转换会丢失内容需要通过 ObjectMapper 获取 // 多态JSON普通转换会丢失内容需要通过 ObjectMapper 获取
if (element != null && StringUtils.isNotEmpty(element.getString("hashTree"))) { if (element != null && StringUtils.isNotEmpty(element.getString("hashTree"))) {
LinkedList<MsTestElement> elements = mapper.readValue(element.getString("hashTree"), LinkedList<MsTestElement> elements = mapper.readValue(element.getString("hashTree"),
new TypeReference<LinkedList<MsTestElement>>() {}); new TypeReference<LinkedList<MsTestElement>>() {
});
scenario.setHashTree(elements); scenario.setHashTree(elements);
} }
if (StringUtils.isNotEmpty(element.getString("variables"))) { if (StringUtils.isNotEmpty(element.getString("variables"))) {
LinkedList<KeyValue> variables = mapper.readValue(element.getString("variables"), LinkedList<ScenarioVariable> variables = mapper.readValue(element.getString("variables"),
new TypeReference<LinkedList<KeyValue>>() {}); new TypeReference<LinkedList<ScenarioVariable>>() {
});
scenario.setVariables(variables); scenario.setVariables(variables);
} }
group.setEnableCookieShare(scenario.isEnableCookieShare()); group.setEnableCookieShare(scenario.isEnableCookieShare());
@ -571,9 +574,9 @@ public class ApiDefinitionService {
apiDefinitionMapper.deleteByExample(example); apiDefinitionMapper.deleteByExample(example);
} }
private List<String> getAllApiIdsByFontedSelect(List<String> filter, String name, List<String> moduleIds, String projectId, List<String> unSelectIds) { private List<String> getAllApiIdsByFontedSelect(Map<String, List<String>> filters, String name, List<String> moduleIds, String projectId, List<String> unSelectIds) {
ApiDefinitionRequest request = new ApiDefinitionRequest(); ApiDefinitionRequest request = new ApiDefinitionRequest();
request.setFilters(filter); request.setFilters(filters);
request.setName(name); request.setName(name);
request.setModuleIds(moduleIds); request.setModuleIds(moduleIds);
request.setProjectId(projectId); request.setProjectId(projectId);
@ -621,4 +624,4 @@ public class ApiDefinitionService {
} }
} }
} }
} }

View File

@ -6,7 +6,7 @@
<el-col> <el-col>
<!--操作按钮--> <!--操作按钮-->
<div class="ms-opt-btn"> <div class="ms-opt-btn">
<el-button type="primary" size="small" @click="editScenario">{{$t('commons.save')}}</el-button> <el-button type="primary" size="small" @click="editScenario(true)">{{$t('commons.save')}}</el-button>
</div> </div>
</el-col> </el-col>
</el-row> </el-row>
@ -220,7 +220,7 @@
</el-drawer> </el-drawer>
<!--场景公共参数--> <!--场景公共参数-->
<ms-variable-list :currentScenario="currentScenario" @setVariables="setVariables" ref="scenarioParameters"/> <ms-variable-list @setVariables="setVariables" ref="scenarioParameters"/>
<!--外部导入--> <!--外部导入-->
<api-import ref="apiImport" :saved="false" @refresh="apiImport"/> <api-import ref="apiImport" :saved="false" @refresh="apiImport"/>
</div> </div>
@ -456,6 +456,10 @@
}, },
setVariables(v) { setVariables(v) {
this.currentScenario.variables = v; this.currentScenario.variables = v;
if (this.path.endsWith("/update")) {
//
this.editScenario();
}
}, },
showButton(...names) { showButton(...names) {
for (const name of names) { for (const name of names) {
@ -677,12 +681,17 @@
this.$error(this.$t('api_test.environment.select_environment')); this.$error(this.$t('api_test.environment.select_environment'));
return; return;
} }
this.debugData = { this.$refs['currentScenario'].validate((valid) => {
id: this.currentScenario.id, name: this.currentScenario.name, type: "scenario", if (valid) {
variables: this.currentScenario.variables, referenced: 'Created', enableCookieShare: this.enableCookieShare, this.editScenario();
environmentId: this.currentEnvironmentId, hashTree: this.scenarioDefinition this.debugData = {
}; id: this.currentScenario.id, name: this.currentScenario.name, type: "scenario",
this.reportId = getUUID().substring(0, 8); variables: this.currentScenario.variables, referenced: 'Created', enableCookieShare: this.enableCookieShare,
environmentId: this.currentEnvironmentId, hashTree: this.scenarioDefinition
};
this.reportId = getUUID().substring(0, 8);
}
})
}, },
getEnvironments() { getEnvironments() {
if (this.projectId) { if (this.projectId) {
@ -821,13 +830,15 @@
}) })
return bodyUploadFiles; return bodyUploadFiles;
}, },
editScenario() { editScenario(showMessage) {
this.$refs['currentScenario'].validate((valid) => { this.$refs['currentScenario'].validate((valid) => {
if (valid) { if (valid) {
this.setParameter(); this.setParameter();
let bodyFiles = this.getBodyUploadFiles(this.currentScenario); let bodyFiles = this.getBodyUploadFiles(this.currentScenario);
this.$fileUpload(this.path, null, bodyFiles, this.currentScenario, response => { this.$fileUpload(this.path, null, bodyFiles, this.currentScenario, response => {
this.$success(this.$t('commons.save_success')); if (showMessage) {
this.$success(this.$t('commons.save_success'));
}
this.path = "/api/automation/update"; this.path = "/api/automation/update";
if (response.data) { if (response.data) {
this.currentScenario.id = response.data.id; this.currentScenario.id = response.data.id;

View File

@ -1,81 +1,30 @@
<template> <template>
<el-dialog append-to-body :close-on-click-modal="false" :title="$t('api_test.scenario.variables')" <el-form :model="editData" label-position="right" label-width="80px" size="small" ref="form">
:visible.sync="visible" class="environment-dialog" width="40%" <el-form-item :label="$t('api_test.variable_name')" prop="name">
@close="close"> <el-input v-model="editData.name" :placeholder="$t('api_test.variable_name')"></el-input>
<el-form :model="form" label-position="right" label-width="80px" size="small" ref="form" :rules="rule"> </el-form-item>
<el-form-item :label="$t('api_test.variable_name')" prop="name">
<el-input v-model="form.name" :placeholder="$t('api_test.variable_name')"></el-input>
</el-form-item>
<el-form-item :label="$t('commons.description')" prop="description"> <el-form-item :label="$t('commons.description')" prop="description">
<el-input class="ms-http-textarea" <el-input class="ms-http-textarea"
v-model="form.description" v-model="editData.description"
type="textarea" type="textarea"
:autosize="{ minRows: 2, maxRows: 10}" :autosize="{ minRows: 2, maxRows: 10}"
:rows="2" size="small"/> :rows="2" size="small"/>
</el-form-item> </el-form-item>
<el-form-item :label="$t('api_test.value')" prop="value"> <el-form-item :label="$t('api_test.value')" prop="value">
<el-input v-model="form.value" :placeholder="$t('api_test.value')"></el-input> <el-input v-model="editData.value" :placeholder="$t('api_test.value')"></el-input>
</el-form-item> </el-form-item>
</el-form> </el-form>
<template v-slot:footer>
<ms-dialog-footer
@cancel="close"
@confirm="saveParameters"/>
</template>
</el-dialog>
</template> </template>
<script> <script>
import MsDialogFooter from "../../../../common/components/MsDialogFooter";
export default { export default {
name: "MsEditConstant", name: "MsEditConstant",
components: { components: {},
MsDialogFooter props: {
editData: {},
}, },
data() {
return {
visible: false,
form: {type: "CONSTANT"},
editFlag: false,
rule: {
name: [
{required: true, message: this.$t('api_test.variable_name'), trigger: 'blur'},
],
},
}
},
methods: {
open: function (v) {
this.visible = true;
if (v) {
this.form = v;
this.editFlag = true;
} else {
this.form = {};
this.editFlag = false;
}
this.form.type = "CONSTANT";
},
close() {
this.visible = false;
this.form = {};
},
saveParameters() {
this.$refs['form'].validate((valid) => {
if (valid) {
this.visible = false;
if (!this.editFlag) {
this.$emit('addParameters', this.form);
}
}
});
}
}
} }
</script> </script>

View File

@ -1,89 +1,38 @@
<template> <template>
<el-dialog append-to-body :close-on-click-modal="false" title="计数器编辑" <el-form :model="editData" label-position="right" label-width="80px" size="small" ref="form2">
:visible.sync="visible" class="environment-dialog" width="610px"
@close="close">
<el-form :model="form" label-position="right" label-width="80px" size="small" ref="form" :rules="rule">
<el-form-item :label="$t('api_test.variable_name')" prop="name"> <el-form-item :label="$t('api_test.variable_name')" prop="name">
<el-input v-model="form.name" :placeholder="$t('api_test.variable_name')"></el-input> <el-input v-model="editData.name" :placeholder="$t('api_test.variable_name')"></el-input>
</el-form-item> </el-form-item>
<el-form-item :label="$t('commons.description')" prop="description"> <el-form-item :label="$t('commons.description')" prop="description">
<el-input class="ms-http-textarea" <el-input class="ms-http-textarea"
v-model="form.description" v-model="editData.description"
type="textarea" type="textarea"
:autosize="{ minRows: 2, maxRows: 10}" :autosize="{ minRows: 2, maxRows: 10}"
:rows="2" size="small"/> :rows="2" size="small"/>
</el-form-item> </el-form-item>
<el-form-item label="开始" prop="set"> <el-form-item label="开始" prop="set">
<el-input-number size="small" v-model="form.startNumber" placeholder="0" :max="1000*10000000" :min="0"/> <el-input-number size="small" v-model="editData.startNumber" placeholder="0" :max="1000*10000000" :min="0"/>
<span style="margin: 0px 10px 10px ">结束</span> <span style="margin: 0px 10px 10px ">结束</span>
<el-input-number size="small" v-model="form.endNumber" placeholder="10" :max="1000*10000000" :min="0"/> <el-input-number size="small" v-model="editData.endNumber" placeholder="10" :max="1000*10000000" :min="0"/>
<span style="margin: 0px 10px 10px ">增量</span> <span style="margin: 0px 10px 10px ">增量</span>
<el-input-number size="small" v-model="form.increment" placeholder="1" :max="1000*10000000" :min="0"/> <el-input-number size="small" v-model="editData.increment" placeholder="1" :max="1000*10000000" :min="0"/>
</el-form-item> </el-form-item>
<el-form-item label="开始" prop="value"> <el-form-item label="开始" prop="value">
<el-input v-model="form.value" placeholder="000产生至少3位数字。user_000输出形式为user_nnn"></el-input> <el-input v-model="editData.value" placeholder="000产生至少3位数字。user_000输出形式为user_nnn"></el-input>
</el-form-item> </el-form-item>
</el-form> </el-form>
<template v-slot:footer>
<ms-dialog-footer
@cancel="close"
@confirm="saveParameters"/>
</template>
</el-dialog>
</template> </template>
<script> <script>
import MsDialogFooter from "../../../../common/components/MsDialogFooter";
export default { export default {
name: "MsEditCounter", name: "MsEditCounter",
components: { components: {},
MsDialogFooter props: {
editData: {},
}, },
data() {
return {
visible: false,
form: {type: "COUNTER"},
editFlag: false,
rule: {
name: [
{required: true, message: this.$t('api_test.variable_name'), trigger: 'blur'},
],
},
}
},
methods: {
open: function (v) {
this.visible = true;
if (v) {
this.form = v;
this.editFlag = true;
} else {
this.form = {};
this.editFlag = false;
}
this.form.type = "COUNTER";
},
close() {
this.visible = false;
this.form = {};
},
saveParameters() {
this.$refs['form'].validate((valid) => {
if (valid) {
this.visible = false;
if (!this.editFlag) {
this.$emit('addParameters', this.form);
}
}
});
}
}
} }
</script> </script>

View File

@ -1,89 +1,79 @@
<template> <template>
<el-dialog append-to-body :close-on-click-modal="false" title="CSV编辑" <el-form :model="editData" label-position="right" label-width="80px" size="small" ref="form3">
:visible.sync="visible" class="environment-dialog" width="600px" <el-form-item :label="$t('api_test.variable_name')" prop="name">
@close="close"> <el-input v-model="editData.name" :placeholder="$t('api_test.variable_name')"></el-input>
<el-form :model="form" label-position="right" label-width="80px" size="small" ref="form" :rules="rule"> </el-form-item>
<el-form-item :label="$t('api_test.variable_name')" prop="name">
<el-input v-model="form.name" :placeholder="$t('api_test.variable_name')"></el-input>
</el-form-item>
<el-form-item :label="$t('commons.description')" prop="description"> <el-form-item :label="$t('commons.description')" prop="description">
<el-input class="ms-http-textarea" <el-input class="ms-http-textarea"
v-model="form.description" v-model="editData.description"
type="textarea" type="textarea"
:autosize="{ minRows: 2, maxRows: 10}" :autosize="{ minRows: 2, maxRows: 10}"
:rows="2" size="small"/> :rows="2" size="small"/>
</el-form-item> </el-form-item>
<el-tabs v-model="activeName" @tab-click="handleClick" style="margin-left: 40px"> <el-tabs v-model="activeName" @tab-click="handleClick" style="margin-left: 40px">
<el-tab-pane label="配置" name="config"> <el-tab-pane label="配置" name="config">
<el-row> <el-row>
<el-col :span="4" style="margin-top: 5px"> <el-col :span="4" style="margin-top: 5px">
<span>添加文件</span> <span>添加文件</span>
</el-col> </el-col>
<el-col :span="20"> <el-col :span="20">
<ms-csv-file-upload :parameter="form"/> <ms-csv-file-upload :parameter="editData"/>
</el-col> </el-col>
</el-row> </el-row>
<el-row style="margin-top: 10px"> <el-row style="margin-top: 10px">
<el-col :span="4" style="margin-top: 5px"> <el-col :span="4" style="margin-top: 5px">
<span>Encoding</span> <span>Encoding</span>
</el-col> </el-col>
<el-col :span="20"> <el-col :span="20">
<el-input v-model="form.encoding" size="small"/> <el-input v-model="editData.encoding" size="small"/>
</el-col> </el-col>
</el-row> </el-row>
<el-row style="margin-top: 10px"> <el-row style="margin-top: 10px">
<el-col :span="4" style="margin-top: 5px"> <el-col :span="4" style="margin-top: 5px">
<span>分隔符</span> <span>分隔符</span>
</el-col> </el-col>
<el-col :span="20"> <el-col :span="20">
<el-input v-model="form.splits" size="small"/> <el-input v-model="editData.splits" size="small"/>
</el-col> </el-col>
</el-row> </el-row>
</el-tab-pane> </el-tab-pane>
<el-tab-pane :label="$t('schema.preview')" name="preview"> <el-tab-pane :label="$t('schema.preview')" name="preview">
<el-table <el-table
:data="previewData" :data="previewData"
style="width: 100%" style="width: 100%"
height="400px" height="400px"
v-loading="loading"> v-loading="loading">
<!-- 自定义列的遍历--> <!-- 自定义列的遍历-->
<el-table-column v-for="(item, index) in columns" :key="index" :label="columns[index]" align="left" width="180"> <el-table-column v-for="(item, index) in columns" :key="index" :label="columns[index]" align="left" width="180">
<!-- 数据的遍历 scope.row就代表数据的每一个对象--> <!-- 数据的遍历 scope.row就代表数据的每一个对象-->
<template slot-scope="scope"> <template slot-scope="scope">
<span>{{scope.row[index]}}</span> <span>{{scope.row[index]}}</span>
</template> </template>
</el-table-column> </el-table-column>
</el-table> </el-table>
</el-tab-pane> </el-tab-pane>
</el-tabs> </el-tabs>
</el-form> </el-form>
<template v-slot:footer>
<ms-dialog-footer
@cancel="close"
@confirm="saveParameters"/>
</template>
</el-dialog>
</template> </template>
<script> <script>
import MsDialogFooter from "../../../../common/components/MsDialogFooter";
import MsCsvFileUpload from "./CsvFileUpload"; import MsCsvFileUpload from "./CsvFileUpload";
export default { export default {
name: "MsEditCsv", name: "MsEditCsv",
components: { components: {
MsDialogFooter,
MsCsvFileUpload MsCsvFileUpload
}, },
props: {
editData: {},
},
data() { data() {
return { return {
activeName: "config", activeName: "config",
visible: false, visible: false,
loading: false, loading: false,
form: {type: "CSV"},
editFlag: false, editFlag: false,
previewData: [], previewData: [],
columns: [], columns: [],
@ -95,21 +85,6 @@
} }
}, },
methods: { methods: {
open: function (v) {
this.visible = true;
if (v) {
this.form = v;
this.editFlag = true;
} else {
this.form = {};
this.editFlag = false;
}
this.form.type = "CSV";
},
close() {
this.visible = false;
this.form = {};
},
complete(results) { complete(results) {
if (results.errors && results.errors.length > 0) { if (results.errors && results.errors.length > 0) {
this.$error(results.errors); this.$error(results.errors);
@ -119,44 +94,32 @@
this.columns = results.data[0]; this.columns = results.data[0];
this.previewData = results.data; this.previewData = results.data;
} }
this.loading = false;
}, },
handleClick() { handleClick() {
let config = {complete: this.complete}; let config = {complete: this.complete};
// //
if (this.form.files.length > 0 && this.form.files[0].file) { if (this.editData.files && this.editData.files.length > 0 && this.editData.files[0].file) {
this.$papa.parse(this.form.files[0].file, config); this.loading = true;
this.$papa.parse(this.editData.files[0].file, config);
} }
// //
if (this.form.files.length > 0 && !this.form.files[0].file) { if (this.editData.files && this.editData.files.length > 0 && !this.editData.files[0].file) {
let file = this.form.files[0]; let file = this.editData.files[0];
let config = { let conf = {
url: "/api/automation/file/download", url: "/api/automation/file/download",
method: 'post', method: 'post',
data: file, data: file,
responseType: 'blob' responseType: 'blob',
}; };
this.result = this.$request(config).then(response => { this.result = this.$request(conf).then(response => {
const content = response.data; const content = response.data;
const blob = new Blob([content]); const blob = new Blob([content]);
console.log(blob) this.loading = true;
console.log(content) this.$papa.parse(blob, config);
let data = new FormData();
data.append("file", blob, blob.name);
this.$papa.parse(data, config);
}); });
} }
}, },
saveParameters() {
this.$refs['form'].validate((valid) => {
if (valid) {
this.visible = false;
if (!this.editFlag) {
this.$emit('addParameters', this.form);
}
}
});
}
} }
} }
</script> </script>

View File

@ -1,81 +1,30 @@
<template> <template>
<el-dialog append-to-body :close-on-click-modal="false" title="列表编辑" <el-form :model="editData" label-position="right" label-width="80px" size="small" ref="form4">
:visible.sync="visible" class="environment-dialog" width="40%" <el-form-item :label="$t('api_test.variable_name')" prop="name">
@close="close"> <el-input v-model="editData.name" :placeholder="$t('api_test.variable_name')"></el-input>
<el-form :model="form" label-position="right" label-width="80px" size="small" ref="form" :rules="rule"> </el-form-item>
<el-form-item :label="$t('api_test.variable_name')" prop="name">
<el-input v-model="form.name" :placeholder="$t('api_test.variable_name')"></el-input>
</el-form-item>
<el-form-item :label="$t('commons.description')" prop="description"> <el-form-item :label="$t('commons.description')" prop="description">
<el-input class="ms-http-textarea" <el-input class="ms-http-textarea"
v-model="form.description" v-model="editData.description"
type="textarea" type="textarea"
:autosize="{ minRows: 2, maxRows: 10}" :autosize="{ minRows: 2, maxRows: 10}"
:rows="2" size="small"/> :rows="2" size="small"/>
</el-form-item> </el-form-item>
<el-form-item :label="$t('api_test.value')" prop="value"> <el-form-item :label="$t('api_test.value')" prop="value">
<el-input v-model="form.value" placeholder="列表数据用,分隔"></el-input> <el-input v-model="editData.value" placeholder="列表数据用,分隔"></el-input>
</el-form-item> </el-form-item>
</el-form> </el-form>
<template v-slot:footer>
<ms-dialog-footer
@cancel="close"
@confirm="saveParameters"/>
</template>
</el-dialog>
</template> </template>
<script> <script>
import MsDialogFooter from "../../../../common/components/MsDialogFooter";
export default { export default {
name: "MsEditListValue", name: "MsEditListValue",
components: { components: {},
MsDialogFooter props: {
editData: {},
}, },
data() {
return {
visible: false,
form: {type: "LIST"},
editFlag: false,
rule: {
name: [
{required: true, message: this.$t('api_test.variable_name'), trigger: 'blur'},
],
},
}
},
methods: {
open: function (v) {
this.visible = true;
if (v) {
this.form = v;
this.editFlag = true;
} else {
this.form = {};
this.editFlag = false;
}
this.form.type = "LIST";
},
close() {
this.visible = false;
this.form = {};
},
saveParameters() {
this.$refs['form'].validate((valid) => {
if (valid) {
this.visible = false;
if (!this.editFlag) {
this.$emit('addParameters', this.form);
}
}
});
}
}
} }
</script> </script>

View File

@ -1,87 +1,37 @@
<template> <template>
<el-dialog append-to-body :close-on-click-modal="false" title="随机数编辑" <el-form :model="editData" label-position="right" label-width="80px" size="small" ref="form5">
:visible.sync="visible" class="environment-dialog" width="600px" <el-form-item :label="$t('api_test.variable_name')" prop="name">
@close="close"> <el-input v-model="editData.name" :placeholder="$t('api_test.variable_name')"></el-input>
<el-form :model="form" label-position="right" label-width="80px" size="small" ref="form" :rules="rule"> </el-form-item>
<el-form-item :label="$t('api_test.variable_name')" prop="name">
<el-input v-model="form.name" :placeholder="$t('api_test.variable_name')"></el-input>
</el-form-item>
<el-form-item :label="$t('commons.description')" prop="description"> <el-form-item :label="$t('commons.description')" prop="description">
<el-input class="ms-http-textarea" <el-input class="ms-http-textarea"
v-model="form.description" v-model="editData.description"
type="textarea" type="textarea"
:autosize="{ minRows: 2, maxRows: 10}" :autosize="{ minRows: 2, maxRows: 10}"
:rows="2" size="small"/> :rows="2" size="small"/>
</el-form-item> </el-form-item>
<el-form-item label="最小值" prop="set"> <el-form-item label="最小值" prop="set">
<el-input-number size="small" v-model="form.minNumber" placeholder="0" :max="1000*10000000" :min="0"/> <el-input-number size="small" v-model="editData.minNumber" placeholder="0" :max="1000*10000000" :min="0"/>
<span style="margin: 0px 10px 10px ">最大值</span> <span style="margin: 0px 10px 10px ">最大值</span>
<el-input-number size="small" v-model="form.maxNumber" placeholder="10" :max="1000*10000000" :min="0"/> <el-input-number size="small" v-model="editData.maxNumber" placeholder="10" :max="1000*10000000" :min="0"/>
</el-form-item> </el-form-item>
<el-form-item label="开始" prop="value"> <el-form-item label="开始" prop="value">
<el-input v-model="form.value" placeholder="000产生至少3位数字。user_000输出形式为user_nnn"></el-input> <el-input v-model="editData.value" placeholder="000产生至少3位数字。user_000输出形式为user_nnn"></el-input>
</el-form-item> </el-form-item>
</el-form> </el-form>
<template v-slot:footer>
<ms-dialog-footer
@cancel="close"
@confirm="saveParameters"/>
</template>
</el-dialog>
</template> </template>
<script> <script>
import MsDialogFooter from "../../../../common/components/MsDialogFooter";
export default { export default {
name: "MsEditRandom", name: "MsEditRandom",
components: { components: {},
MsDialogFooter props: {
editData: {},
}, },
data() {
return {
visible: false,
form: {type: "RANDOM"},
editFlag: false,
rule: {
name: [
{required: true, message: this.$t('api_test.variable_name'), trigger: 'blur'},
],
},
}
},
methods: {
open: function (v) {
this.visible = true;
if (v) {
this.form = v;
this.editFlag = true;
} else {
this.form = {};
this.editFlag = false;
}
this.form.type = "RANDOM";
},
close() {
this.visible = false;
this.form = {};
},
saveParameters() {
this.$refs['form'].validate((valid) => {
if (valid) {
this.visible = false;
if (!this.editFlag) {
this.$emit('addParameters', this.form);
}
}
});
}
}
} }
</script> </script>

View File

@ -1,27 +1,36 @@
<template> <template>
<el-dialog :title="$t('api_test.scenario.variables')" <el-dialog :title="$t('api_test.scenario.variables')"
:visible.sync="visible" class="environment-dialog" width="60%" :visible.sync="visible" class="environment-dialog" width="70%"
@close="close"> @close="close">
<div> <div>
<el-table ref="table" border :data="variables" class="adjust-table" @select-all="select" @select="select" <el-row>
v-loading="loading"> <el-col :span="12">
<el-table-column type="selection" width="38"/> <div style="border:1px #DCDFE6 solid; min-height: 400px;border-radius: 4px ;width: 100% ;">
<el-table-column prop="num" label="ID" sortable/>
<el-table-column prop="name" :label="$t('api_test.variable_name')" sortable show-overflow-tooltip/>
<el-table-column prop="type" :label="$t('test_track.case.type')">
<template v-slot:default="scope">
<span>{{types.get(scope.row.type)}}</span>
</template>
</el-table-column>
<el-table-column prop="value" :label="$t('api_test.value')" show-overflow-tooltip/>
<el-table-column :label="$t('commons.operating')"> <el-table ref="table" border :data="variables" class="adjust-table" @select-all="select" @select="select"
<template v-slot:default="{row}"> v-loading="loading" @row-click="edit">
<el-button type="text" @click="edit(row)">{{ $t('commons.edit') }}</el-button> <el-table-column type="selection" width="38"/>
</template> <el-table-column prop="num" label="ID" sortable/>
</el-table-column> <el-table-column prop="name" :label="$t('api_test.variable_name')" sortable show-overflow-tooltip/>
<el-table-column prop="type" :label="$t('test_track.case.type')">
<template v-slot:default="scope">
<span>{{types.get(scope.row.type)}}</span>
</template>
</el-table-column>
<el-table-column prop="value" :label="$t('api_test.value')" show-overflow-tooltip/>
</el-table>
</div>
</el-col>
<el-col :span="12">
<ms-edit-constant v-if="editData.type=='CONSTANT'" ref="parameters" :editData.sync="editData"/>
<ms-edit-counter v-if="editData.type=='COUNTER'" ref="counter" :editData.sync="editData"/>
<ms-edit-random v-if="editData.type=='RANDOM'" ref="random" :editData.sync="editData"/>
<ms-edit-list-value v-if="editData.type=='LIST'" ref="listValue" :editData="editData"/>
<ms-edit-csv v-if="editData.type=='CSV'" ref="csv" :editData.sync="editData"/>
</el-col>
</el-row>
</el-table>
</div> </div>
<template v-slot:footer> <template v-slot:footer>
@ -41,11 +50,6 @@
</div> </div>
</template> </template>
<ms-edit-constant ref="parameters" @addParameters="addParameters"/>
<ms-edit-counter ref="counter" @addParameters="addParameters"/>
<ms-edit-random ref="random" @addParameters="addParameters"/>
<ms-edit-list-value ref="listValue" @addParameters="addParameters"/>
<ms-edit-csv ref="csv" @addParameters="addParameters"/>
</el-dialog> </el-dialog>
</template> </template>
@ -87,48 +91,19 @@
selection: [], selection: [],
loading: false, loading: false,
currentPage: 1, currentPage: 1,
editData: {},
pageSize: 10, pageSize: 10,
total: 0, total: 0,
} }
}, },
methods: { methods: {
handleClick(command) { handleClick(command) {
switch (command) { this.editData = {};
case "CONSTANT": this.editData.type = command;
this.$refs.parameters.open(); this.addParameters(this.editData);
break;
case "LIST":
this.$refs.listValue.open();
break;
case "CSV":
this.$refs.csv.open();
break;
case "COUNTER":
this.$refs.counter.open();
break;
case "RANDOM":
this.$refs.random.open();
break;
}
}, },
edit(row) { edit(row) {
switch (row.type) { this.editData = row;
case "CONSTANT":
this.$refs.parameters.open(row);
break;
case "LIST":
this.$refs.listValue.open(row);
break;
case "CSV":
this.$refs.csv.open(row);
break;
case "COUNTER":
this.$refs.counter.open(row);
break;
case "RANDOM":
this.$refs.random.open(row);
break;
}
}, },
addParameters(v) { addParameters(v) {
v.id = getUUID(); v.id = getUUID();
@ -148,9 +123,17 @@
open: function (variables) { open: function (variables) {
this.variables = variables; this.variables = variables;
this.visible = true; this.visible = true;
this.editData = {type: "CONSTANT"};
this.addParameters(this.editData);
}, },
close() { close() {
this.visible = false; this.visible = false;
this.variables.forEach(item => {
if (item.name === undefined || item.name === "") {
const index = this.variables.findIndex(d => d.id === item.id);
this.variables.splice(index, 1);
}
})
this.$emit('setVariables', this.variables); this.$emit('setVariables', this.variables);
}, },
deleteVariable() { deleteVariable() {