From cc8736efcd9a3693ff774251a717b8fbf0f624d9 Mon Sep 17 00:00:00 2001 From: baiqi Date: Thu, 19 Dec 2024 15:12:35 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E6=8F=90=E5=8F=96=E8=A1=8C=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/models/apiTest/common.ts | 4 ++-- .../views/api-test/components/condition/content.vue | 12 ++++++++---- .../views/api-test/components/condition/index.vue | 9 +++++---- .../src/views/api-test/components/condition/list.vue | 6 +++--- frontend/src/views/api-test/components/config.ts | 3 ++- .../api-test/components/requestComposition/index.vue | 7 +++++-- .../management/components/management/api/index.vue | 3 ++- 7 files changed, 27 insertions(+), 17 deletions(-) diff --git a/frontend/src/models/apiTest/common.ts b/frontend/src/models/apiTest/common.ts index 918792623c..6ca22e6b67 100644 --- a/frontend/src/models/apiTest/common.ts +++ b/frontend/src/models/apiTest/common.ts @@ -227,7 +227,7 @@ export interface ResponseVariableAssertion { } // 执行请求-前后置操作处理器 export interface ExecuteConditionProcessorCommon { - id: number; // 处理器ID,前端列表渲染需要,后台无此字段 + id: string | number; // 处理器ID,前端列表渲染需要,后台无此字段 enable: boolean; // 是否启用 name?: string; // 条件处理器名称 processorType: RequestConditionProcessor; @@ -308,7 +308,7 @@ export type ExecuteConditionProcessor = Partial< export interface ExecuteConditionConfig { enableGlobal?: boolean; // 是否启用全局前/后置 默认为 true processors: ExecuteConditionProcessor[]; - activeItemId?: number; + activeItemId?: number | string; } // 执行请求-共用配置子项 export interface ExecuteCommonChild { diff --git a/frontend/src/views/api-test/components/condition/content.vue b/frontend/src/views/api-test/components/condition/content.vue index e49684024d..d41a811fa6 100644 --- a/frontend/src/views/api-test/components/condition/content.vue +++ b/frontend/src/views/api-test/components/condition/content.vue @@ -499,7 +499,7 @@ import { useI18n } from '@/hooks/useI18n'; import useModal from '@/hooks/useModal'; import useAppStore from '@/store/modules/app'; - import { characterLimit } from '@/utils'; + import { characterLimit, getGenerateId } from '@/utils'; import { hasAnyPermission } from '@/utils/permission'; import { @@ -546,7 +546,7 @@ ); const emit = defineEmits<{ (e: 'copy'): void; - (e: 'delete', id: number): void; + (e: 'delete', id: number | string): void; (e: 'change'): void; }>(); @@ -899,7 +899,11 @@ const defaultItem = ref( cloneDeep( condition.value.extractors?.length - ? condition.value.extractors[condition.value.extractors.length - 1] + ? { + ...defaultExtractParamItem, + variableType: condition.value.extractors[condition.value.extractors.length - 1].variableType, + extractType: condition.value.extractors[condition.value.extractors.length - 1].extractType, + } : defaultExtractParamItem ) ); @@ -933,7 +937,7 @@ if (currentIndex > -1) { condition.value.extractors.splice(currentIndex, 0, { ...currentExtractorsItem, - id: new Date().getTime().toString(), + id: getGenerateId(), }); const temList = cloneDeep(condition.value?.extractors); condition.value.extractors = temList; diff --git a/frontend/src/views/api-test/components/condition/index.vue b/frontend/src/views/api-test/components/condition/index.vue index 0f936f79ab..5c649bb656 100644 --- a/frontend/src/views/api-test/components/condition/index.vue +++ b/frontend/src/views/api-test/components/condition/index.vue @@ -61,6 +61,7 @@ import { conditionTypeNameMap } from '@/config/apiTest'; import { useI18n } from '@/hooks/useI18n'; + import { getGenerateId } from '@/utils'; import { ConditionType, ExecuteConditionProcessor, RegexExtract } from '@/models/apiTest/common'; import { RequestConditionProcessor, RequestExtractScope } from '@/enums/apiEnum'; @@ -104,7 +105,7 @@ function copyListItem() { const copyItem = { ...cloneDeep(activeItem.value), - id: new Date().getTime(), + id: getGenerateId(), }; list.value.push(copyItem as ExecuteConditionProcessor); activeItem.value = list.value[list.value.length - 1]; @@ -126,7 +127,7 @@ * 添加条件 */ function addCondition(value: ConditionType) { - const id = new Date().getTime(); + const id = getGenerateId(); switch (value) { // 脚本执行类型 case RequestConditionProcessor.SCRIPT: @@ -238,9 +239,9 @@ extractors: item.extractors?.map((e, j) => ({ ...e, extractScope: (e as RegexExtract).extractScope || RequestExtractScope.BODY, - id: new Date().getTime() + j, + id: getGenerateId() + j, })), - id: new Date().getTime() + i, + id: getGenerateId() + i, }; } return item; diff --git a/frontend/src/views/api-test/components/condition/list.vue b/frontend/src/views/api-test/components/condition/list.vue index e8df099e94..d8a7541cd9 100644 --- a/frontend/src/views/api-test/components/condition/list.vue +++ b/frontend/src/views/api-test/components/condition/list.vue @@ -69,7 +69,7 @@ import { conditionTypeNameMap } from '@/config/apiTest'; import { useI18n } from '@/hooks/useI18n'; import useModal from '@/hooks/useModal'; - import { characterLimit } from '@/utils'; + import { characterLimit, getGenerateId } from '@/utils'; import { ExecuteConditionProcessor } from '@/models/apiTest/common'; import { RequestConditionProcessor } from '@/enums/apiEnum'; @@ -161,7 +161,7 @@ function copyListItem(item: ExecuteConditionProcessor) { let copyItem = { ...cloneDeep(item), - id: new Date().getTime(), + id: getGenerateId(), }; const isExistPre = list.value.filter( (current) => current.beforeStepScript && current.processorType === RequestConditionProcessor.REQUEST_SCRIPT @@ -178,7 +178,7 @@ copyItem = { ...cloneDeep(item), beforeStepScript: !isExistPre, - id: new Date().getTime(), + id: getGenerateId(), }; const copyIndex = list.value.findIndex((e: ExecuteConditionProcessor) => e.id === item.id); diff --git a/frontend/src/views/api-test/components/config.ts b/frontend/src/views/api-test/components/config.ts index a36ffd7314..a4b64c8011 100644 --- a/frontend/src/views/api-test/components/config.ts +++ b/frontend/src/views/api-test/components/config.ts @@ -5,6 +5,7 @@ import { LanguageEnum } from '@/components/pure/ms-code-editor/types'; import { RequestParam } from '@/views/api-test/components/requestComposition/index.vue'; import { useI18n } from '@/hooks/useI18n'; +import { getGenerateId } from '@/utils'; import { EnableKeyValueParam, @@ -81,7 +82,7 @@ export const defaultRequestParamsItem: ExecuteRequestCommonParam = { // 请求的响应 response 默认的响应信息项 export const defaultResponseItem: ResponseDefinition = { - id: new Date().getTime(), + id: getGenerateId(), name: 'apiTestManagement.response', label: 'apiTestManagement.response', closable: false, diff --git a/frontend/src/views/api-test/components/requestComposition/index.vue b/frontend/src/views/api-test/components/requestComposition/index.vue index d900e79179..40cee8f25f 100644 --- a/frontend/src/views/api-test/components/requestComposition/index.vue +++ b/frontend/src/views/api-test/components/requestComposition/index.vue @@ -1010,8 +1010,11 @@ processor.extractParams || [], defaultKeyValueParamItem ).validParams; - } else if (processor.processorType === RequestConditionProcessor.EXTRACT) { - processor.extractors = filterKeyValParams(processor.extractors || [], defaultExtractParamItem).validParams; + } else if (processor.processorType === RequestConditionProcessor.EXTRACT && processor.extractors) { + processor.extractors = filterKeyValParams( + processor.extractors, + processor.extractors[processor.extractors.length - 1] + ).validParams; } return processor; }); diff --git a/frontend/src/views/api-test/management/components/management/api/index.vue b/frontend/src/views/api-test/management/components/management/api/index.vue index 9d64e22de8..76f917e580 100644 --- a/frontend/src/views/api-test/management/components/management/api/index.vue +++ b/frontend/src/views/api-test/management/components/management/api/index.vue @@ -136,6 +136,7 @@ import useAppStore from '@/store/modules/app'; import useCacheStore from '@/store/modules/cache/cache'; import useUserStore from '@/store/modules/user'; + import { getGenerateId } from '@/utils'; import { hasAnyPermission } from '@/utils/permission'; import { ProtocolItem } from '@/models/apiTest/common'; @@ -418,7 +419,7 @@ isNew: isCopy, unSaved: isCopy, isCopy, - id: isCopy ? new Date().getTime() : res.id, + id: isCopy ? getGenerateId() : res.id, isExecute, mode: isExecute ? 'debug' : 'definition', definitionActiveKey: isCopy || isExecute || isEdit ? 'definition' : 'preview',