diff --git a/components/canvas/CanvasChatPanel.tsx b/components/canvas/CanvasChatPanel.tsx index 202ca45..8d62c87 100644 --- a/components/canvas/CanvasChatPanel.tsx +++ b/components/canvas/CanvasChatPanel.tsx @@ -268,13 +268,33 @@ export function CanvasChatPanel({ chatId, initialMessages = [], onClose, onOpenF const parts: any[] = []; // 添加文件部分(作为 file 类型的 part) - attachments.forEach(a => { + // 同时将用户上传的图片添加到画布 + attachments.forEach((a, index) => { parts.push({ type: "file" as const, mediaType: a.contentType, name: a.name, url: a.url, }); + + // 将用户上传的图片添加到画布 + if (a.contentType?.startsWith('image/')) { + const existingNodes = nodes.length; + const x = 100 + ((existingNodes + index) % 4) * 320; + const y = 100 + Math.floor((existingNodes + index) / 4) * 320; + + addNode({ + type: 'image', + position: { x, y }, + size: { width: 300, height: 300 }, + data: { + src: a.url, + status: 'completed', + prompt: '用户上传', + }, + connections: [], + }); + } }); // 添加文本部分 @@ -289,9 +309,13 @@ export function CanvasChatPanel({ chatId, initialMessages = [], onClose, onOpenF parts: parts, }); + if (attachments.length > 0) { + toast.success(`已将 ${attachments.length} 张图片添加到画布`); + } + setInput(""); setAttachments([]); - }, [input, attachments, selectedModelId, sendMessage]); + }, [input, attachments, selectedModelId, sendMessage, addNode, nodes.length]); // 处理文件选择 const handleFileSelect = async (e: React.ChangeEvent) => {