fix: 修复同时上传多张图片时位置重叠的问题

This commit is contained in:
Your Name 2026-02-03 10:21:25 +08:00
parent be6f22b3d6
commit 691c626e3f

View File

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