diff --git a/components/canvas/CanvasChatPanel.tsx b/components/canvas/CanvasChatPanel.tsx index 72a7935..f65f940 100644 --- a/components/canvas/CanvasChatPanel.tsx +++ b/components/canvas/CanvasChatPanel.tsx @@ -856,6 +856,9 @@ export function CanvasChatPanel({ chatId, initialMessages = [], onClose, onOpenF if (!files) return; let firstImageUrl: string | null = null; + // 记录本次上传开始时的节点数量,用于计算新图片位置 + const baseNodeCount = nodes.length; + let uploadIndex = 0; for (const file of Array.from(files)) { if (!file.type.startsWith('image/')) { @@ -907,10 +910,12 @@ export function CanvasChatPanel({ chatId, initialMessages = [], onClose, onOpenF // 获取图片原始尺寸后添加到画布 const dimensions = await getImageDimensions(imageUrl); - const existingNodes = nodes.length; + // 使用 baseNodeCount + uploadIndex 计算位置,确保多张图片不重叠 + const nodeIndex = baseNodeCount + uploadIndex; const spacing = 20; - const x = 100 + (existingNodes % 3) * (dimensions.width + spacing); - const y = 100 + Math.floor(existingNodes / 3) * (dimensions.height + spacing); + const x = 100 + (nodeIndex % 3) * (dimensions.width + spacing); + const y = 100 + Math.floor(nodeIndex / 3) * (dimensions.height + spacing); + uploadIndex++; // 递增索引 addNode({ type: 'image',