Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug Report]: 新创建的dynamic-group中的孩子节点会被之前创建的dynamic-group节点影响 #2052

Open
xiaozhaoCcz opened this issue Jan 20, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@xiaozhaoCcz
Copy link

xiaozhaoCcz commented Jan 20, 2025

发生了什么?

Image
Image

function confirmDialog() {
  const _node = lf.value.getNodeModelById(jobNodeEditId.value);
  const _jobInfo = jobInfoList.value.find(
    (e: any) => e.id === jobSelectId.value
  ) as any;

  // const position =
  const nodeInfo = {
    width: _node.width,
    height: _node.height,
    x: _node.x,
    y: _node.y,
  };

  console.log(nodeInfo);

  const graphModel = lf.value.graphModel;
  if (_jobInfo.jobType === 2) {
    //新增任务组
    let data = {} as any;
    await JobInfoAPI.getJobCompose(jobSelectId.value, 1).then(
      (res) => (data = res)
    );
    // 后端返回的代码
    const jobNode = data.jobNode;
    const newNodes = data.nodes;
    const newEdges = data.edges;
    newNodes.push(jobNode);

    // await addJobNodes(newNodes, graphModel, newEdges);

    newNodes.forEach((node) => {
      // 直接新增节点,dynamic-group中的child节点是空的???
      graphModel.addNode(generateNode(node));
    });
    // 重新设置任务组的孩子节点
    newNodes.forEach((n) => {
      const node = lf.value.getNodeModelById(n.id);
      if (n.nodeType === "dynamic-group") {
        JSON.parse(n.children).forEach((id: any) => node.addChild(id));
      }
    });
    // 添加新边
    newEdges.forEach((e) => {
      graphModel.addEdge(generateEdge(e));
    });

    const pNode = lf.value.getNodeModelById(jobNode.id);
    graphModel.moveNode2Coordinate(
      [jobNode.id],
      nodeInfo.x - nodeInfo.width / 2 + pNode.width / 2,
      nodeInfo.y - nodeInfo.height / 2 + pNode.height / 2
    );
    graphModel.deleteNode(_node.id);
  } else {
    _node.setProperty("jobId", jobSelectId.value);
    _node.updateText(_jobInfo.jobDesc);
  }
  cancelDialog();
}
function generateNode(node: any) {
  return {
    id: node.id,
    text: node.jobName,
    type: node.nodeType,
    x: node.nodePositionX,
    y: node.nodePositionY,
    properties: JSON.parse(node.properties),
    children: node.children != null ? JSON.parse(node.children) : [],
  };
}

function generateEdge(edge: any) {
  return {
    sourceNodeId: edge.fromNodeId,
    targetNodeId: edge.endNodeId,
    type: "polyline",
  };
}

logicflow/core版本

2.0.10

logicflow/extension版本

2.0.14

logicflow/engine版本

No response

浏览器&环境

No response

@xiaozhaoCcz xiaozhaoCcz added the bug Something isn't working label Jan 20, 2025
@ZivvW
Copy link
Contributor

ZivvW commented Jan 21, 2025

lf.addelements 替换 graphModel.addNode 试试呢,不行的话最好弄个完整的可复现示例出来

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants