From cf972e68397b053baad757d57ad1402296b3a245 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=A6=82=E5=A8=81?= Date: Thu, 18 Sep 2025 17:00:00 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=99=90=E5=88=B6=E5=8D=95=E4=B8=AA?= =?UTF-8?q?=E6=B5=81=E5=90=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/main.py | 5 +++-- backend/app/tool/__init__.py | 16 ++++++++++++++++ frontend/src/pages/Flow/Detail.jsx | 10 +++++++--- .../src/pages/Flow/components/CustomNode.jsx | 7 ++++--- .../src/pages/Flow/components/OnlyOneHandle.jsx | 17 +++++++++++++++++ 5 files changed, 47 insertions(+), 8 deletions(-) create mode 100644 backend/app/tool/__init__.py create mode 100644 frontend/src/pages/Flow/components/OnlyOneHandle.jsx diff --git a/backend/app/main.py b/backend/app/main.py index d63255b..8af66e4 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -5,6 +5,7 @@ import os import uvicorn import uuid import time +from tool import format_content_uuid import models.db as DB import nodes as F from tortoise.transactions import in_transaction @@ -298,11 +299,11 @@ def create_app(): if not work_content: work_content = DB.WorkContent( user_id=work.creator_id, - content=body.content, + content=[], is_deleted=0, work_id=work.id, ) - work_content.content = body.content + work_content.content = format_content_uuid(body.content) work_content.update_time = datetime.datetime.now() await work_content.save() return BaseResponse() diff --git a/backend/app/tool/__init__.py b/backend/app/tool/__init__.py new file mode 100644 index 0000000..0ea1b0e --- /dev/null +++ b/backend/app/tool/__init__.py @@ -0,0 +1,16 @@ +from uuid import uuid4 + + +def format_content_uuid(content:list[dict]): + """替换所有由前端生成的 uuid 字段""" + uuid_mapping = {k.get('uuid', ''): uuid4().hex for k in list(filter(lambda x: "temp_" in x.get("uuid", "") , content))} + for x in content: + edge = x.get('edge') + x_uuid = x.get('uuid', '') + x["uuid"] = uuid_mapping.get(x_uuid) or x_uuid + if edge: + source_uuid = edge.get('source', '') + target_uuid = edge.get('target', '') + edge["source"] = uuid_mapping.get(source_uuid) or source_uuid + edge["target"] = uuid_mapping.get(target_uuid) or target_uuid + return content diff --git a/frontend/src/pages/Flow/Detail.jsx b/frontend/src/pages/Flow/Detail.jsx index aaf334f..79e9aa9 100644 --- a/frontend/src/pages/Flow/Detail.jsx +++ b/frontend/src/pages/Flow/Detail.jsx @@ -90,6 +90,7 @@ const FlowDetail = () => { sourcePosition: 'right', targetPosition: 'left', type: type, + detail: { title: type} }, ]); } @@ -142,11 +143,13 @@ const FlowDetail = () => { onOk: async () => { const content = []; nodes.forEach(e => { - const edge = edges.find(obj => obj.target === e.id); + const edge = edges.find(obj => obj.source === e.id); content.push({ ...e.detail, position: e.position, - edge: edge ? { source: edge.source, target: edge.target } : undefined + edge: edge ? { source: edge.source, target: edge.target } : undefined, + type: e.type, + uuid: e.id }) }); const res = await flowUpdate(record.uuid, { @@ -154,7 +157,8 @@ const FlowDetail = () => { ...formRef.current.getFieldsValue() }) if (res?.success) { - message.success("保持成功"); + message.success("保存成功"); + loadDetail(); } else { message.error(res.message); } diff --git a/frontend/src/pages/Flow/components/CustomNode.jsx b/frontend/src/pages/Flow/components/CustomNode.jsx index 7c3a60a..2abf647 100644 --- a/frontend/src/pages/Flow/components/CustomNode.jsx +++ b/frontend/src/pages/Flow/components/CustomNode.jsx @@ -1,6 +1,7 @@ import React, { memo } from 'react'; -import { Handle, Position } from '@xyflow/react'; +import { Position } from '@xyflow/react'; import './CustomNode.css'; +import OnlyOneHandle from './OnlyOneHandle'; const CustomNode = memo(({ data: { style, position, ...data}, isConnectable }) => { return ( @@ -8,8 +9,8 @@ const CustomNode = memo(({ data: { style, position, ...data}, isConnectable }) =
{data.label}
- {position?.includes('left') && } - {position?.includes('right') && } + {position?.includes('left') && } + {position?.includes('right') && } ); }) diff --git a/frontend/src/pages/Flow/components/OnlyOneHandle.jsx b/frontend/src/pages/Flow/components/OnlyOneHandle.jsx new file mode 100644 index 0000000..d305210 --- /dev/null +++ b/frontend/src/pages/Flow/components/OnlyOneHandle.jsx @@ -0,0 +1,17 @@ +import React from 'react'; +import { Handle, useNodeConnections } from '@xyflow/react'; + +const OnlyOneHandle = (props) => { + const connections = useNodeConnections({ + handleType: props.type, + }); + + return ( + + ); +}; + +export default OnlyOneHandle;