fix(接口场景): 场景步骤问题修复

This commit is contained in:
baiqi 2024-07-18 15:00:12 +08:00 committed by 刘瑞斌
parent 0b59e73899
commit 66ee2c3d33
5 changed files with 21 additions and 7 deletions

View File

@ -126,6 +126,7 @@
actionOnNodeClick?: 'expand'; //
nodeHighlightClass?: string; //
hideSwitcher?: boolean; //
handleDrop?: boolean; //
titleTooltipPosition?:
| 'top'
| 'tl'
@ -333,6 +334,10 @@
dropNode: MsTreeNodeData; //
dropPosition: number; // -1 1 0
}) {
if (props.handleDrop) {
emit('drop', data.value, dragNode, dropNode, dropPosition);
return;
}
loop(data.value, dragNode.key, (item, index, arr) => {
arr.splice(index, 1);
});

View File

@ -969,7 +969,7 @@
function handleClose() {
if (isReplace.value) {
isReplace.value = false;
} else if (!requestVModel.value.isNew) {
} else {
emit('applyStep', cloneDeep(makeRequestParams()) as RequestParam);
}
}

View File

@ -26,6 +26,7 @@
block-node
draggable
hide-switcher
handle-drop
@select="(selectedKeys, node) => handleStepSelect(node as ScenarioStepItem)"
@expand="handleStepExpand"
@more-actions-close="() => setFocusNodeKey('')"
@ -910,7 +911,11 @@
const { isQuoteScenario } = getStepType(node as ScenarioStepItem);
if (stepDetail) {
//
stepDetails.value[id] = cloneDeep(stepDetail);
stepDetails.value[id] = cloneDeep({
...stepDetail,
stepId: id,
uniqueId: id,
});
}
if (stepFileParam) {
//

View File

@ -195,11 +195,13 @@ export default function useStepOperation({
}
loading.value = true;
const offspringIds: string[] = [];
mapTree(cloneDeep(dragNode.children || []), (e) => {
const realStep = findNodeByKey<ScenarioStepItem>(steps.value, dragNode.uniqueId, 'uniqueId');
if (!realStep) return;
mapTree(cloneDeep(realStep.children || []), (e) => {
offspringIds.push(e.uniqueId);
return e;
});
const stepIdAndOffspringIds = [dragNode.uniqueId, ...offspringIds];
const stepIdAndOffspringIds = [realStep.uniqueId, ...offspringIds];
if (dropPosition === 0) {
// 拖拽到节点内
if (selectedKeys.value.includes(dropNode.uniqueId)) {
@ -209,7 +211,7 @@ export default function useStepOperation({
} else if (dropNode.parent && selectedKeys.value.includes(dropNode.parent.uniqueId)) {
// 释放位置的节点的父节点已选中,则需要把拖动的节点及其子孙节点也需要选中(因为父级选中子级也会展示选中状态)
selectedKeys.value = selectedKeys.value.concat(stepIdAndOffspringIds);
} else if (dragNode.parent && selectedKeys.value.includes(dragNode.parent.uniqueId)) {
} else if (realStep.parent && selectedKeys.value.includes(realStep.parent.uniqueId)) {
// 如果被拖动的节点的父节点在选中的节点中,则需要把被拖动的节点及其子孙节点从选中的节点中移除
selectedKeys.value = selectedKeys.value.filter((e) => {
for (let i = 0; i < stepIdAndOffspringIds.length; i++) {
@ -222,7 +224,7 @@ export default function useStepOperation({
return true;
});
}
const dragResult = handleTreeDragDrop(steps.value, dragNode, dropNode, dropPosition, 'uniqueId');
const dragResult = handleTreeDragDrop(steps.value, realStep, dropNode, dropPosition, 'uniqueId');
if (dragResult) {
Message.success(t('common.moveSuccess'));
scenario.value.unSaved = true;

View File

@ -1,3 +1,5 @@
import { traverseTree } from '@/utils';
import { RequestResult } from '@/models/apiTest/common';
import { type Scenario, type ScenarioStepDetails, ScenarioStepItem } from '@/models/apiTest/scenario';
import { ScenarioExecuteStatus, ScenarioStepType } from '@/enums/apiEnum';
@ -123,7 +125,7 @@ export function getScenarioFileParams(scenario: Scenario) {
*/
export function getStepDetails(steps: ScenarioStepItem[], details: Record<string, ScenarioStepDetails>) {
const newStepDetails: Record<string, ScenarioStepDetails> = {};
steps.forEach((step) => {
traverseTree(steps, (step) => {
const currentDetail = details[step.id] as RequestParam;
if (
currentDetail &&