Merge branch 'v1.8'

This commit is contained in:
Captain.B 2021-03-25 19:26:55 +08:00
commit 4cf1dd112b
8 changed files with 272 additions and 193 deletions

View File

@ -136,8 +136,10 @@ public class MsJmeterParser extends ApiImportAbstractParser<ScenarioImport> {
try { try {
HTTPSamplerProxy source = (HTTPSamplerProxy) key; HTTPSamplerProxy source = (HTTPSamplerProxy) key;
BeanUtils.copyBean(samplerProxy, source); BeanUtils.copyBean(samplerProxy, source);
samplerProxy.setRest(new ArrayList<KeyValue>(){{this.add(new KeyValue());}});
samplerProxy.setArguments(new ArrayList<KeyValue>(){{this.add(new KeyValue());}});
if (source != null && source.getHTTPFiles().length > 0) { if (source != null && source.getHTTPFiles().length > 0) {
samplerProxy.getBody().setBinary(new ArrayList<>()); samplerProxy.getBody().initBinary();
samplerProxy.getBody().setType(Body.FORM_DATA); samplerProxy.getBody().setType(Body.FORM_DATA);
List<KeyValue> keyValues = new LinkedList<>(); List<KeyValue> keyValues = new LinkedList<>();
for (HTTPFileArg arg : source.getHTTPFiles()) { for (HTTPFileArg arg : source.getHTTPFiles()) {
@ -163,6 +165,7 @@ public class MsJmeterParser extends ApiImportAbstractParser<ScenarioImport> {
source.getArguments().getArgumentsAsMap().forEach((k, v) -> { source.getArguments().getArgumentsAsMap().forEach((k, v) -> {
samplerProxy.getBody().setRaw(v); samplerProxy.getBody().setRaw(v);
}); });
samplerProxy.getBody().initKvs();
} else { } else {
List<KeyValue> keyValues = new LinkedList<>(); List<KeyValue> keyValues = new LinkedList<>();
source.getArguments().getArgumentsAsMap().forEach((k, v) -> { source.getArguments().getArgumentsAsMap().forEach((k, v) -> {
@ -173,6 +176,7 @@ public class MsJmeterParser extends ApiImportAbstractParser<ScenarioImport> {
samplerProxy.setArguments(keyValues); samplerProxy.setArguments(keyValues);
} }
} }
samplerProxy.getBody().initBinary();
} }
samplerProxy.setPath(""); samplerProxy.setPath("");
samplerProxy.setMethod(source.getMethod()); samplerProxy.setMethod(source.getMethod());

View File

@ -66,14 +66,11 @@ public class Body {
sampler.setDoMultipart(true); sampler.setDoMultipart(true);
} }
} else { } else {
if (!this.isJson()) { if (StringUtils.isNotEmpty(this.format) && "JSON-SCHEMA".equals(this.format) && this.getJsonSchema() != null) {
sampler.setPostBodyRaw(true); this.raw = JSONSchemaGenerator.getJson(com.alibaba.fastjson.JSON.toJSONString(this.getJsonSchema()));
} else {
if (StringUtils.isNotEmpty(this.format) && "JSON-SCHEMA".equals(this.format) && this.getJsonSchema() != null) {
this.raw = JSONSchemaGenerator.getJson(com.alibaba.fastjson.JSON.toJSONString(this.getJsonSchema()));
}
} }
KeyValue keyValue = new KeyValue("", "JSON-SCHEMA", this.getRaw(), true, true); KeyValue keyValue = new KeyValue("", "JSON-SCHEMA", this.getRaw(), true, true);
sampler.setPostBodyRaw(true);
keyValue.setEnable(true); keyValue.setEnable(true);
keyValue.setEncode(false); keyValue.setEncode(false);
body.add(keyValue); body.add(keyValue);

View File

@ -86,216 +86,240 @@ public class ApiDocumentService {
apiInfoDTO.setStatus(apiModel.getStatus()); apiInfoDTO.setStatus(apiModel.getStatus());
if (apiModel.getRequest() != null) { if (apiModel.getRequest() != null) {
JSONObject requestJsonObj = JSONObject.parseObject(apiModel.getRequest()); JSONObject requestObj = this.genJSONObject(apiModel.getRequest());
//head赋值conversionModelToDTO if(requestObj!=null){
if (requestJsonObj.containsKey("headers")) { if (requestObj.containsKey("headers")) {
JSONArray requestHeadDataArr = new JSONArray(); JSONArray requestHeadDataArr = new JSONArray();
//head赋值 //head赋值
JSONArray headArr = requestJsonObj.getJSONArray("headers"); JSONArray headArr = requestObj.getJSONArray("headers");
for (int index = 0; index < headArr.size(); index++) { for (int index = 0; index < headArr.size(); index++) {
JSONObject headObj = headArr.getJSONObject(index); JSONObject headObj = headArr.getJSONObject(index);
if (headObj.containsKey("name") && headObj.containsKey("value")) { if (headObj.containsKey("name") && headObj.containsKey("value")) {
requestHeadDataArr.add(headObj); requestHeadDataArr.add(headObj);
}
} }
apiInfoDTO.setRequestHead(requestHeadDataArr.toJSONString());
} }
apiInfoDTO.setRequestHead(requestHeadDataArr.toJSONString()); //url参数赋值
} JSONArray urlParamArr = new JSONArray();
//url参数赋值 if (requestObj.containsKey("arguments")) {
JSONArray urlParamArr = new JSONArray(); try{
if (requestJsonObj.containsKey("arguments")) { JSONArray headArr = requestObj.getJSONArray("arguments");
//urlParam -- query赋值 for (int index = 0; index < headArr.size(); index++) {
JSONArray headArr = requestJsonObj.getJSONArray("arguments");
for (int index = 0; index < headArr.size(); index++) {
JSONObject headObj = headArr.getJSONObject(index);
if (headObj.containsKey("name") && headObj.containsKey("value")) {
urlParamArr.add(headObj);
}
}
}
if (requestJsonObj.containsKey("rest")) {
//urlParam -- rest赋值
JSONArray headArr = requestJsonObj.getJSONArray("rest");
for (int index = 0; index < headArr.size(); index++) {
JSONObject headObj = headArr.getJSONObject(index);
if (headObj.containsKey("name") && headObj.containsKey("value")) {
urlParamArr.add(headObj);
}
}
}
apiInfoDTO.setUrlParams(urlParamArr.toJSONString());
//请求体参数类型
if (requestJsonObj.containsKey("body")) {
JSONObject bodyObj = requestJsonObj.getJSONObject("body");
if (bodyObj.containsKey("type")) {
String type = bodyObj.getString("type");
if (StringUtils.equals(type, "WWW_FORM")) {
apiInfoDTO.setRequestBodyParamType("x-www-from-urlencoded");
} else if (StringUtils.equals(type, "Form Data")) {
apiInfoDTO.setRequestBodyParamType("form-data");
} else {
apiInfoDTO.setRequestBodyParamType(type);
}
if (StringUtils.equals(type, "JSON")) { JSONObject headObj = headArr.getJSONObject(index);
//判断是否是JsonSchema if (headObj.containsKey("name") && headObj.containsKey("value")) {
boolean isJsonSchema = false; urlParamArr.add(headObj);
if (bodyObj.containsKey("format")) {
String foramtValue = String.valueOf(bodyObj.get("format"));
if (StringUtils.equals("JSON-SCHEMA", foramtValue)) {
isJsonSchema = true;
}
}
if (isJsonSchema) {
apiInfoDTO.setRequestBodyParamType("JSON-SCHEMA");
apiInfoDTO.setJsonSchemaBody(bodyObj);
} else {
if (bodyObj.containsKey("raw")) {
String raw = bodyObj.getString("raw");
apiInfoDTO.setRequestBodyStrutureData(raw);
//转化jsonObje 或者 jsonArray
this.setPreviewData(previewJsonArray, raw);
}
}
} else if (StringUtils.equalsAny(type, "XML", "Raw")) {
if (bodyObj.containsKey("raw")) {
String raw = bodyObj.getString("raw");
apiInfoDTO.setRequestBodyStrutureData(raw);
JSONObject previewObj = JSONObject.parseObject(raw);
this.setPreviewData(previewJsonArray, raw);
}
} else if (StringUtils.equalsAny(type, "Form Data", "WWW_FORM")) {
if (bodyObj.containsKey("kvs")) {
JSONArray bodyParamArr = new JSONArray();
JSONArray kvsArr = bodyObj.getJSONArray("kvs");
Map<String, String> previewObjMap = new LinkedHashMap<>();
for (int i = 0; i < kvsArr.size(); i++) {
JSONObject kv = kvsArr.getJSONObject(i);
if (kv.containsKey("name") && kv.containsKey("value")) {
bodyParamArr.add(kv);
previewObjMap.put(String.valueOf(kv.get("name")), String.valueOf(kv.get("value")));
} }
}
this.setPreviewData(previewJsonArray, JSONObject.toJSONString(previewObjMap));
apiInfoDTO.setRequestBodyFormData(bodyParamArr.toJSONString());
} }
} else if (StringUtils.equals(type, "BINARY")) { }catch (Exception e){
if (bodyObj.containsKey("binary")) { }
List<Map<String, String>> bodyParamList = new ArrayList<>(); }
JSONArray kvsArr = bodyObj.getJSONArray("binary"); if (requestObj.containsKey("rest")) {
try{
//urlParam -- rest赋值
JSONArray headArr = requestObj.getJSONArray("rest");
for (int index = 0; index < headArr.size(); index++) {
JSONObject headObj = headArr.getJSONObject(index);
if (headObj.containsKey("name") && headObj.containsKey("value")) {
urlParamArr.add(headObj);
}
}
}catch (Exception e){
}
}
apiInfoDTO.setUrlParams(urlParamArr.toJSONString());
//请求体参数类型
if (requestObj.containsKey("body")) {
try{
JSONObject bodyObj = requestObj.getJSONObject("body");
if (bodyObj.containsKey("type")) {
String type = bodyObj.getString("type");
if (StringUtils.equals(type, "WWW_FORM")) {
apiInfoDTO.setRequestBodyParamType("x-www-from-urlencoded");
} else if (StringUtils.equals(type, "Form Data")) {
apiInfoDTO.setRequestBodyParamType("form-data");
} else {
apiInfoDTO.setRequestBodyParamType(type);
}
Map<String, String> previewObjMap = new LinkedHashMap<>(); if (StringUtils.equals(type, "JSON")) {
for (int i = 0; i < kvsArr.size(); i++) { //判断是否是JsonSchema
JSONObject kv = kvsArr.getJSONObject(i); boolean isJsonSchema = false;
if (kv.containsKey("description") && kv.containsKey("files")) { if (bodyObj.containsKey("format")) {
Map<String, String> bodyMap = new HashMap<>(); String foramtValue = String.valueOf(bodyObj.get("format"));
String name = kv.getString("description"); if (StringUtils.equals("JSON-SCHEMA", foramtValue)) {
JSONArray fileArr = kv.getJSONArray("files"); isJsonSchema = true;
String value = ""; }
for (int j = 0; j < fileArr.size(); j++) { }
JSONObject fileObj = fileArr.getJSONObject(j); if (isJsonSchema) {
if (fileObj.containsKey("name")) { apiInfoDTO.setRequestBodyParamType("JSON-SCHEMA");
value += fileObj.getString("name") + " ;"; apiInfoDTO.setJsonSchemaBody(bodyObj);
} else {
if (bodyObj.containsKey("raw")) {
String raw = bodyObj.getString("raw");
apiInfoDTO.setRequestBodyStrutureData(raw);
//转化jsonObje 或者 jsonArray
this.setPreviewData(previewJsonArray, raw);
}
}
} else if (StringUtils.equalsAny(type, "XML", "Raw")) {
if (bodyObj.containsKey("raw")) {
String raw = bodyObj.getString("raw");
apiInfoDTO.setRequestBodyStrutureData(raw);
this.setPreviewData(previewJsonArray, raw);
}
} else if (StringUtils.equalsAny(type, "Form Data", "WWW_FORM")) {
if (bodyObj.containsKey("kvs")) {
JSONArray bodyParamArr = new JSONArray();
JSONArray kvsArr = bodyObj.getJSONArray("kvs");
Map<String, String> previewObjMap = new LinkedHashMap<>();
for (int i = 0; i < kvsArr.size(); i++) {
JSONObject kv = kvsArr.getJSONObject(i);
if (kv.containsKey("name") && kv.containsKey("value")) {
bodyParamArr.add(kv);
previewObjMap.put(String.valueOf(kv.get("name")), String.valueOf(kv.get("value")));
} }
} }
bodyMap.put("name", name); this.setPreviewData(previewJsonArray, JSONObject.toJSONString(previewObjMap));
bodyMap.put("value", value); apiInfoDTO.setRequestBodyFormData(bodyParamArr.toJSONString());
bodyMap.put("contentType", "File"); }
bodyParamList.add(bodyMap); } else if (StringUtils.equals(type, "BINARY")) {
if (bodyObj.containsKey("binary")) {
List<Map<String, String>> bodyParamList = new ArrayList<>();
JSONArray kvsArr = bodyObj.getJSONArray("binary");
previewObjMap.put(String.valueOf(name), String.valueOf(value)); Map<String, String> previewObjMap = new LinkedHashMap<>();
for (int i = 0; i < kvsArr.size(); i++) {
JSONObject kv = kvsArr.getJSONObject(i);
if (kv.containsKey("description") && kv.containsKey("files")) {
Map<String, String> bodyMap = new HashMap<>();
String name = kv.getString("description");
JSONArray fileArr = kv.getJSONArray("files");
String value = "";
for (int j = 0; j < fileArr.size(); j++) {
JSONObject fileObj = fileArr.getJSONObject(j);
if (fileObj.containsKey("name")) {
value += fileObj.getString("name") + " ;";
}
}
bodyMap.put("name", name);
bodyMap.put("value", value);
bodyMap.put("contentType", "File");
bodyParamList.add(bodyMap);
previewObjMap.put(String.valueOf(name), String.valueOf(value));
}
}
this.setPreviewData(previewJsonArray, JSONObject.toJSONString(previewObjMap));
apiInfoDTO.setRequestBodyFormData(JSONArray.toJSONString(bodyParamList));
} }
} }
this.setPreviewData(previewJsonArray, JSONObject.toJSONString(previewObjMap));
apiInfoDTO.setRequestBodyFormData(JSONArray.toJSONString(bodyParamList));
} }
}catch (Exception e){
} }
} }
} }
} }
//赋值响应头 //赋值响应头
if (apiModel.getResponse() != null) { if (apiModel.getResponse() != null) {
JSONObject responseJsonObj = JSONObject.parseObject(apiModel.getResponse()); JSONObject responseJsonObj = this.genJSONObject(apiModel.getResponse());
if (responseJsonObj!=null && responseJsonObj.containsKey("headers")) { if (responseJsonObj!=null && responseJsonObj.containsKey("headers")) {
JSONArray responseHeadDataArr = new JSONArray(); try{
JSONArray headArr = responseJsonObj.getJSONArray("headers"); JSONArray responseHeadDataArr = new JSONArray();
for (int index = 0; index < headArr.size(); index++) { JSONArray headArr = responseJsonObj.getJSONArray("headers");
JSONObject headObj = headArr.getJSONObject(index); for (int index = 0; index < headArr.size(); index++) {
if (headObj.containsKey("name") && headObj.containsKey("value")) { JSONObject headObj = headArr.getJSONObject(index);
responseHeadDataArr.add(headObj); if (headObj.containsKey("name") && headObj.containsKey("value")) {
responseHeadDataArr.add(headObj);
}
} }
apiInfoDTO.setResponseHead(responseHeadDataArr.toJSONString());
}catch (Exception e){
} }
apiInfoDTO.setResponseHead(responseHeadDataArr.toJSONString());
} }
// 赋值响应体 // 赋值响应体
if (responseJsonObj!=null && responseJsonObj.containsKey("body")) { if (responseJsonObj!=null && responseJsonObj.containsKey("body")) {
JSONObject bodyObj = responseJsonObj.getJSONObject("body"); try {
if (bodyObj.containsKey("type")) { JSONObject bodyObj = responseJsonObj.getJSONObject("body");
String type = bodyObj.getString("type"); if (bodyObj.containsKey("type")) {
if (StringUtils.equals(type, "WWW_FORM")) { String type = bodyObj.getString("type");
apiInfoDTO.setResponseBodyParamType("x-www-from-urlencoded"); if (StringUtils.equals(type, "WWW_FORM")) {
} else if (StringUtils.equals(type, "Form Data")) { apiInfoDTO.setResponseBodyParamType("x-www-from-urlencoded");
apiInfoDTO.setResponseBodyParamType("form-data"); } else if (StringUtils.equals(type, "Form Data")) {
} else { apiInfoDTO.setResponseBodyParamType("form-data");
apiInfoDTO.setResponseBodyParamType(type); } else {
} apiInfoDTO.setResponseBodyParamType(type);
if (StringUtils.equalsAny(type, "JSON", "XML", "Raw")) {
if (bodyObj.containsKey("raw")) {
String raw = bodyObj.getString("raw");
apiInfoDTO.setResponseBodyStrutureData(raw);
} }
} else if (StringUtils.equalsAny(type, "Form Data", "WWW_FORM")) { if (StringUtils.equalsAny(type, "JSON", "XML", "Raw")) {
if (bodyObj.containsKey("kvs")) { if (bodyObj.containsKey("raw")) {
JSONArray bodyParamArr = new JSONArray(); String raw = bodyObj.getString("raw");
JSONArray kvsArr = bodyObj.getJSONArray("kvs"); apiInfoDTO.setResponseBodyStrutureData(raw);
for (int i = 0; i < kvsArr.size(); i++) {
JSONObject kv = kvsArr.getJSONObject(i);
if (kv.containsKey("name")) {
bodyParamArr.add(kv);
}
} }
apiInfoDTO.setResponseBodyFormData(bodyParamArr.toJSONString()); } else if (StringUtils.equalsAny(type, "Form Data", "WWW_FORM")) {
} if (bodyObj.containsKey("kvs")) {
} else if (StringUtils.equals(type, "BINARY")) { JSONArray bodyParamArr = new JSONArray();
if (bodyObj.containsKey("binary")) { JSONArray kvsArr = bodyObj.getJSONArray("kvs");
List<Map<String, String>> bodyParamList = new ArrayList<>(); for (int i = 0; i < kvsArr.size(); i++) {
JSONArray kvsArr = bodyObj.getJSONArray("kvs"); JSONObject kv = kvsArr.getJSONObject(i);
for (int i = 0; i < kvsArr.size(); i++) { if (kv.containsKey("name")) {
JSONObject kv = kvsArr.getJSONObject(i); bodyParamArr.add(kv);
if (kv.containsKey("description") && kv.containsKey("files")) {
Map<String, String> bodyMap = new HashMap<>();
String name = kv.getString("description");
JSONArray fileArr = kv.getJSONArray("files");
String value = "";
for (int j = 0; j < fileArr.size(); j++) {
JSONObject fileObj = fileArr.getJSONObject(j);
if (fileObj.containsKey("name")) {
value += fileObj.getString("name") + " ;";
}
} }
bodyMap.put("name", name);
bodyMap.put("value", value);
bodyParamList.add(bodyMap);
} }
apiInfoDTO.setResponseBodyFormData(bodyParamArr.toJSONString());
}
} else if (StringUtils.equals(type, "BINARY")) {
if (bodyObj.containsKey("binary")) {
List<Map<String, String>> bodyParamList = new ArrayList<>();
JSONArray kvsArr = bodyObj.getJSONArray("kvs");
for (int i = 0; i < kvsArr.size(); i++) {
JSONObject kv = kvsArr.getJSONObject(i);
if (kv.containsKey("description") && kv.containsKey("files")) {
Map<String, String> bodyMap = new HashMap<>();
String name = kv.getString("description");
JSONArray fileArr = kv.getJSONArray("files");
String value = "";
for (int j = 0; j < fileArr.size(); j++) {
JSONObject fileObj = fileArr.getJSONObject(j);
if (fileObj.containsKey("name")) {
value += fileObj.getString("name") + " ;";
}
}
bodyMap.put("name", name);
bodyMap.put("value", value);
bodyParamList.add(bodyMap);
}
}
apiInfoDTO.setResponseBodyFormData(JSONArray.toJSONString(bodyParamList));
} }
apiInfoDTO.setResponseBodyFormData(JSONArray.toJSONString(bodyParamList));
} }
} }
}catch (Exception e){
} }
} }
// 赋值响应码 // 赋值响应码
if (responseJsonObj!=null && responseJsonObj.containsKey("statusCode")) { if (responseJsonObj!=null && responseJsonObj.containsKey("statusCode")) {
JSONArray responseStatusDataArr = new JSONArray(); try {
JSONArray statusArr = responseJsonObj.getJSONArray("statusCode"); JSONArray responseStatusDataArr = new JSONArray();
for (int index = 0; index < statusArr.size(); index++) { JSONArray statusArr = responseJsonObj.getJSONArray("statusCode");
JSONObject statusObj = statusArr.getJSONObject(index); for (int index = 0; index < statusArr.size(); index++) {
if (statusObj.containsKey("name") && statusObj.containsKey("value")) { JSONObject statusObj = statusArr.getJSONObject(index);
responseStatusDataArr.add(statusObj); if (statusObj.containsKey("name") && statusObj.containsKey("value")) {
responseStatusDataArr.add(statusObj);
}
} }
apiInfoDTO.setResponseCode(responseStatusDataArr.toJSONString());
}catch (Exception e){
} }
apiInfoDTO.setResponseCode(responseStatusDataArr.toJSONString());
} }
} }
} }
@ -304,6 +328,15 @@ public class ApiDocumentService {
return apiInfoDTO; return apiInfoDTO;
} }
private JSONObject genJSONObject(String request) {
JSONObject returnObj = null;
try{
returnObj = JSONObject.parseObject(request);
}catch (Exception e){
}
return returnObj;
}
private void setPreviewData(JSONArray previewArray, String data) { private void setPreviewData(JSONArray previewArray, String data) {
try { try {
JSONObject previewObj = JSONObject.parseObject(data); JSONObject previewObj = JSONObject.parseObject(data);

View File

@ -5,12 +5,12 @@
<el-option v-for="(environment, index) in pe.envs" :key="index" <el-option v-for="(environment, index) in pe.envs" :key="index"
:label="environment.name + (environment.config.httpConfig.socket ? (': ' + environment.config.httpConfig.protocol + '://' + environment.config.httpConfig.socket) : '')" :label="environment.name + (environment.config.httpConfig.socket ? (': ' + environment.config.httpConfig.protocol + '://' + environment.config.httpConfig.socket) : '')"
:value="environment.id"/> :value="environment.id"/>
<el-button class="ms-scenario-button" size="mini" type="primary" @click="openEnvironmentConfig(pe.id)"> <el-button class="ms-scenario-button" size="mini" type="primary" @click="openEnvironmentConfig(pe.id, pe['selectEnv'])">
{{ $t('api_test.environment.environment_config') }} {{ $t('api_test.environment.environment_config') }}
</el-button> </el-button>
<template v-slot:empty> <template v-slot:empty>
<div class="empty-environment"> <div class="empty-environment">
<el-button class="ms-scenario-button" size="mini" type="primary" @click="openEnvironmentConfig(pe.id)"> <el-button class="ms-scenario-button" size="mini" type="primary" @click="openEnvironmentConfig(pe.id, pe['selectEnv'])">
{{ $t('api_test.environment.environment_config') }} {{ $t('api_test.environment.environment_config') }}
</el-button> </el-button>
</div> </div>
@ -78,12 +78,12 @@ export default {
const project = this.projectList.find(p => p.id === id); const project = this.projectList.find(p => p.id === id);
return project ? project.name : ""; return project ? project.name : "";
}, },
openEnvironmentConfig(projectId) { openEnvironmentConfig(projectId, envId) {
if (!projectId) { if (!projectId) {
this.$error(this.$t('api_test.select_project')); this.$error(this.$t('api_test.select_project'));
return; return;
} }
this.$refs.environmentConfig.open(projectId); this.$refs.environmentConfig.open(projectId, envId);
}, },
handleConfirm() { handleConfirm() {
let map = new Map(); let map = new Map();

View File

@ -77,7 +77,7 @@
this.$error(this.$t('api_test.select_project')); this.$error(this.$t('api_test.select_project'));
return; return;
} }
this.$refs.environmentConfig.open(this.projectId); this.$refs.environmentConfig.open(this.projectId, this.environmentId);
}, },
environmentChange(value) { environmentChange(value) {
for (let i in this.environments) { for (let i in this.environments) {

View File

@ -46,13 +46,15 @@
icon: 'el-icon-delete', icon: 'el-icon-delete',
func: this.deleteEnvironment func: this.deleteEnvironment
} }
] ],
selectEnvironmentId: ''
} }
}, },
methods: { methods: {
open: function (projectId) { open: function (projectId, envId) {
this.visible = true; this.visible = true;
this.projectId = projectId; this.projectId = projectId;
this.selectEnvironmentId = envId;
this.getEnvironments(); this.getEnvironments();
listenGoBack(this.close); listenGoBack(this.close);
}, },
@ -114,7 +116,16 @@
this.result = this.$get('/api/environment/list/' + this.projectId, response => { this.result = this.$get('/api/environment/list/' + this.projectId, response => {
this.environments = response.data; this.environments = response.data;
if (this.environments.length > 0) { if (this.environments.length > 0) {
this.$refs.environmentItems.itemSelected(0, this.environments[0]); if (this.selectEnvironmentId) {
const index = this.environments.findIndex(e => e.id === this.selectEnvironmentId);
if (index !== -1) {
this.$refs.environmentItems.itemSelected(index, this.environments[index]);
} else {
this.$refs.environmentItems.itemSelected(0, this.environments[0]);
}
} else {
this.$refs.environmentItems.itemSelected(0, this.environments[0]);
}
} else { } else {
let item = new Environment({ let item = new Environment({
projectId: this.projectId projectId: this.projectId

View File

@ -46,13 +46,15 @@
icon: 'el-icon-delete', icon: 'el-icon-delete',
func: this.deleteEnvironment func: this.deleteEnvironment
} }
] ],
selectEnvironmentId: ''
} }
}, },
methods: { methods: {
open: function (projectId) { open: function (projectId, envId) {
this.visible = true; this.visible = true;
this.projectId = projectId; this.projectId = projectId;
this.selectEnvironmentId = envId;
this.getEnvironments(); this.getEnvironments();
listenGoBack(this.close); listenGoBack(this.close);
}, },
@ -114,7 +116,16 @@
this.result = this.$get('/api/environment/list/' + this.projectId, response => { this.result = this.$get('/api/environment/list/' + this.projectId, response => {
this.environments = response.data; this.environments = response.data;
if (this.environments.length > 0) { if (this.environments.length > 0) {
this.$refs.environmentItems.itemSelected(0, this.environments[0]); if (this.selectEnvironmentId) {
const index = this.environments.findIndex(e => e.id === this.selectEnvironmentId);
if (index !== -1) {
this.$refs.environmentItems.itemSelected(index, this.environments[index]);
} else {
this.$refs.environmentItems.itemSelected(0, this.environments[0]);
}
} else {
this.$refs.environmentItems.itemSelected(0, this.environments[0]);
}
} else { } else {
let item = new Environment({ let item = new Environment({
projectId: this.projectId projectId: this.projectId

View File

@ -4,7 +4,7 @@
<el-col> <el-col>
<el-form :inline="true"> <el-form :inline="true">
<el-form-item :label="$t('load_test.select_resource_pool')"> <el-form-item :label="$t('load_test.select_resource_pool')">
<el-select v-model="resourcePool" :disabled="isReadOnly" size="mini"> <el-select v-model="resourcePool" :disabled="isReadOnly" size="mini" @change="resourcePoolChange">
<el-option <el-option
v-for="item in resourcePools" v-for="item in resourcePools"
:key="item.id" :key="item.id"
@ -32,7 +32,7 @@
</el-tag> </el-tag>
<el-tag type="primary" size="mini" v-if="threadGroup.threadType === 'ITERATION'"> <el-tag type="primary" size="mini" v-if="threadGroup.threadType === 'ITERATION'">
{{ $t('load_test.thread_num') }} {{ threadGroup.threadNumber }}, {{ $t('load_test.thread_num') }} {{ threadGroup.threadNumber }},
{{$t('load_test.iterate_num')}} {{threadGroup.iterateNum}} {{ $t('load_test.iterate_num') }} {{ threadGroup.iterateNum }}
</el-tag> </el-tag>
</template> </template>
<el-form :inline="true"> <el-form :inline="true">
@ -42,6 +42,7 @@
v-model="threadGroup.threadNumber" v-model="threadGroup.threadNumber"
@change="calculateTotalChart(threadGroup)" @change="calculateTotalChart(threadGroup)"
:min="resourcePoolResourceLength" :min="resourcePoolResourceLength"
:max="maxThreadNumbers"
size="mini"/> size="mini"/>
</el-form-item> </el-form-item>
<br> <br>
@ -219,7 +220,8 @@ export default {
resourcePools: [], resourcePools: [],
activeNames: ["0"], activeNames: ["0"],
threadGroups: [], threadGroups: [],
resourcePoolResourceLength: 1 resourcePoolResourceLength: 1,
maxThreadNumbers: 5000,
} }
}, },
mounted() { mounted() {
@ -336,6 +338,22 @@ export default {
}); });
} }
}, },
resourcePoolChange() {
let result = this.resourcePools.filter(p => p.id === this.resourcePool);
if (result.length === 1) {
let threadNumber = 0;
result[0].resources.forEach(resource => {
threadNumber += JSON.parse(resource.configuration).maxConcurrency;
})
this.maxThreadNumbers = threadNumber;
this.threadGroups.forEach(tg => {
if (tg.threadNumber > threadNumber) {
this.$set(tg, "threadNumber", threadNumber);
}
})
this.calculateTotalChart();
}
},
calculateTotalChart() { calculateTotalChart() {
let handler = this; let handler = this;
if (handler.duration < handler.rampUpTime) { if (handler.duration < handler.rampUpTime) {
@ -344,6 +362,11 @@ export default {
if (handler.rampUpTime < handler.step) { if (handler.rampUpTime < handler.step) {
handler.step = handler.rampUpTime; handler.step = handler.rampUpTime;
} }
// 线
let resourcePool = this.resourcePools.filter(v => v.id === this.resourcePool)[0];
if (resourcePool) {
this.resourcePoolResourceLength = resourcePool.resources.length;
}
let color = ['#60acfc', '#32d3eb', '#5bc49f', '#feb64d', '#ff7c7c', '#9287e7', '#ca8622', '#bda29a', '#6e7074', '#546570', '#c4ccd3']; let color = ['#60acfc', '#32d3eb', '#5bc49f', '#feb64d', '#ff7c7c', '#9287e7', '#ca8622', '#bda29a', '#6e7074', '#546570', '#c4ccd3'];
handler.options = { handler.options = {
color: color, color: color,
@ -649,7 +672,7 @@ export default {
border-bottom: 1px solid #DCDFE6; border-bottom: 1px solid #DCDFE6;
} }
/deep/ .el-collapse-item__content{ /deep/ .el-collapse-item__content {
padding-left: 10px; padding-left: 10px;
padding-bottom: 5px; padding-bottom: 5px;
border-left-width: 8px; border-left-width: 8px;