fix: 修复同时上传多张图片时位置重叠的问题
This commit is contained in:
parent
be6f22b3d6
commit
691c626e3f
@ -856,6 +856,9 @@ export function CanvasChatPanel({ chatId, initialMessages = [], onClose, onOpenF
|
|||||||
if (!files) return;
|
if (!files) return;
|
||||||
|
|
||||||
let firstImageUrl: string | null = null;
|
let firstImageUrl: string | null = null;
|
||||||
|
// 记录本次上传开始时的节点数量,用于计算新图片位置
|
||||||
|
const baseNodeCount = nodes.length;
|
||||||
|
let uploadIndex = 0;
|
||||||
|
|
||||||
for (const file of Array.from(files)) {
|
for (const file of Array.from(files)) {
|
||||||
if (!file.type.startsWith('image/')) {
|
if (!file.type.startsWith('image/')) {
|
||||||
@ -907,10 +910,12 @@ export function CanvasChatPanel({ chatId, initialMessages = [], onClose, onOpenF
|
|||||||
|
|
||||||
// 获取图片原始尺寸后添加到画布
|
// 获取图片原始尺寸后添加到画布
|
||||||
const dimensions = await getImageDimensions(imageUrl);
|
const dimensions = await getImageDimensions(imageUrl);
|
||||||
const existingNodes = nodes.length;
|
// 使用 baseNodeCount + uploadIndex 计算位置,确保多张图片不重叠
|
||||||
|
const nodeIndex = baseNodeCount + uploadIndex;
|
||||||
const spacing = 20;
|
const spacing = 20;
|
||||||
const x = 100 + (existingNodes % 3) * (dimensions.width + spacing);
|
const x = 100 + (nodeIndex % 3) * (dimensions.width + spacing);
|
||||||
const y = 100 + Math.floor(existingNodes / 3) * (dimensions.height + spacing);
|
const y = 100 + Math.floor(nodeIndex / 3) * (dimensions.height + spacing);
|
||||||
|
uploadIndex++; // 递增索引
|
||||||
|
|
||||||
addNode({
|
addNode({
|
||||||
type: 'image',
|
type: 'image',
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user