fix(接口测试): 参数提取行修复

This commit is contained in:
baiqi 2024-12-19 15:12:35 +08:00 committed by 刘瑞斌
parent 7cec9c2c76
commit cc8736efcd
7 changed files with 27 additions and 17 deletions

View File

@ -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 {

View File

@ -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;

View File

@ -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;

View File

@ -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);

View File

@ -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,

View File

@ -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;
});

View File

@ -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',