feat(canvas): add batch add-to-canvas and optimize batch mode UI
This commit is contained in:
parent
254511b91a
commit
b1261dd0bf
@ -381,6 +381,40 @@ export default function CanvasEditorPage({ params }: PageProps) {
|
||||
});
|
||||
};
|
||||
|
||||
const handleBatchAddToCanvas = useCallback((imageUrls: string[]) => {
|
||||
if (!imageUrls || imageUrls.length === 0) {
|
||||
toast.error("没有可添加到画布的图片");
|
||||
return;
|
||||
}
|
||||
|
||||
const columns = Math.min(4, imageUrls.length);
|
||||
const startX = 120;
|
||||
const startY = 120;
|
||||
const createdNodeIds: string[] = [];
|
||||
|
||||
for (const [index, imageUrl] of imageUrls.entries()) {
|
||||
const x = startX + (index % columns) * 320;
|
||||
const y = startY + Math.floor(index / columns) * 320;
|
||||
const nodeId = addNode({
|
||||
type: "image",
|
||||
position: { x, y },
|
||||
size: { width: 300, height: 300 },
|
||||
data: {
|
||||
src: imageUrl,
|
||||
status: "completed",
|
||||
title: `批量结果-${index + 1}`,
|
||||
prompt: "批量处理结果",
|
||||
},
|
||||
connections: [],
|
||||
});
|
||||
createdNodeIds.push(nodeId);
|
||||
}
|
||||
|
||||
if (createdNodeIds.length > 0) {
|
||||
selectNodes(createdNodeIds);
|
||||
}
|
||||
}, [addNode, selectNodes]);
|
||||
|
||||
// 处理图片操作(通过事件分发到选中图片节点执行)
|
||||
const handleAction = (action: string) => {
|
||||
if (!selectedImageNode) {
|
||||
@ -926,6 +960,7 @@ export default function CanvasEditorPage({ params }: PageProps) {
|
||||
<SceneFusionDialog
|
||||
open={sceneFusionDialogOpen}
|
||||
onOpenChange={setSceneFusionDialogOpen}
|
||||
onBatchAddToCanvas={handleBatchAddToCanvas}
|
||||
/>
|
||||
</div>
|
||||
</TooltipProvider>
|
||||
|
||||
@ -13,9 +13,10 @@ import { SceneFusionView } from "@/components/scene-fusion-view";
|
||||
interface SceneFusionDialogProps {
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
onBatchAddToCanvas?: (imageUrls: string[]) => void | Promise<void>;
|
||||
}
|
||||
|
||||
export function SceneFusionDialog({ open, onOpenChange }: SceneFusionDialogProps) {
|
||||
export function SceneFusionDialog({ open, onOpenChange, onBatchAddToCanvas }: SceneFusionDialogProps) {
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="z-[20000] max-w-6xl h-[92vh] flex flex-col p-0 gap-0 overflow-hidden !bg-white dark:!bg-zinc-950">
|
||||
@ -26,7 +27,7 @@ export function SceneFusionDialog({ open, onOpenChange }: SceneFusionDialogProps
|
||||
<div className="relative flex-1 min-h-0">
|
||||
<div className="absolute inset-0 bg-white dark:bg-zinc-950 pointer-events-none" />
|
||||
<div className="relative z-10 h-full">
|
||||
<SceneFusionView onBack={() => onOpenChange(false)} />
|
||||
<SceneFusionView onBack={() => onOpenChange(false)} onBatchAddToCanvas={onBatchAddToCanvas} />
|
||||
</div>
|
||||
</div>
|
||||
</DialogContent>
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user