From 1578a81d8f0d737d856788a173351946666ba36f Mon Sep 17 00:00:00 2001 From: shiziyuan9527 Date: Tue, 21 Apr 2020 14:27:12 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=A7=E7=94=9F?= =?UTF-8?q?=E6=8A=A5=E5=91=8A=E7=9A=84=E5=90=8E=E5=8F=B0=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/metersphere/report/JtlResolver.java | 129 ++-------------- .../report/parse/ResultDataParse.java | 139 ++++++++++++++++++ 2 files changed, 153 insertions(+), 115 deletions(-) create mode 100644 backend/src/main/java/io/metersphere/report/parse/ResultDataParse.java diff --git a/backend/src/main/java/io/metersphere/report/JtlResolver.java b/backend/src/main/java/io/metersphere/report/JtlResolver.java index e4b79a1c79..5e3b4d163e 100644 --- a/backend/src/main/java/io/metersphere/report/JtlResolver.java +++ b/backend/src/main/java/io/metersphere/report/JtlResolver.java @@ -3,23 +3,16 @@ package io.metersphere.report; import com.opencsv.bean.CsvToBean; import com.opencsv.bean.CsvToBeanBuilder; import com.opencsv.bean.HeaderColumnNameMappingStrategy; -import io.metersphere.commons.utils.MsJMeterUtils; import io.metersphere.report.base.*; import io.metersphere.report.dto.ErrorsTop5DTO; import io.metersphere.report.dto.RequestStatisticsDTO; +import io.metersphere.report.parse.ResultDataParse; import org.apache.commons.lang3.StringUtils; -import org.apache.jmeter.report.core.Sample; -import org.apache.jmeter.report.core.SampleMetadata; -import org.apache.jmeter.report.dashboard.JsonizerVisitor; -import org.apache.jmeter.report.processor.*; -import org.apache.jmeter.report.processor.graph.AbstractOverTimeGraphConsumer; import org.apache.jmeter.report.processor.graph.impl.ActiveThreadsGraphConsumer; import org.apache.jmeter.report.processor.graph.impl.HitsPerSecondGraphConsumer; import org.apache.jmeter.report.processor.graph.impl.ResponseTimeOverTimeGraphConsumer; - import java.io.Reader; import java.io.StringReader; -import java.math.BigDecimal; import java.text.DecimalFormat; import java.text.ParseException; import java.text.SimpleDateFormat; @@ -278,7 +271,7 @@ public class JtlResolver { DecimalFormat decimalFormat = new DecimalFormat("0.00"); List totalLineList = JtlResolver.resolver(jtlString); - // todo + // todo 修改测试概览的数值 List totalLineList2 = JtlResolver.resolver(jtlString); // 时间戳转时间 for (Metric metric : totalLineList2) { @@ -343,115 +336,21 @@ public class JtlResolver { } public static List getLoadChartData(String jtlString) { - Map activeThreadMap = getResultDataMap(jtlString, new ActiveThreadsGraphConsumer()); - Map hitsMap = getResultDataMap(jtlString, new HitsPerSecondGraphConsumer()); - List activeThreadList = new ArrayList<>(); - List hitsList = new ArrayList<>(); - mapResolver(activeThreadMap, activeThreadList, "users"); - mapResolver(hitsMap, hitsList, "hits"); - activeThreadList.addAll(hitsList); - return activeThreadList; + Map activeThreadMap = ResultDataParse.getGraphDataMap(jtlString, new ActiveThreadsGraphConsumer()); + Map hitsMap = ResultDataParse.getGraphDataMap(jtlString, new HitsPerSecondGraphConsumer()); + List resultList = ResultDataParse.graphMapParsing(activeThreadMap, "users"); + List hitsList = ResultDataParse.graphMapParsing(hitsMap, "hits"); + resultList.addAll(hitsList); + return resultList; } public static List getResponseTimeChartData(String jtlString) { - Map activeThreadMap = getResultDataMap(jtlString, new ActiveThreadsGraphConsumer()); - Map responseTimeMap = getResultDataMap(jtlString, new ResponseTimeOverTimeGraphConsumer()); - List activeThreadList = new ArrayList<>(); - List responseTimeList = new ArrayList<>(); - mapResolver(activeThreadMap, activeThreadList, "users"); - mapResolver(responseTimeMap, responseTimeList, "responseTime"); - activeThreadList.addAll(responseTimeList); - return activeThreadList; - - } - - public static void mapResolver(Map map, List list, String seriesName) { - // ThreadGroup-1 - for (String key : map.keySet()) { - MapResultData mapResultData = (MapResultData) map.get(key); - ResultData maxY = mapResultData.getResult("maxY"); - ListResultData series = (ListResultData) mapResultData.getResult("series"); - if (series.getSize() > 0) { - for (int j = 0; j < series.getSize(); j++) { - MapResultData resultData = (MapResultData) series.get(j); - // data, isOverall, label, isController - ListResultData data = (ListResultData) resultData.getResult("data"); - ValueResultData label = (ValueResultData) resultData.getResult("label"); - - if (data.getSize() > 0) { - for (int i = 0; i < data.getSize(); i++) { - ListResultData listResultData = (ListResultData) data.get(i); - String result = listResultData.accept(new JsonizerVisitor()); - result = result.substring(1, result.length() - 1); - String[] split = result.split(","); - ChartsData chartsData = new ChartsData(); - BigDecimal bigDecimal = new BigDecimal(split[0]); - String timeStamp = bigDecimal.toPlainString(); - String time = null; - try { - time = formatDate(stampToDate(DATE_TIME_PATTERN, timeStamp)); - } catch (ParseException e) { - e.printStackTrace(); - } - chartsData.setxAxis(time); - chartsData.setyAxis(new BigDecimal(split[1].trim())); - if (series.getSize() == 1) { - chartsData.setGroupName(seriesName); - } else { - chartsData.setGroupName((String) label.getValue()); - } - list.add(chartsData); - } - } - } - - - } - } - } - - public static Map getResultDataMap(String jtlString, AbstractOverTimeGraphConsumer timeGraphConsumer) { - int row = 0; - AbstractOverTimeGraphConsumer abstractOverTimeGraphConsumer = timeGraphConsumer; - abstractOverTimeGraphConsumer.setGranularity(60000); - // 使用反射获取properties - MsJMeterUtils.loadJMeterProperties("jmeter.properties"); // 这个路径不存在 - SampleMetadata sampleMetaData = createTestMetaData(); - SampleContext sampleContext = new SampleContext(); - abstractOverTimeGraphConsumer.setSampleContext(sampleContext); - abstractOverTimeGraphConsumer.initialize(); - abstractOverTimeGraphConsumer.startConsuming(); - StringTokenizer tokenizer = new StringTokenizer(jtlString, "\n"); - // 去掉第一行 - tokenizer.nextToken(); - while (tokenizer.hasMoreTokens()) { - String line = tokenizer.nextToken(); - String[] data = line.split(",", -1); - Sample sample = new Sample(row++, sampleMetaData, data); - abstractOverTimeGraphConsumer.consume(sample, 0); - } - abstractOverTimeGraphConsumer.stopConsuming(); - return sampleContext.getData(); - } - - // Create a static SampleMetadataObject - private static SampleMetadata createTestMetaData() { - String columnsString = "timeStamp,elapsed,label,responseCode,responseMessage,threadName,success,failureMessage,bytes,sentBytes,grpThreads,allThreads,URL,Latency,IdleTime,Connect"; - columnsString = "timeStamp,elapsed,label,responseCode,responseMessage,threadName,dataType,success,failureMessage,bytes,sentBytes,grpThreads,allThreads,URL,Latency,IdleTime,Connect"; - - String[] columns = new String[17]; - int lastComa = 0; - int columnIndex = 0; - for (int i = 0; i < columnsString.length(); i++) { - if (columnsString.charAt(i) == ',') { - columns[columnIndex] = columnsString.substring(lastComa, i); - lastComa = i + 1; - columnIndex++; - } else if (i + 1 == columnsString.length()) { - columns[columnIndex] = columnsString.substring(lastComa, i + 1); - } - } - return new SampleMetadata(',', columns); + Map activeThreadMap = ResultDataParse.getGraphDataMap(jtlString, new ActiveThreadsGraphConsumer()); + Map responseTimeMap = ResultDataParse.getGraphDataMap(jtlString, new ResponseTimeOverTimeGraphConsumer()); + List resultList = ResultDataParse.graphMapParsing(activeThreadMap, "users"); + List responseTimeList = ResultDataParse.graphMapParsing(responseTimeMap, "responseTime"); + resultList.addAll(responseTimeList); + return resultList; } public static ReportTimeInfo getReportTimeInfo(String jtlString) { diff --git a/backend/src/main/java/io/metersphere/report/parse/ResultDataParse.java b/backend/src/main/java/io/metersphere/report/parse/ResultDataParse.java new file mode 100644 index 0000000000..016fbc0855 --- /dev/null +++ b/backend/src/main/java/io/metersphere/report/parse/ResultDataParse.java @@ -0,0 +1,139 @@ +package io.metersphere.report.parse; + +import io.metersphere.commons.utils.MsJMeterUtils; +import io.metersphere.report.base.ChartsData; +import org.apache.jmeter.report.core.Sample; +import org.apache.jmeter.report.core.SampleMetadata; +import org.apache.jmeter.report.dashboard.JsonizerVisitor; +import org.apache.jmeter.report.processor.*; +import org.apache.jmeter.report.processor.graph.AbstractOverTimeGraphConsumer; +import java.math.BigDecimal; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.time.Instant; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.StringTokenizer; + +public class ResultDataParse { + + private static final String DATE_TIME_PATTERN = "yyyy/MM/dd HH:mm:ss"; + private static final String TIME_PATTERN = "HH:mm:ss"; + + public static List graphMapParsing(Map map, String seriesName) { + List list = new ArrayList<>(); + // ThreadGroup + for (String key : map.keySet()) { + MapResultData mapResultData = (MapResultData) map.get(key); + ResultData maxY = mapResultData.getResult("maxY"); + ListResultData series = (ListResultData) mapResultData.getResult("series"); + if (series.getSize() > 0) { + for (int j = 0; j < series.getSize(); j++) { + MapResultData resultData = (MapResultData) series.get(j); + // data, isOverall, label, isController + ListResultData data = (ListResultData) resultData.getResult("data"); + ValueResultData label = (ValueResultData) resultData.getResult("label"); + + if (data.getSize() > 0) { + for (int i = 0; i < data.getSize(); i++) { + ListResultData listResultData = (ListResultData) data.get(i); + String result = listResultData.accept(new JsonizerVisitor()); + result = result.substring(1, result.length() - 1); + String[] split = result.split(","); + ChartsData chartsData = new ChartsData(); + BigDecimal bigDecimal = new BigDecimal(split[0]); + String timeStamp = bigDecimal.toPlainString(); + String time = null; + try { + time = formatDate(stampToDate(DATE_TIME_PATTERN, timeStamp)); + } catch (ParseException e) { + e.printStackTrace(); + } + chartsData.setxAxis(time); + chartsData.setyAxis(new BigDecimal(split[1].trim())); + if (series.getSize() == 1) { + chartsData.setGroupName(seriesName); + } else { + chartsData.setGroupName((String) label.getValue()); + } + list.add(chartsData); + } + } + } + + } + } + return list; + } + + public static Map getGraphDataMap(String jtlString, AbstractOverTimeGraphConsumer timeGraphConsumer) { + AbstractOverTimeGraphConsumer abstractOverTimeGraphConsumer = timeGraphConsumer; + abstractOverTimeGraphConsumer.setGranularity(60000); + abstractOverTimeGraphConsumer.initialize(); + SampleContext sampleContext = initJmeterConsumer(jtlString, abstractOverTimeGraphConsumer); + return sampleContext.getData(); + } + + public static Map getSummryDataMap(String jtlString, AbstractSummaryConsumer summaryConsumer) { + AbstractSummaryConsumer abstractSummaryConsumer = summaryConsumer; + SampleContext sampleContext = initJmeterConsumer(jtlString, summaryConsumer); + return sampleContext.getData(); + } + + private static SampleContext initJmeterConsumer(String jtlString, AbstractSampleConsumer abstractSampleConsumer) { + int row = 0; + // 使用反射获取properties + MsJMeterUtils.loadJMeterProperties("jmeter.properties"); + SampleMetadata sampleMetaData = createTestMetaData(); + SampleContext sampleContext = new SampleContext(); + abstractSampleConsumer.setSampleContext(sampleContext); + abstractSampleConsumer.startConsuming(); + StringTokenizer tokenizer = new StringTokenizer(jtlString, "\n"); + // 去掉第一行 + tokenizer.nextToken(); + while (tokenizer.hasMoreTokens()) { + String line = tokenizer.nextToken(); + String[] data = line.split(",", -1); + Sample sample = new Sample(row++, sampleMetaData, data); + abstractSampleConsumer.consume(sample, 0); + } + abstractSampleConsumer.stopConsuming(); + return sampleContext; + } + + // Create a static SampleMetadataObject + private static SampleMetadata createTestMetaData() { + String columnsString = "timeStamp,elapsed,label,responseCode,responseMessage,threadName,success,failureMessage,bytes,sentBytes,grpThreads,allThreads,URL,Latency,IdleTime,Connect"; + columnsString = "timeStamp,elapsed,label,responseCode,responseMessage,threadName,dataType,success,failureMessage,bytes,sentBytes,grpThreads,allThreads,URL,Latency,IdleTime,Connect"; + + String[] columns = new String[17]; + int lastComa = 0; + int columnIndex = 0; + for (int i = 0; i < columnsString.length(); i++) { + if (columnsString.charAt(i) == ',') { + columns[columnIndex] = columnsString.substring(lastComa, i); + lastComa = i + 1; + columnIndex++; + } else if (i + 1 == columnsString.length()) { + columns[columnIndex] = columnsString.substring(lastComa, i + 1); + } + } + return new SampleMetadata(',', columns); + } + + private static String stampToDate(String pattern, String timeStamp) { + DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(pattern); + LocalDateTime localDateTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(Long.parseLong(timeStamp)), ZoneId.systemDefault()); + return localDateTime.format(dateTimeFormatter); + } + + private static String formatDate(String dateString) throws ParseException { + SimpleDateFormat before = new SimpleDateFormat(DATE_TIME_PATTERN); + SimpleDateFormat after = new SimpleDateFormat(TIME_PATTERN); + return after.format(before.parse(dateString)); + } +} From 3b0e2c11b78816dda4067d422314cc2342f05617 Mon Sep 17 00:00:00 2001 From: shiziyuan9527 Date: Tue, 21 Apr 2020 14:33:10 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=90=8D=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{JtlResolver.java => GenerateReport.java} | 12 ++++++------ .../io/metersphere/service/ReportService.java | 16 ++++++++-------- 2 files changed, 14 insertions(+), 14 deletions(-) rename backend/src/main/java/io/metersphere/report/{JtlResolver.java => GenerateReport.java} (97%) diff --git a/backend/src/main/java/io/metersphere/report/JtlResolver.java b/backend/src/main/java/io/metersphere/report/GenerateReport.java similarity index 97% rename from backend/src/main/java/io/metersphere/report/JtlResolver.java rename to backend/src/main/java/io/metersphere/report/GenerateReport.java index 5e3b4d163e..870b4b6673 100644 --- a/backend/src/main/java/io/metersphere/report/JtlResolver.java +++ b/backend/src/main/java/io/metersphere/report/GenerateReport.java @@ -24,7 +24,7 @@ import java.time.format.DateTimeFormatter; import java.util.*; import java.util.stream.Collectors; -public class JtlResolver { +public class GenerateReport { private static final Integer ERRORS_TOP_SIZE = 5; private static final String DATE_TIME_PATTERN = "yyyy/MM/dd HH:mm:ss"; @@ -186,7 +186,7 @@ public class JtlResolver { } } - Map> jtlMap = falseList.stream().collect(Collectors.groupingBy(JtlResolver::getResponseCodeAndFailureMessage)); + Map> jtlMap = falseList.stream().collect(Collectors.groupingBy(GenerateReport::getResponseCodeAndFailureMessage)); for (Map.Entry> next : jtlMap.entrySet()) { String key = next.getKey(); @@ -219,7 +219,7 @@ public class JtlResolver { .collect(Collectors.toList()); Map> collect = falseList.stream() - .collect(Collectors.groupingBy(JtlResolver::getResponseCodeAndFailureMessage)); + .collect(Collectors.groupingBy(GenerateReport::getResponseCodeAndFailureMessage)); for (Map.Entry> next : collect.entrySet()) { String key = next.getKey(); @@ -270,9 +270,9 @@ public class JtlResolver { TestOverview testOverview = new TestOverview(); DecimalFormat decimalFormat = new DecimalFormat("0.00"); - List totalLineList = JtlResolver.resolver(jtlString); + List totalLineList = GenerateReport.resolver(jtlString); // todo 修改测试概览的数值 - List totalLineList2 = JtlResolver.resolver(jtlString); + List totalLineList2 = GenerateReport.resolver(jtlString); // 时间戳转时间 for (Metric metric : totalLineList2) { metric.setTimestamp(stampToDate(DATE_TIME_PATTERN, metric.getTimestamp())); @@ -355,7 +355,7 @@ public class JtlResolver { public static ReportTimeInfo getReportTimeInfo(String jtlString) { ReportTimeInfo reportTimeInfo = new ReportTimeInfo(); - List totalLineList = JtlResolver.resolver(jtlString); + List totalLineList = GenerateReport.resolver(jtlString); totalLineList.sort(Comparator.comparing(t0 -> Long.valueOf(t0.getTimestamp()))); diff --git a/backend/src/main/java/io/metersphere/service/ReportService.java b/backend/src/main/java/io/metersphere/service/ReportService.java index 38c2e88c92..a833a5a07a 100644 --- a/backend/src/main/java/io/metersphere/service/ReportService.java +++ b/backend/src/main/java/io/metersphere/service/ReportService.java @@ -11,7 +11,7 @@ import io.metersphere.controller.request.ReportRequest; import io.metersphere.dto.ReportDTO; import io.metersphere.engine.Engine; import io.metersphere.engine.EngineFactory; -import io.metersphere.report.JtlResolver; +import io.metersphere.report.GenerateReport; import io.metersphere.report.base.ChartsData; import io.metersphere.report.base.Errors; import io.metersphere.report.base.ReportTimeInfo; @@ -90,7 +90,7 @@ public class ReportService { checkReportStatus(id); LoadTestReportWithBLOBs loadTestReport = loadTestReportMapper.selectByPrimaryKey(id); String content = loadTestReport.getContent(); - RequestStatisticsDTO requestStatistics = JtlResolver.getRequestStatistics(content); + RequestStatisticsDTO requestStatistics = GenerateReport.getRequestStatistics(content); return requestStatistics; } @@ -98,7 +98,7 @@ public class ReportService { checkReportStatus(id); LoadTestReportWithBLOBs loadTestReport = loadTestReportMapper.selectByPrimaryKey(id); String content = loadTestReport.getContent(); - List errors = JtlResolver.getErrorsList(content); + List errors = GenerateReport.getErrorsList(content); return errors; } @@ -106,7 +106,7 @@ public class ReportService { checkReportStatus(id); LoadTestReportWithBLOBs loadTestReport = loadTestReportMapper.selectByPrimaryKey(id); String content = loadTestReport.getContent(); - ErrorsTop5DTO errors = JtlResolver.getErrorsTop5DTO(content); + ErrorsTop5DTO errors = GenerateReport.getErrorsTop5DTO(content); return errors; } @@ -114,7 +114,7 @@ public class ReportService { checkReportStatus(id); LoadTestReportWithBLOBs loadTestReport = loadTestReportMapper.selectByPrimaryKey(id); String content = loadTestReport.getContent(); - TestOverview testOverview = JtlResolver.getTestOverview(content); + TestOverview testOverview = GenerateReport.getTestOverview(content); return testOverview; } @@ -122,7 +122,7 @@ public class ReportService { checkReportStatus(id); LoadTestReportWithBLOBs loadTestReport = loadTestReportMapper.selectByPrimaryKey(id); String content = loadTestReport.getContent(); - ReportTimeInfo reportTimeInfo = JtlResolver.getReportTimeInfo(content); + ReportTimeInfo reportTimeInfo = GenerateReport.getReportTimeInfo(content); return reportTimeInfo; } @@ -130,7 +130,7 @@ public class ReportService { checkReportStatus(id); LoadTestReportWithBLOBs loadTestReport = loadTestReportMapper.selectByPrimaryKey(id); String content = loadTestReport.getContent(); - List chartsDataList = JtlResolver.getLoadChartData(content); + List chartsDataList = GenerateReport.getLoadChartData(content); return chartsDataList; } @@ -138,7 +138,7 @@ public class ReportService { checkReportStatus(id); LoadTestReportWithBLOBs loadTestReport = loadTestReportMapper.selectByPrimaryKey(id); String content = loadTestReport.getContent(); - List chartsDataList = JtlResolver.getResponseTimeChartData(content); + List chartsDataList = GenerateReport.getResponseTimeChartData(content); return chartsDataList; } From 8dc3249347066bba648cfdde3a41fa18e70901c9 Mon Sep 17 00:00:00 2001 From: q4speed Date: Tue, 21 Apr 2020 15:43:52 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=A9=BA=E6=95=B0?= =?UTF-8?q?=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/api/test/ApiTestConfig.vue | 25 ++++++--- .../api/test/components/ApiAssertionRegex.vue | 6 +-- .../api/test/components/ApiAssertionText.vue | 16 +++--- .../api/test/components/ApiKeyValue.vue | 51 ++++++++++--------- .../api/test/components/ApiRequestConfig.vue | 2 +- .../api/test/components/ApiRequestForm.vue | 20 ++++---- .../api/test/components/ApiScenarioConfig.vue | 7 ++- .../api/test/components/ApiScenarioForm.vue | 2 +- 8 files changed, 70 insertions(+), 59 deletions(-) diff --git a/frontend/src/business/components/api/test/ApiTestConfig.vue b/frontend/src/business/components/api/test/ApiTestConfig.vue index a85f5edc15..50d26f98b1 100644 --- a/frontend/src/business/components/api/test/ApiTestConfig.vue +++ b/frontend/src/business/components/api/test/ApiTestConfig.vue @@ -8,13 +8,13 @@ - + 保存 - + @@ -35,9 +35,10 @@ projects: [], change: false, test: { + id: null, projectId: null, name: null, - scenario_definition: [] + scenarioDefinition: [] } } }, @@ -53,11 +54,21 @@ methods: { saveTest: function () { - this.change = false; - this.$message({ - message: this.$t('commons.save_success'), - type: 'success' + + let param = { + id: this.test.id, + projectId: this.test.projectId, + name: this.test.name, + scenarioDefinition: JSON.stringify(this.test.scenarioDefinition) + } + + this.result = this.$post("/api/save", param, response => { + this.test.id = response.data; + this.$message({ + message: this.$t('commons.save_success'), + type: 'success' + }); }); } }, diff --git a/frontend/src/business/components/api/test/components/ApiAssertionRegex.vue b/frontend/src/business/components/api/test/components/ApiAssertionRegex.vue index 3c53617938..bc61db655b 100644 --- a/frontend/src/business/components/api/test/components/ApiAssertionRegex.vue +++ b/frontend/src/business/components/api/test/components/ApiAssertionRegex.vue @@ -4,9 +4,9 @@ - - - + + + diff --git a/frontend/src/business/components/api/test/components/ApiAssertionText.vue b/frontend/src/business/components/api/test/components/ApiAssertionText.vue index 9916f71637..20bc6840c6 100644 --- a/frontend/src/business/components/api/test/components/ApiAssertionText.vue +++ b/frontend/src/business/components/api/test/components/ApiAssertionText.vue @@ -4,19 +4,19 @@ - - - + + + - - - - - + + + + + diff --git a/frontend/src/business/components/api/test/components/ApiKeyValue.vue b/frontend/src/business/components/api/test/components/ApiKeyValue.vue index ed90e30d78..12aff27318 100644 --- a/frontend/src/business/components/api/test/components/ApiKeyValue.vue +++ b/frontend/src/business/components/api/test/components/ApiKeyValue.vue @@ -12,8 +12,21 @@ - + + + + + +
+ + + + + + + + +
@@ -31,45 +44,33 @@ items: Array }, + data() { + return { + kv: new KeyValue() + } + }, + methods: { add: function () { - this.items.push(new KeyValue()); + if (this.kv.key || this.kv.value) { + this.items.push(this.kv); + this.kv = new KeyValue(); + } }, remove: function (index) { this.items.splice(index, 1); - if (this.items.length === 0) { - this.add(); - } }, check: function () { - let isNeedCreate = true; let removeIndex = -1; this.items.forEach((item, index) => { if (!item.key && !item.value) { - // 多余的空行 - if (index !== this.items.length - 1) { - removeIndex = index; - } - // 没有空行,需要创建空行 - isNeedCreate = false; + removeIndex = index; } }); - if (isNeedCreate) { - this.add(); - } if (removeIndex !== -1) { this.remove(removeIndex); } // TODO 检查key重复 - }, - isDisable: function (index) { - return this.items.length - 1 === index; - } - }, - - created() { - if (this.items.length === 0) { - this.add(); } } } diff --git a/frontend/src/business/components/api/test/components/ApiRequestConfig.vue b/frontend/src/business/components/api/test/components/ApiRequestConfig.vue index 9746e52699..7e6f87a15d 100644 --- a/frontend/src/business/components/api/test/components/ApiRequestConfig.vue +++ b/frontend/src/business/components/api/test/components/ApiRequestConfig.vue @@ -11,7 +11,7 @@
- + 复制请求 删除请求 diff --git a/frontend/src/business/components/api/test/components/ApiRequestForm.vue b/frontend/src/business/components/api/test/components/ApiRequestForm.vue index 0ddf3375e9..34b0791f57 100644 --- a/frontend/src/business/components/api/test/components/ApiRequestForm.vue +++ b/frontend/src/business/components/api/test/components/ApiRequestForm.vue @@ -1,20 +1,20 @@