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 { export interface ExecuteConditionProcessorCommon {
id: number; // 处理器ID前端列表渲染需要后台无此字段 id: string | number; // 处理器ID前端列表渲染需要后台无此字段
enable: boolean; // 是否启用 enable: boolean; // 是否启用
name?: string; // 条件处理器名称 name?: string; // 条件处理器名称
processorType: RequestConditionProcessor; processorType: RequestConditionProcessor;
@ -308,7 +308,7 @@ export type ExecuteConditionProcessor = Partial<
export interface ExecuteConditionConfig { export interface ExecuteConditionConfig {
enableGlobal?: boolean; // 是否启用全局前/后置 默认为 true enableGlobal?: boolean; // 是否启用全局前/后置 默认为 true
processors: ExecuteConditionProcessor[]; processors: ExecuteConditionProcessor[];
activeItemId?: number; activeItemId?: number | string;
} }
// 执行请求-共用配置子项 // 执行请求-共用配置子项
export interface ExecuteCommonChild { export interface ExecuteCommonChild {

View File

@ -499,7 +499,7 @@
import { useI18n } from '@/hooks/useI18n'; import { useI18n } from '@/hooks/useI18n';
import useModal from '@/hooks/useModal'; import useModal from '@/hooks/useModal';
import useAppStore from '@/store/modules/app'; import useAppStore from '@/store/modules/app';
import { characterLimit } from '@/utils'; import { characterLimit, getGenerateId } from '@/utils';
import { hasAnyPermission } from '@/utils/permission'; import { hasAnyPermission } from '@/utils/permission';
import { import {
@ -546,7 +546,7 @@
); );
const emit = defineEmits<{ const emit = defineEmits<{
(e: 'copy'): void; (e: 'copy'): void;
(e: 'delete', id: number): void; (e: 'delete', id: number | string): void;
(e: 'change'): void; (e: 'change'): void;
}>(); }>();
@ -899,7 +899,11 @@
const defaultItem = ref( const defaultItem = ref(
cloneDeep( cloneDeep(
condition.value.extractors?.length 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 : defaultExtractParamItem
) )
); );
@ -933,7 +937,7 @@
if (currentIndex > -1) { if (currentIndex > -1) {
condition.value.extractors.splice(currentIndex, 0, { condition.value.extractors.splice(currentIndex, 0, {
...currentExtractorsItem, ...currentExtractorsItem,
id: new Date().getTime().toString(), id: getGenerateId(),
}); });
const temList = cloneDeep(condition.value?.extractors); const temList = cloneDeep(condition.value?.extractors);
condition.value.extractors = temList; condition.value.extractors = temList;

View File

@ -61,6 +61,7 @@
import { conditionTypeNameMap } from '@/config/apiTest'; import { conditionTypeNameMap } from '@/config/apiTest';
import { useI18n } from '@/hooks/useI18n'; import { useI18n } from '@/hooks/useI18n';
import { getGenerateId } from '@/utils';
import { ConditionType, ExecuteConditionProcessor, RegexExtract } from '@/models/apiTest/common'; import { ConditionType, ExecuteConditionProcessor, RegexExtract } from '@/models/apiTest/common';
import { RequestConditionProcessor, RequestExtractScope } from '@/enums/apiEnum'; import { RequestConditionProcessor, RequestExtractScope } from '@/enums/apiEnum';
@ -104,7 +105,7 @@
function copyListItem() { function copyListItem() {
const copyItem = { const copyItem = {
...cloneDeep(activeItem.value), ...cloneDeep(activeItem.value),
id: new Date().getTime(), id: getGenerateId(),
}; };
list.value.push(copyItem as ExecuteConditionProcessor); list.value.push(copyItem as ExecuteConditionProcessor);
activeItem.value = list.value[list.value.length - 1]; activeItem.value = list.value[list.value.length - 1];
@ -126,7 +127,7 @@
* 添加条件 * 添加条件
*/ */
function addCondition(value: ConditionType) { function addCondition(value: ConditionType) {
const id = new Date().getTime(); const id = getGenerateId();
switch (value) { switch (value) {
// //
case RequestConditionProcessor.SCRIPT: case RequestConditionProcessor.SCRIPT:
@ -238,9 +239,9 @@
extractors: item.extractors?.map((e, j) => ({ extractors: item.extractors?.map((e, j) => ({
...e, ...e,
extractScope: (e as RegexExtract).extractScope || RequestExtractScope.BODY, 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; return item;

View File

@ -69,7 +69,7 @@
import { conditionTypeNameMap } from '@/config/apiTest'; import { conditionTypeNameMap } from '@/config/apiTest';
import { useI18n } from '@/hooks/useI18n'; import { useI18n } from '@/hooks/useI18n';
import useModal from '@/hooks/useModal'; import useModal from '@/hooks/useModal';
import { characterLimit } from '@/utils'; import { characterLimit, getGenerateId } from '@/utils';
import { ExecuteConditionProcessor } from '@/models/apiTest/common'; import { ExecuteConditionProcessor } from '@/models/apiTest/common';
import { RequestConditionProcessor } from '@/enums/apiEnum'; import { RequestConditionProcessor } from '@/enums/apiEnum';
@ -161,7 +161,7 @@
function copyListItem(item: ExecuteConditionProcessor) { function copyListItem(item: ExecuteConditionProcessor) {
let copyItem = { let copyItem = {
...cloneDeep(item), ...cloneDeep(item),
id: new Date().getTime(), id: getGenerateId(),
}; };
const isExistPre = list.value.filter( const isExistPre = list.value.filter(
(current) => current.beforeStepScript && current.processorType === RequestConditionProcessor.REQUEST_SCRIPT (current) => current.beforeStepScript && current.processorType === RequestConditionProcessor.REQUEST_SCRIPT
@ -178,7 +178,7 @@
copyItem = { copyItem = {
...cloneDeep(item), ...cloneDeep(item),
beforeStepScript: !isExistPre, beforeStepScript: !isExistPre,
id: new Date().getTime(), id: getGenerateId(),
}; };
const copyIndex = list.value.findIndex((e: ExecuteConditionProcessor) => e.id === item.id); 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 { RequestParam } from '@/views/api-test/components/requestComposition/index.vue';
import { useI18n } from '@/hooks/useI18n'; import { useI18n } from '@/hooks/useI18n';
import { getGenerateId } from '@/utils';
import { import {
EnableKeyValueParam, EnableKeyValueParam,
@ -81,7 +82,7 @@ export const defaultRequestParamsItem: ExecuteRequestCommonParam = {
// 请求的响应 response 默认的响应信息项 // 请求的响应 response 默认的响应信息项
export const defaultResponseItem: ResponseDefinition = { export const defaultResponseItem: ResponseDefinition = {
id: new Date().getTime(), id: getGenerateId(),
name: 'apiTestManagement.response', name: 'apiTestManagement.response',
label: 'apiTestManagement.response', label: 'apiTestManagement.response',
closable: false, closable: false,

View File

@ -1010,8 +1010,11 @@
processor.extractParams || [], processor.extractParams || [],
defaultKeyValueParamItem defaultKeyValueParamItem
).validParams; ).validParams;
} else if (processor.processorType === RequestConditionProcessor.EXTRACT) { } else if (processor.processorType === RequestConditionProcessor.EXTRACT && processor.extractors) {
processor.extractors = filterKeyValParams(processor.extractors || [], defaultExtractParamItem).validParams; processor.extractors = filterKeyValParams(
processor.extractors,
processor.extractors[processor.extractors.length - 1]
).validParams;
} }
return processor; return processor;
}); });

View File

@ -136,6 +136,7 @@
import useAppStore from '@/store/modules/app'; import useAppStore from '@/store/modules/app';
import useCacheStore from '@/store/modules/cache/cache'; import useCacheStore from '@/store/modules/cache/cache';
import useUserStore from '@/store/modules/user'; import useUserStore from '@/store/modules/user';
import { getGenerateId } from '@/utils';
import { hasAnyPermission } from '@/utils/permission'; import { hasAnyPermission } from '@/utils/permission';
import { ProtocolItem } from '@/models/apiTest/common'; import { ProtocolItem } from '@/models/apiTest/common';
@ -418,7 +419,7 @@
isNew: isCopy, isNew: isCopy,
unSaved: isCopy, unSaved: isCopy,
isCopy, isCopy,
id: isCopy ? new Date().getTime() : res.id, id: isCopy ? getGenerateId() : res.id,
isExecute, isExecute,
mode: isExecute ? 'debug' : 'definition', mode: isExecute ? 'debug' : 'definition',
definitionActiveKey: isCopy || isExecute || isEdit ? 'definition' : 'preview', definitionActiveKey: isCopy || isExecute || isEdit ? 'definition' : 'preview',