From 27016d1014655c59fd3bc48aa7d8d38152e5e9e4 Mon Sep 17 00:00:00 2001 From: teukkk Date: Mon, 15 Apr 2024 19:11:26 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E8=AF=B7=E6=B1=82=E5=8F=82=E6=95=B0=E7=9A=84=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E5=90=8D=E7=A7=B0=E5=94=AF=E4=B8=80=E7=9A=84=E6=A0=A1=E9=AA=8C?= =?UTF-8?q?(=E5=89=8D=E7=BD=AE,=E5=90=8E=E7=BD=AE)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/models/apiTest/common.ts | 1 + .../api-test/components/condition/content.vue | 2 ++ .../api-test/components/condition/index.vue | 11 +++++-- .../components/requestComposition/index.vue | 33 +++++++++++++++---- .../requestComposition/postcondition.vue | 9 +++++ .../requestComposition/precondition.vue | 9 +++++ 6 files changed, 55 insertions(+), 10 deletions(-) diff --git a/frontend/src/models/apiTest/common.ts b/frontend/src/models/apiTest/common.ts index d29a71c29a..7c151f72ae 100644 --- a/frontend/src/models/apiTest/common.ts +++ b/frontend/src/models/apiTest/common.ts @@ -305,6 +305,7 @@ export type ExecuteConditionProcessor = Partial< export interface ExecuteConditionConfig { enableGlobal?: boolean; // 是否启用全局前/后置 默认为 true processors: ExecuteConditionProcessor[]; + activeItemId?: number; } // 执行请求-断言配置子项 export type ExecuteAssertionItem = ResponseAssertionCommon & diff --git a/frontend/src/views/api-test/components/condition/content.vue b/frontend/src/views/api-test/components/condition/content.vue index 654e19568e..e801f1fe60 100644 --- a/frontend/src/views/api-test/components/condition/content.vue +++ b/frontend/src/views/api-test/components/condition/content.vue @@ -727,6 +727,7 @@ if (!result){ title: 'apiTestDebug.paramName', dataIndex: 'key', slotName: 'key', + needValidRepeat: true, }, { title: 'apiTestDebug.extractValueByColumn', @@ -767,6 +768,7 @@ if (!result){ title: 'apiTestDebug.paramName', dataIndex: 'variableName', slotName: 'key', + needValidRepeat: true, width: 150, }, { diff --git a/frontend/src/views/api-test/components/condition/index.vue b/frontend/src/views/api-test/components/condition/index.vue index c6367971d4..109ae0480e 100644 --- a/frontend/src/views/api-test/components/condition/index.vue +++ b/frontend/src/views/api-test/components/condition/index.vue @@ -22,7 +22,7 @@ (data.value[0]); + const activeItemId = computed(() => activeItem.value?.id); function handleListActiveChange(item: ExecuteConditionProcessor) { activeItem.value = item; @@ -109,8 +110,8 @@ * 删除列表项 */ function deleteListItem(id: string | number) { - data.value = data.value.filter((precondition) => precondition.id !== activeItem.value.id); - if (activeItem.value.id === id) { + data.value = data.value.filter((precondition) => precondition.id !== activeItemId.value); + if (activeItemId.value === id) { [activeItem.value] = data.value; } emit('change'); @@ -244,6 +245,10 @@ [activeItem.value] = data.value; } }); + + defineExpose({ + activeItemId, + }); diff --git a/frontend/src/views/api-test/components/requestComposition/index.vue b/frontend/src/views/api-test/components/requestComposition/index.vue index 8409c6bd0d..f79f3a25b0 100644 --- a/frontend/src/views/api-test/components/requestComposition/index.vue +++ b/frontend/src/views/api-test/components/requestComposition/index.vue @@ -1361,6 +1361,12 @@ } } + function setChildErrorMessage(key: number | string, listItem: TabErrorMessage) { + if (requestVModel.value.errorMessageInfo) { + requestVModel.value.errorMessageInfo[requestVModel.value.activeTab][key] = cloneDeep(listItem); + } + } + function changeTabErrorMessageList(tabKey: string, formErrorMessageList: string[]) { if (!requestVModel.value.errorMessageInfo) return; const label = contentTabList.value.find((item) => item.value === tabKey)?.label ?? ''; @@ -1369,11 +1375,13 @@ label, messageList: formErrorMessageList, }; - // TODO: 处理前置的sql 后置的sql和提取 断言的响应头和变量 + initErrorMessageInfoItem(requestVModel.value.activeTab); if (requestVModel.value.activeTab === RequestComposition.BODY) { - initErrorMessageInfoItem(RequestComposition.BODY); - requestVModel.value.errorMessageInfo[RequestComposition.BODY][requestVModel.value.body.bodyType] = - cloneDeep(listItem); + setChildErrorMessage(requestVModel.value.body.bodyType, listItem); + } else if (requestVModel.value.activeTab === RequestComposition.POST_CONDITION) { + setChildErrorMessage(requestVModel.value.children[0].postProcessorConfig.activeItemId as number, listItem); + } else if (requestVModel.value.activeTab === RequestComposition.PRECONDITION) { + setChildErrorMessage(requestVModel.value.children[0].preProcessorConfig.activeItemId as number, listItem); } else { requestVModel.value.errorMessageInfo[requestVModel.value.activeTab] = cloneDeep(listItem); } @@ -1389,10 +1397,21 @@ if (!requestVModel.value.errorMessageInfo) return; const flattenedMessages: { label: string; messageList: string[] }[] = []; const { errorMessageInfo } = requestVModel.value; - Object.values(errorMessageInfo).forEach((item) => { - const label = item.label || (Object.values(item)[0] && Object.values(item)[0].label); + Object.entries(errorMessageInfo).forEach(([key, item]) => { + const label = item.label || Object.values(item)[0]?.label; + // 处理前后置已删除的 + if ([RequestComposition.POST_CONDITION as string, RequestComposition.PRECONDITION as string].includes(key)) { + const processorIds = requestVModel.value.children[0][ + key === RequestComposition.POST_CONDITION ? 'postProcessorConfig' : 'preProcessorConfig' + ].processors.map((processorItem) => String(processorItem.id)); + Object.entries(item).forEach(([childKey, childItem]) => { + if (!processorIds.includes(childKey)) { + childItem.messageList = []; + } + }); + } const messageList: string[] = - item.messageList || [...new Set(Object.values(item).flatMap((bodyType) => bodyType.messageList))] || []; + item.messageList || [...new Set(Object.values(item).flatMap((child) => child.messageList))] || []; if (messageList.length) { flattenedMessages.push({ label, messageList: [...new Set(messageList)] }); } diff --git a/frontend/src/views/api-test/components/requestComposition/postcondition.vue b/frontend/src/views/api-test/components/requestComposition/postcondition.vue index c0069fd574..ff5e2b36cb 100644 --- a/frontend/src/views/api-test/components/requestComposition/postcondition.vue +++ b/frontend/src/views/api-test/components/requestComposition/postcondition.vue @@ -1,5 +1,6 @@