Compare commits

...

2 Commits

Author SHA1 Message Date
李如威 63b1f0f10b feat: 装备修改保存 2025-09-22 11:21:57 +08:00
李如威 cf972e6839 feat: 限制单个流向 2025-09-18 17:00:00 +08:00
5 changed files with 57 additions and 8 deletions

View File

@ -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
@ -202,10 +203,20 @@ def create_app():
nodes = []
params = {}
status = {}
uuids = []
first_uuid = next((x['uuid'] for x in work_content.content if x.get("type") == "first"), "")
if not first_uuid:
work_log.status = DB.WorkLogsStatus.FAILED
await work_log.save()
app.state.tasks.pop(task_id, None)
for x in work_content.content:
node_id = x["uuid"]
node_type = x["type"]
node_info = x["detail"]
node_edge = x.get("edge")
params[node_id] = node_info
status[node_id] = "wait"
node_class_map = {
@ -298,11 +309,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()

View File

@ -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

View File

@ -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);
}

View File

@ -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 }) =
<div >
{data.label}
</div>
{position?.includes('left') && <Handle type="target" position={Position.Left} isConnectable={isConnectable} />}
{position?.includes('right') && <Handle type="source" position={Position.Right} isConnectable={isConnectable} />}
{position?.includes('left') && <OnlyOneHandle connectionCount={1} type="target" position={Position.Left} isConnectable={isConnectable} />}
{position?.includes('right') && <OnlyOneHandle connectionCount={1} type="source" position={Position.Right} isConnectable={isConnectable} />}
</div>
);
})

View File

@ -0,0 +1,17 @@
import React from 'react';
import { Handle, useNodeConnections } from '@xyflow/react';
const OnlyOneHandle = (props) => {
const connections = useNodeConnections({
handleType: props.type,
});
return (
<Handle
{...props}
isConnectable={connections.length < props.connectionCount}
/>
);
};
export default OnlyOneHandle;