From 9d86f375cb899ab525cb02b731023523cc867975 Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Mon, 16 Oct 2023 13:48:19 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):?= =?UTF-8?q?=20=E6=AD=A3=E5=88=99=E6=8F=90=E5=8F=96=E6=96=B9=E5=BC=8F?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=87=AA=E5=AE=9A=E4=B9=89=E6=A8=A1=E7=89=88?= =?UTF-8?q?=E9=80=89=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --story=1013329 --user=赵勇 接口测试-正则提取-添加模版匹配规则选项 https://www.tapd.cn/55049933/s/1426415 Signed-off-by: fit2-zhao --- .../definition/request/extract/MsExtract.java | 6 ++++- .../request/extract/MsExtractRegex.java | 2 +- .../components/extract/ApiExtractCommon.vue | 23 +++++++++++++++++-- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/extract/MsExtract.java b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/extract/MsExtract.java index babad81943..2dbd7e542e 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/extract/MsExtract.java +++ b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/extract/MsExtract.java @@ -97,7 +97,11 @@ public class MsExtract extends MsTestElement { extractor.setMatchNumber(-1); } // $1$提取 JSON 响应中的第一个匹配项 $0$用于提取整个 JSON 响应 - extractor.setTemplate("$0$"); + if (StringUtils.isNotEmpty(extractRegex.getTemplate())) { + extractor.setTemplate(extractRegex.getTemplate()); + } else { + extractor.setTemplate("$1$"); + } extract.add(extractor.getRefName()); return extractor; diff --git a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/extract/MsExtractRegex.java b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/extract/MsExtractRegex.java index bb5782d066..a7cf11b169 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/extract/MsExtractRegex.java +++ b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/extract/MsExtractRegex.java @@ -7,7 +7,7 @@ import lombok.EqualsAndHashCode; @Data public class MsExtractRegex extends MsExtractCommon { private String useHeaders; - + private String template; public MsExtractRegex() { setType(MsExtractType.REGEX); } diff --git a/api-test/frontend/src/business/definition/components/extract/ApiExtractCommon.vue b/api-test/frontend/src/business/definition/components/extract/ApiExtractCommon.vue index 1c8004d087..a18482fd3a 100644 --- a/api-test/frontend/src/business/definition/components/extract/ApiExtractCommon.vue +++ b/api-test/frontend/src/business/definition/components/extract/ApiExtractCommon.vue @@ -31,7 +31,15 @@ size="small" show-word-limit :placeholder="expression" - @click.native="savePreParams(common.variable)" /> + @click.native="savePreParams(common.variable)" + style="width: 70%" /> + + @@ -104,10 +112,21 @@ export default { { label: 'Response Code', value: 'code' }, { label: 'Response Message', value: 'message' }, ], + restaurants: [ + { value: '$0$', id: '$0$' }, + { value: '$1$', id: '$1$' }, + ], }; }, - + created() { + if (!this.common.template) { + this.$set(this.common, 'template', '$1$'); + } + }, methods: { + querySearch(queryString, cb) { + cb(this.restaurants); + }, add() { this.common.type = this.extractType; this.list.push(new ExtractCommon(this.extractType, this.common));