From 886d566c21c5249631607f355b9b38b5062f29d5 Mon Sep 17 00:00:00 2001 From: baiqi Date: Sat, 23 Mar 2024 22:53:55 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=8E=A5=E5=8F=A3=E5=9C=BA=E6=99=AF):=20?= =?UTF-8?q?=E5=9C=BA=E6=99=AF=E6=AD=A5=E9=AA=A4=E8=87=AA=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E8=AF=B7=E6=B1=82=E4=BF=9D=E5=AD=98&=E6=9F=A5=E7=9C=8B?= =?UTF-8?q?=E8=AF=A6=E6=83=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/api/modules/api-test/scenario.ts | 14 + frontend/src/api/requrls/api-test/scenario.ts | 2 + .../business/ms-assertion/index.vue | 5 +- .../src/components/pure/ms-drawer/index.vue | 2 +- .../components/pure/ms-table/select-all.vue | 2 +- frontend/src/enums/apiEnum.ts | 47 ++- frontend/src/models/apiTest/common.ts | 2 +- frontend/src/models/apiTest/scenario.ts | 189 +++++++++++- frontend/src/utils/index.ts | 18 +- .../components/requestComposition/index.vue | 5 +- .../report/component/conditionStatus.vue | 20 +- .../scenario/components/assertion.vue | 7 +- .../api-test/scenario/components/baseInfo.vue | 40 +++ .../scenario/components/changeHistory.vue | 6 +- .../components/common/customApiDrawer.vue | 192 ++++++------ .../scenario/components/common/stepType.vue | 50 ---- .../components/common/stepType/stepType.vue | 63 ++++ .../components/common/stepType/utils.ts | 22 ++ .../api-test/scenario/components/config.ts | 128 ++++++-- .../scenario/components/executeHistory.vue | 6 +- .../api-test/scenario/components/params.vue | 7 +- .../api-test/scenario/components/prePost.vue | 16 +- .../components/scenarioModuleTree.vue | 2 +- .../scenario/components/scenarioTable.vue | 16 +- .../api-test/scenario/components/setting.vue | 35 +-- .../step/createAction/createStepActions.vue | 61 ++-- .../createAction/stepInsertStepTrigger.vue | 24 +- .../step/createAction/useCreateActions.ts | 98 +++---- .../scenario/components/step/index.vue | 35 +-- .../stepNodeComposition/conditionContent.vue | 33 +-- .../step/stepNodeComposition/loopContent.vue | 121 ++++---- .../step/stepNodeComposition/quoteContent.vue | 44 ++- .../stepNodeComposition/waitTimeContent.vue | 2 +- .../scenario/components/step/stepTree.vue | 276 +++++++++--------- .../views/api-test/scenario/create/index.vue | 23 +- .../views/api-test/scenario/detail/index.vue | 108 ++++--- .../src/views/api-test/scenario/index.vue | 125 +++++--- .../views/api-test/scenario/locale/zh-CN.ts | 10 +- .../src/views/api-test/scenario/recycle.vue | 2 +- 39 files changed, 1111 insertions(+), 747 deletions(-) create mode 100644 frontend/src/views/api-test/scenario/components/baseInfo.vue delete mode 100644 frontend/src/views/api-test/scenario/components/common/stepType.vue create mode 100644 frontend/src/views/api-test/scenario/components/common/stepType/stepType.vue create mode 100644 frontend/src/views/api-test/scenario/components/common/stepType/utils.ts diff --git a/frontend/src/api/modules/api-test/scenario.ts b/frontend/src/api/modules/api-test/scenario.ts index b8f2a250f7..bb2c16a0c0 100644 --- a/frontend/src/api/modules/api-test/scenario.ts +++ b/frontend/src/api/modules/api-test/scenario.ts @@ -1,6 +1,7 @@ import MSR from '@/api/http/index'; import { AddModuleUrl, + AddScenarioUrl, BatchCopyScenarioUrl, BatchDeleteScenarioUrl, BatchEditScenarioUrl, @@ -13,6 +14,7 @@ import { ExecuteHistoryUrl, GetModuleCountUrl, GetModuleTreeUrl, + GetScenarioUrl, GetTrashModuleCountUrl, GetTrashModuleTreeUrl, MoveModuleUrl, @@ -36,6 +38,8 @@ import { ApiScenarioUpdateDTO, ExecuteHistoryItem, ExecutePageParams, + Scenario, + ScenarioDetail, ScenarioHistoryItem, ScenarioHistoryPageParams, } from '@/models/apiTest/scenario'; @@ -180,3 +184,13 @@ export function batchDeleteScenario(data: { }) { return MSR.post({ url: BatchDeleteScenarioUrl, data }); } + +// 添加场景 +export function addScenario(params: Scenario) { + return MSR.post({ url: AddScenarioUrl, params }); +} + +// 获取场景详情 +export function getScenarioDetail(id: string) { + return MSR.get({ url: GetScenarioUrl, params: id }); +} diff --git a/frontend/src/api/requrls/api-test/scenario.ts b/frontend/src/api/requrls/api-test/scenario.ts index f9f17f6bae..ae35eaf6f3 100644 --- a/frontend/src/api/requrls/api-test/scenario.ts +++ b/frontend/src/api/requrls/api-test/scenario.ts @@ -5,6 +5,8 @@ export const GetModuleCountUrl = '/api/scenario/module/count'; // 获取模块 export const AddModuleUrl = '/api/scenario/module/add'; // 添加模块 export const DeleteModuleUrl = '/api/scenario/module/delete'; // 删除模块 export const ScenarioPageUrl = '/api/scenario/page'; // 接口场景列表 +export const AddScenarioUrl = '/api/scenario/add'; // 添加接口场景 +export const GetScenarioUrl = '/api/scenario/get'; // 获取接口场景详情 export const UpdateScenarioUrl = '/api/scenario/update'; // 更新接口场景 export const RecycleScenarioUrl = '/api/scenario/delete-to-gc'; // 删除接口场景 export const BatchRecycleScenarioUrl = '/api/scenario/batch-operation/delete-gc'; // 批量删除接口场景 diff --git a/frontend/src/components/business/ms-assertion/index.vue b/frontend/src/components/business/ms-assertion/index.vue index 7517453773..06cb13ef4c 100644 --- a/frontend/src/components/business/ms-assertion/index.vue +++ b/frontend/src/components/business/ms-assertion/index.vue @@ -146,8 +146,8 @@ import { useI18n } from '@/hooks/useI18n'; - import { ExecuteAssertionConfig, ExecuteConditionProcessor } from '@/models/apiTest/common'; - import { RequestConditionScriptLanguage, ResponseAssertionType, ResponseBodyAssertionType } from '@/enums/apiEnum'; + import { ExecuteAssertionConfig } from '@/models/apiTest/common'; + import { ResponseAssertionType, ResponseBodyAssertionType } from '@/enums/apiEnum'; import { ExecuteAssertion, MsAssertionItem } from './type'; @@ -175,7 +175,6 @@ const innerConfig = useVModel(props, 'assertionConfig', emit); - const activeIds = ref(''); // Item点击的key const activeKey = ref(''); // 展示的value diff --git a/frontend/src/components/pure/ms-drawer/index.vue b/frontend/src/components/pure/ms-drawer/index.vue index 79b95570aa..290b4e913a 100644 --- a/frontend/src/components/pure/ms-drawer/index.vue +++ b/frontend/src/components/pure/ms-drawer/index.vue @@ -330,7 +330,7 @@ .handle { @apply absolute left-0 top-0 flex h-full items-center; - z-index: 1; + z-index: 10; width: 8px; background-color: var(--color-neutral-3); cursor: col-resize; diff --git a/frontend/src/components/pure/ms-table/select-all.vue b/frontend/src/components/pure/ms-table/select-all.vue index cc1a021f01..96e24a7be3 100644 --- a/frontend/src/components/pure/ms-table/select-all.vue +++ b/frontend/src/components/pure/ms-table/select-all.vue @@ -52,7 +52,7 @@ const checked = computed({ get: () => { - return props.selectedKeys.size === props.total; + return props.selectedKeys.size > 0 && props.selectedKeys.size === props.total; }, set: (value) => { return value; diff --git a/frontend/src/enums/apiEnum.ts b/frontend/src/enums/apiEnum.ts index d4537f8b22..e290d93049 100644 --- a/frontend/src/enums/apiEnum.ts +++ b/frontend/src/enums/apiEnum.ts @@ -231,6 +231,11 @@ export enum ScenarioCreateComposition { // 接口场景详情组成部分 export enum ScenarioDetailComposition { BASE_INFO = 'BASE_INFO', + STEP = 'STEP', + PARAMS = 'PARAMS', + PRE_POST = 'PRE_POST', + ASSERTION = 'ASSERTION', + SETTING = 'SETTING', EXECUTE_HISTORY = 'EXECUTE_HISTORY', CHANGE_HISTORY = 'CHANGE_HISTORY', DEPENDENCY = 'DEPENDENCY', @@ -244,18 +249,6 @@ export enum ScenarioExecuteStatus { } // 场景步骤类型 export enum ScenarioStepType { - QUOTE_API = 'QUOTE_API', - COPY_API = 'COPY_API', - QUOTE_CASE = 'QUOTE_CASE', - COPY_CASE = 'COPY_CASE', - QUOTE_SCENARIO = 'QUOTE_SCENARIO', - COPY_SCENARIO = 'COPY_SCENARIO', - WAIT_TIME = 'WAIT_TIME', - LOOP_CONTROL = 'LOOP_CONTROL', - CONDITION_CONTROL = 'CONDITION_CONTROL', - ONLY_ONCE_CONTROL = 'ONLY_ONCE_CONTROL', - SCRIPT_OPERATION = 'SCRIPT_OPERATION', - CUSTOM_API = 'CUSTOM_API', API_CASE = 'API_CASE', // 接口用例 LOOP_CONTROLLER = 'LOOP_CONTROLLER', // 循环控制器 API = 'API', // 接口定义 @@ -263,6 +256,14 @@ export enum ScenarioStepType { API_SCENARIO = ' API_SCENARIO', // 场景 IF_CONTROLLER = 'IF_CONTROLLER', // 条件控制器 ONCE_ONLY_CONTROLLER = 'ONCE_ONLY_CONTROLLER', // 一次控制器 + CONSTANT_TIMER = 'CONSTANT_TIMER', // 等待控制器 + SCRIPT = 'SCRIPT', // 脚本 +} +export enum ScenarioStepRefType { + COPY = 'COPY', // 复制 + DIRECT = 'DIRECT', // 在场景中直接创建的步骤 例如 自定义请求,逻辑控制器 + PARTIAL_REF = 'PARTIAL_REF', // 部分引用 + REF = 'REF', // 完全引用 } // 场景添加步骤操作类型 export enum ScenarioAddStepActionType { @@ -293,3 +294,25 @@ export enum ChangeHistoryStatusFilters { IMPORT = 'IMPORT', DELETE = 'DELETE', } +// 场景步骤-循环控制器类型 +export enum ScenarioStepLoopTypeEnum { + WHILE = 'WHILE', + LOOP_COUNT = 'LOOP_COUNT', + FOREACH = 'FOREACH', +} +// 场景步骤-循环控制器-while循环类型 +export enum WhileConditionType { + CONDITION = 'CONDITION', + SCRIPT = 'SCRIPT', +} +export enum ScenarioStepPolymorphicName { + COMMON_SCRIPT = 'MsCommentScriptElement', + IF_CONTROLLER = 'MsIfController', + LOOP_CONTROLLER = 'MsLoopController', + ONLY_ONCE = 'MsOnceOnlyController', + TIME_CONTROLLER = 'MsConstantTimerController', +} +export enum ScenarioFailureStrategy { + CONTINUE = 'CONTINUE', + STOP = 'STOP', +} diff --git a/frontend/src/models/apiTest/common.ts b/frontend/src/models/apiTest/common.ts index 1a71bf6ea3..c916ddd0c1 100644 --- a/frontend/src/models/apiTest/common.ts +++ b/frontend/src/models/apiTest/common.ts @@ -314,7 +314,7 @@ export type ExecuteAssertionItem = ResponseAssertionCommon & ResponseVariableAssertion; // 执行请求-断言配置 export interface ExecuteAssertionConfig { - enableGlobal: boolean; // 是否启用全局断言 + enableGlobal?: boolean; // 是否启用全局断言,部分地方没有 assertions: ExecuteAssertionItem[]; } // 执行请求-共用配置子项 diff --git a/frontend/src/models/apiTest/scenario.ts b/frontend/src/models/apiTest/scenario.ts index 3e2ab3d688..fa73ab81bd 100644 --- a/frontend/src/models/apiTest/scenario.ts +++ b/frontend/src/models/apiTest/scenario.ts @@ -1,11 +1,28 @@ import type { CaseLevel } from '@/components/business/ms-case-associate/types'; -import { ScenarioStepInfo } from '@/views/api-test/scenario/components/step/index.vue'; import { ApiDefinitionCustomField, ApiRunModeRequest } from '@/models/apiTest/management'; -import { ApiScenarioStatus, RequestComposition, RequestDefinitionStatus } from '@/enums/apiEnum'; +import { + ApiScenarioStatus, + RequestAssertionCondition, + RequestComposition, + RequestDefinitionStatus, + RequestMethods, + ScenarioExecuteStatus, + ScenarioFailureStrategy, + ScenarioStepLoopTypeEnum, + ScenarioStepPolymorphicName, + ScenarioStepRefType, + ScenarioStepType, + WhileConditionType, +} from '@/enums/apiEnum'; import { BatchApiParams, TableQueryParams } from '../common'; -import { ExecuteApiRequestFullParams, ResponseDefinition } from './common'; +import { + ExecuteApiRequestFullParams, + ExecuteAssertionItem, + ExecuteConditionConfig, + ResponseDefinition, +} from './common'; // 场景-更新模块参数 export interface ApiScenarioModuleUpdateParams { @@ -27,11 +44,11 @@ export interface ApiScenarioGetModuleParams { // 场景修改参数 export interface ApiScenarioUpdateDTO { - id: string; + id: string | number; name?: string; priority?: string; status?: ApiScenarioStatus; - moduleId?: string; + moduleId?: string | number; description?: string; tags?: string[]; grouped?: boolean; @@ -196,25 +213,171 @@ export type CustomApiStep = ExecuteApiRequestFullParams & { useEnv: string; }; // 场景步骤-循环控制器类型 -export type ScenarioStepLoopType = 'num' | 'while' | 'forEach'; -// 场景步骤-循环控制器-循环类型 -export type ScenarioStepLoopWhileType = 'condition' | 'expression'; +export type ScenarioStepLoopType = ScenarioStepLoopTypeEnum; // 场景步骤-步骤插入类型 export type CreateStepAction = 'inside' | 'before' | 'after'; -// 场景步骤 -export interface Scenario { +export interface OtherConfig { + enableGlobalCookie: boolean; + enableCookieShare: boolean; + stepWaitTime: number; + enableStepWait: boolean; + failureStrategy: ScenarioFailureStrategy; +} +export interface AssertionConfig { + assertions: ExecuteAssertionItem[]; +} +export interface CsvVariable { id: string; + fileId: string; + scenarioId: string; + name: string; + fileName: string; + scope: string; + enable: boolean; + association: boolean; + encoding: string; + random: boolean; + variableNames: string; + ignoreFirstLine: boolean; + delimiter: string; + allowQuotedData: boolean; + recycleOnEof: boolean; + stopThreadOnEof: boolean; +} +export interface CommonVariable { + id: string | number; + key: string; + paramType: string; + value: string; + enable: boolean; + description: string; + tags: string[]; +} +export interface Variable { + commonVariables: CommonVariable[]; + csvVariables: CsvVariable[]; +} +export interface ScenarioConfig { + variable: Variable; + preProcessorConfig: ExecuteConditionConfig; + postProcessorConfig: ExecuteConditionConfig; + assertionConfig: AssertionConfig; + otherConfig: OtherConfig; +} +export interface ForEachController { + loopTime: number; // 循环间隔时间 + value: string; // 变量值 + variable: string; // 变量名 +} +export interface CountController { + loops: number; // 循环次数 +} +export interface WhileScript { + scriptValue: string; // 脚本值 +} +export interface WhileVariable { + condition: RequestAssertionCondition; // 条件操作符 + value: string; // 变量值 + variable: string; // 变量名 +} +export interface WhileController { + conditionType: WhileConditionType; // 条件类型 + timeout: number; // 超时时间 + msWhileScript: WhileScript; // 脚本 + msWhileVariable: WhileVariable; // 变量 +} +export type ExtendedScenarioStepPolymorphicName = ScenarioStepPolymorphicName | string; +// 场景步骤详情公共部分 +export interface StepDetailsCommon { + id: string | number; + copyFromStepId?: string; // 如果步骤是复制的,这个字段是复制的步骤id + name: string; + enable: boolean; + polymorphicName: ExtendedScenarioStepPolymorphicName; // 多态名称,用于后台区分使用的是哪个组件 +} +// 自定义请求 +export interface CustomApiStepDetail extends StepDetailsCommon { + customizeRequest: boolean; // 是否自定义请求 + customizeRequestEnvEnable: boolean; // 是否启用环境 +} +// 条件控制器 +export interface ConditionStepDetail extends StepDetailsCommon { + value: string; // 变量值 + variable: string; // 变量名 + condition: RequestAssertionCondition; // 条件操作符 +} +// 循环控制器 +export interface LoopStepDetail extends StepDetailsCommon { + loopType: ScenarioStepLoopType; + forEachController: ForEachController; + msCountController: CountController; + whileController: WhileController; +} +export type ScenarioStepDetail = Partial; +export interface ScenarioStepItem { + id: string | number; + sort: number; + name: string; + executeStatus?: ScenarioExecuteStatus; + enable: boolean; // 是否启用 + resourceId?: string; // 详情或者引用的类型才有 + resourceNum?: string; // 详情或者引用的类型才有 + stepType: ScenarioStepType; + refType: ScenarioStepRefType; + config?: ScenarioStepDetail; // 对应场景里stepDetails里的详情信息,只有逻辑控制器需要 + csvFileIds?: string[]; + projectId?: string; + versionId?: string; + children?: ScenarioStepItem[]; + // 页面渲染以及交互需要字段 + checked?: boolean; // 是否选中 + expanded?: boolean; // 是否展开 + createActionsVisible?: boolean; // 是否展示创建步骤下拉 + parent?: ScenarioStepItem; // 父级节点,第一层的父级节点为undefined + resourceName?: string; // 引用复制接口、用例、场景时的源资源名称 + method?: RequestMethods; +} +// 场景 +export interface Scenario { + id?: string | number; + num?: number; name: string; moduleId: string | number; - stepInfo: ScenarioStepInfo; priority: CaseLevel; - status: RequestDefinitionStatus; + status: ApiScenarioStatus; tags: string[]; - params: Record[]; + projectId: string; + description: string; + grouped?: boolean; + environmentId?: string; + scenarioConfig: ScenarioConfig; + steps: ScenarioStepItem[]; + stepDetails: Record; + follow?: boolean; + uploadFileIds: string[]; + linkFileIds: string[]; // 前端渲染字段 label: string; closable: boolean; isNew: boolean; unSaved: boolean; executeLoading: boolean; // 执行loading + executeTime?: string | number; // 执行时间 + executeSuccessCount?: number; // 执行成功数量 + executeFailCount?: number; // 执行失败数量 +} +export interface ScenarioDetail extends Scenario { + stepTotal: number; + requestPassRate: string; + lastReportStatus?: string; + lastReportId?: string; + deleted: boolean; + versionId: string; + refId: string; + latest: boolean; + modulePath: string; + createUser: string; + createTime: number; + updateTime: number; + updateUser: string; } diff --git a/frontend/src/utils/index.ts b/frontend/src/utils/index.ts index 4ec756aeeb..0bafd74b20 100644 --- a/frontend/src/utils/index.ts +++ b/frontend/src/utils/index.ts @@ -224,7 +224,7 @@ export function mapTree( return _tree .map((node: TreeNode, i: number) => { const fullPath = node.path ? `${_parentPath}/${node.path}`.replace(/\/+/g, '/') : ''; - node.order = i + 1; // order从 1 开始 + node.sort = i + 1; // order从 1 开始 node.parent = _parent || undefined; // 没有父节点说明是树的第一层 const newNode = typeof customNodeFn === 'function' ? customNodeFn(node, fullPath) : node; if (newNode) { @@ -382,19 +382,19 @@ export function insertNodes( // 插入节点数组 newNodes.forEach((newNode, index) => { newNode.parent = parent; - newNode.order = startOrder + index; + newNode.sort = startOrder + index; }); array.splice(startIndex, 0, ...newNodes); } else { // 插入单个节点 newNodes.parent = parent; - newNodes.order = startOrder; + newNodes.sort = startOrder; array.splice(startIndex, 0, newNodes); } - // 更新插入节点之后的节点的 order + // 更新插入节点之后的节点的 sort const newLength = Array.isArray(newNodes) ? newNodes.length : 1; for (let j = startIndex + newLength; j < array.length; j++) { - array[j].order += newLength; + array[j].sort += newLength; } } @@ -406,9 +406,9 @@ export function insertNodes( const parentChildren = parent ? parent.children || [] : treeArr; // 父节点没有 children 属性,说明是树的第一层,使用 treeArr const index = parentChildren.findIndex((item) => item[customKey] === node[customKey]); if (position === 'before') { - insertNewNodes(parentChildren, index, parent || node.parent, node.order); + insertNewNodes(parentChildren, index, parent || node.parent, node.sort); } else if (position === 'after') { - insertNewNodes(parentChildren, index + 1, parent || node.parent, node.order + 1); + insertNewNodes(parentChildren, index + 1, parent || node.parent, node.sort + 1); } else if (position === 'inside') { if (!node.children) { node.children = []; @@ -460,9 +460,9 @@ export function handleTreeDragDrop( if (index !== -1) { parentChildren.splice(index, 1); - // 更新删除节点后的节点的 order + // 更新删除节点后的节点的 sort for (let i = index; i < parentChildren.length; i++) { - parentChildren[i].order -= 1; + parentChildren[i].sort -= 1; } } diff --git a/frontend/src/views/api-test/components/requestComposition/index.vue b/frontend/src/views/api-test/components/requestComposition/index.vue index f2df8e59e4..99876b0e80 100644 --- a/frontend/src/views/api-test/components/requestComposition/index.vue +++ b/frontend/src/views/api-test/components/requestComposition/index.vue @@ -857,6 +857,7 @@ nextTick(() => { // 如果是没有缓存也不是编辑,则需要重置表单,因为 form-create 只有一个实例,已经被其他有数据的 tab 污染了,需要重置 fApi.value?.resetFields(); + isInitPluginForm.value = true; }); } } @@ -1136,7 +1137,9 @@ } reportId.value = getGenerateId(); requestVModel.value.reportId = reportId.value; // 存储报告ID - debugSocket(executeType); // 开启websocket + if (isExecute) { + debugSocket(executeType); // 开启websocket + } let requestName = ''; let requestModuleId = ''; let apiDefinitionParams: Record = {}; diff --git a/frontend/src/views/api-test/report/component/conditionStatus.vue b/frontend/src/views/api-test/report/component/conditionStatus.vue index 55f585d4dd..7474c20c3c 100644 --- a/frontend/src/views/api-test/report/component/conditionStatus.vue +++ b/frontend/src/views/api-test/report/component/conditionStatus.vue @@ -3,8 +3,6 @@ diff --git a/frontend/src/views/api-test/scenario/components/baseInfo.vue b/frontend/src/views/api-test/scenario/components/baseInfo.vue new file mode 100644 index 0000000000..144654c7a8 --- /dev/null +++ b/frontend/src/views/api-test/scenario/components/baseInfo.vue @@ -0,0 +1,40 @@ + + + + + diff --git a/frontend/src/views/api-test/scenario/components/changeHistory.vue b/frontend/src/views/api-test/scenario/components/changeHistory.vue index 90a1c03b27..a45c62a62a 100644 --- a/frontend/src/views/api-test/scenario/components/changeHistory.vue +++ b/frontend/src/views/api-test/scenario/components/changeHistory.vue @@ -1,6 +1,6 @@ - - {{ t('apiScenario.setting.step.rule.ignore') }} - {{ t('apiScenario.setting.step.rule.stop') }} + + {{ t('apiScenario.setting.step.rule.ignore') }} + {{ t('apiScenario.setting.step.rule.stop') }} @@ -70,21 +70,14 @@ diff --git a/frontend/src/views/api-test/scenario/components/step/createAction/createStepActions.vue b/frontend/src/views/api-test/scenario/components/step/createAction/createStepActions.vue index f122fa48f1..cba0113819 100644 --- a/frontend/src/views/api-test/scenario/components/step/createAction/createStepActions.vue +++ b/frontend/src/views/api-test/scenario/components/step/createAction/createStepActions.vue @@ -45,13 +45,13 @@ import { cloneDeep } from 'lodash-es'; import MsButton from '@/components/pure/ms-button/index.vue'; - import { ScenarioStepItem } from '../stepTree.vue'; import { useI18n } from '@/hooks/useI18n'; + import useAppStore from '@/store/modules/app'; import { findNodeByKey, getGenerateId } from '@/utils'; - import { CreateStepAction } from '@/models/apiTest/scenario'; - import { ScenarioAddStepActionType, ScenarioStepType } from '@/enums/apiEnum'; + import { CreateStepAction, ScenarioStepItem } from '@/models/apiTest/scenario'; + import { ScenarioAddStepActionType, ScenarioStepRefType, ScenarioStepType } from '@/enums/apiEnum'; import useCreateActions from './useCreateActions'; import { defaultStepItemCommon } from '@/views/api-test/scenario/components/config'; @@ -74,6 +74,7 @@ ); }>(); + const appStore = useAppStore(); const { t } = useI18n(); const visible = defineModel('visible', { @@ -101,9 +102,10 @@ if (step.value && props.createStepAction) { handleCreateStep( { - type: ScenarioStepType.LOOP_CONTROL, + stepType: ScenarioStepType.LOOP_CONTROLLER, name: t('apiScenario.loopControl'), - } as ScenarioStepItem, + projectId: appStore.currentProjectId, + }, step.value, steps.value, props.createStepAction, @@ -112,10 +114,12 @@ } else { steps.value.push({ ...cloneDeep(defaultStepItemCommon), - stepId: getGenerateId(), - order: steps.value.length + 1, - type: ScenarioStepType.LOOP_CONTROL, + id: getGenerateId(), + sort: steps.value.length + 1, + stepType: ScenarioStepType.LOOP_CONTROLLER, + refType: ScenarioStepRefType.DIRECT, name: t('apiScenario.loopControl'), + projectId: appStore.currentProjectId, }); } break; @@ -123,9 +127,10 @@ if (step.value && props.createStepAction) { handleCreateStep( { - type: ScenarioStepType.CONDITION_CONTROL, + stepType: ScenarioStepType.IF_CONTROLLER, name: t('apiScenario.conditionControl'), - } as ScenarioStepItem, + projectId: appStore.currentProjectId, + }, step.value, steps.value, props.createStepAction, @@ -134,10 +139,12 @@ } else { steps.value.push({ ...cloneDeep(defaultStepItemCommon), - stepId: getGenerateId(), - order: steps.value.length + 1, - type: ScenarioStepType.CONDITION_CONTROL, + id: getGenerateId(), + sort: steps.value.length + 1, + stepType: ScenarioStepType.IF_CONTROLLER, + refType: ScenarioStepRefType.DIRECT, name: t('apiScenario.conditionControl'), + projectId: appStore.currentProjectId, }); } break; @@ -145,9 +152,10 @@ if (step.value && props.createStepAction) { handleCreateStep( { - type: ScenarioStepType.ONLY_ONCE_CONTROL, + stepType: ScenarioStepType.ONCE_ONLY_CONTROLLER, name: t('apiScenario.onlyOnceControl'), - } as ScenarioStepItem, + projectId: appStore.currentProjectId, + }, step.value, steps.value, props.createStepAction, @@ -156,10 +164,12 @@ } else { steps.value.push({ ...cloneDeep(defaultStepItemCommon), - stepId: getGenerateId(), - order: steps.value.length + 1, - type: ScenarioStepType.ONLY_ONCE_CONTROL, + id: getGenerateId(), + sort: steps.value.length + 1, + stepType: ScenarioStepType.ONCE_ONLY_CONTROLLER, + refType: ScenarioStepRefType.DIRECT, name: t('apiScenario.onlyOnceControl'), + projectId: appStore.currentProjectId, }); } break; @@ -167,9 +177,10 @@ if (step.value && props.createStepAction) { handleCreateStep( { - type: ScenarioStepType.WAIT_TIME, + stepType: ScenarioStepType.CONSTANT_TIMER, name: t('apiScenario.waitTime'), - } as ScenarioStepItem, + projectId: appStore.currentProjectId, + }, step.value, steps.value, props.createStepAction, @@ -178,10 +189,12 @@ } else { steps.value.push({ ...cloneDeep(defaultStepItemCommon), - stepId: getGenerateId(), - order: steps.value.length + 1, - type: ScenarioStepType.WAIT_TIME, + id: getGenerateId(), + sort: steps.value.length + 1, + stepType: ScenarioStepType.CONSTANT_TIMER, + refType: ScenarioStepRefType.DIRECT, name: t('apiScenario.waitTime'), + projectId: appStore.currentProjectId, }); } break; @@ -189,7 +202,7 @@ case ScenarioAddStepActionType.CUSTOM_API: case ScenarioAddStepActionType.SCRIPT_OPERATION: if (step.value) { - const realStep = findNodeByKey(steps.value, step.value.stepId, 'stepId'); + const realStep = findNodeByKey(steps.value, step.value.id, 'id'); if (realStep) { emit('otherCreate', val, realStep as ScenarioStepItem); } diff --git a/frontend/src/views/api-test/scenario/components/step/createAction/stepInsertStepTrigger.vue b/frontend/src/views/api-test/scenario/components/step/createAction/stepInsertStepTrigger.vue index c1bfff4ed7..0442505fdf 100644 --- a/frontend/src/views/api-test/scenario/components/step/createAction/stepInsertStepTrigger.vue +++ b/frontend/src/views/api-test/scenario/components/step/createAction/stepInsertStepTrigger.vue @@ -6,7 +6,7 @@ position="br" @popup-visible-change="handleActionTriggerChange" > - + -