feat: 批量创作表增加完整生成设置对话框,参考图上限提升到10
- 新增 BatchGenerationSettingsDialog 组件:模型选择 + 图像质量/尺寸/宽高比/透明背景/生成张数 - 替换原简单确认框为完整设置面板,用户可在生成前调整参数 - 参考图列上限从 6 提升到 10,列宽调整为 72px 以适配
This commit is contained in:
1 parent
caa02a1307
commit
97e6b045d9
4 files changed
+196
-40
No files matched your search
@@ -0,0 +1,101 @@
|
|||||||
|
import { useEffect, useState } from "react";
|
||||||
|
import { Button, Modal } from "antd";
|
||||||
|
import { WandSparkles, X } from "lucide-react";
|
||||||
|
|
||||||
|
import { ImageSettingsPanel } from "@/components/image-settings-panel";
|
||||||
|
import { ModelPicker } from "@/components/model-picker";
|
||||||
|
import { canvasThemes } from "@/lib/canvas-theme";
|
||||||
|
import { defaultImageParamsForModel } from "@/lib/model-selection";
|
||||||
|
import { useActiveTheme } from "@/stores/canvas/use-canvas-theme-store";
|
||||||
|
import type { AiConfig } from "@/stores/use-config-store";
|
||||||
|
|
||||||
|
export type BatchGenerationSettings = Pick<AiConfig, "model" | "imageModel" | "quality" | "size" | "transparentBackground" | "count">;
|
||||||
|
|
||||||
|
type BatchGenerationSettingsDialogProps = {
|
||||||
|
open: boolean;
|
||||||
|
config: AiConfig;
|
||||||
|
rowCount: number;
|
||||||
|
concurrency: number;
|
||||||
|
onClose: () => void;
|
||||||
|
onConfirm: (settings: BatchGenerationSettings) => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function BatchGenerationSettingsDialog({ open, config, rowCount, concurrency, onClose, onConfirm }: BatchGenerationSettingsDialogProps) {
|
||||||
|
const theme = canvasThemes[useActiveTheme()];
|
||||||
|
const [generationConfig, setGenerationConfig] = useState<AiConfig>(config);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (open) setGenerationConfig(config);
|
||||||
|
}, [config, open]);
|
||||||
|
|
||||||
|
const handleConfigChange = (key: "quality" | "size" | "transparentBackground" | "count", value: string) => {
|
||||||
|
setGenerationConfig((current) => ({ ...current, [key]: value }));
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleModelChange = (model: string) => {
|
||||||
|
setGenerationConfig((current) => ({ ...current, model, imageModel: model, ...defaultImageParamsForModel(current, model) }));
|
||||||
|
};
|
||||||
|
|
||||||
|
const imageModel = generationConfig.imageModel || generationConfig.model;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Modal
|
||||||
|
open={open}
|
||||||
|
onCancel={onClose}
|
||||||
|
footer={null}
|
||||||
|
centered
|
||||||
|
destroyOnHidden
|
||||||
|
width={480}
|
||||||
|
title="批量生成设置"
|
||||||
|
>
|
||||||
|
<div className="flex flex-col gap-4 py-2">
|
||||||
|
<div className="rounded-lg bg-black/5 px-3 py-2 text-sm dark:bg-white/[0.04]">
|
||||||
|
共 <span className="font-semibold">{rowCount}</span> 个未完成任务 · 并发上限 <span className="font-semibold">{concurrency}</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="space-y-2">
|
||||||
|
<div className="text-sm font-medium opacity-75">生成模型</div>
|
||||||
|
<ModelPicker
|
||||||
|
config={generationConfig}
|
||||||
|
value={imageModel}
|
||||||
|
capability="image"
|
||||||
|
fullWidth
|
||||||
|
showSelectedPrice={false}
|
||||||
|
onChange={handleModelChange}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="border-t pt-3" style={{ borderColor: theme.node.stroke }}>
|
||||||
|
<ImageSettingsPanel
|
||||||
|
config={generationConfig}
|
||||||
|
onConfigChange={handleConfigChange}
|
||||||
|
theme={theme}
|
||||||
|
showTitle={false}
|
||||||
|
showCount={true}
|
||||||
|
quickCount={4}
|
||||||
|
maxCount={10}
|
||||||
|
className="w-full space-y-3"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="mt-2 flex justify-end gap-2">
|
||||||
|
<Button icon={<X className="size-4" />} onClick={onClose}>取消</Button>
|
||||||
|
<Button
|
||||||
|
type="primary"
|
||||||
|
icon={<WandSparkles className="size-4" />}
|
||||||
|
onClick={() => onConfirm({
|
||||||
|
model: generationConfig.model,
|
||||||
|
imageModel: generationConfig.imageModel,
|
||||||
|
quality: generationConfig.quality,
|
||||||
|
size: generationConfig.size,
|
||||||
|
transparentBackground: generationConfig.transparentBackground,
|
||||||
|
count: generationConfig.count,
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
开始生成 {rowCount} 个任务
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Modal>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { nanoid } from "nanoid";
|
import { nanoid } from "nanoid";
|
||||||
|
|
||||||
import type { CanvasBatchOperation, CanvasBatchReferenceColumn, CanvasBatchRow, CanvasBatchTableData, CanvasConnection, CanvasNodeData } from "@/types/canvas";
|
import type { CanvasBatchOperation, CanvasBatchReferenceColumn, CanvasBatchRow, CanvasBatchTableData, CanvasConnection, CanvasNodeData } from "@/types/canvas";
|
||||||
|
|
||||||
@@ -7,7 +7,7 @@ export const CREATIVE_BATCH_PROMPT = "基于参考图创作一张新的商业图
|
|||||||
export const BATCH_REFERENCE_HANDLE_PREFIX = "batch-reference:";
|
export const BATCH_REFERENCE_HANDLE_PREFIX = "batch-reference:";
|
||||||
export const BATCH_REFERENCE_HANDLE_TOP = 112;
|
export const BATCH_REFERENCE_HANDLE_TOP = 112;
|
||||||
export const BATCH_REFERENCE_HANDLE_GAP = 38;
|
export const BATCH_REFERENCE_HANDLE_GAP = 38;
|
||||||
export const MAX_BATCH_REFERENCE_COLUMNS = 6;
|
export const MAX_BATCH_REFERENCE_COLUMNS = 10;
|
||||||
export const MAX_BATCH_TEXT_COLUMNS = 4;
|
export const MAX_BATCH_TEXT_COLUMNS = 4;
|
||||||
export const BATCH_TEXT_HANDLE_PREFIX = "batch-text:";
|
export const BATCH_TEXT_HANDLE_PREFIX = "batch-text:";
|
||||||
|
|
||||||
@@ -15,7 +15,7 @@ export function batchGridTemplateColumns(referenceCount: number, textCount: numb
|
|||||||
return [
|
return [
|
||||||
"36px",
|
"36px",
|
||||||
"68px",
|
"68px",
|
||||||
`repeat(${referenceCount}, 88px)`,
|
`repeat(\${referenceCount}, 72px)`,
|
||||||
textCount > 0 ? `repeat(${textCount}, minmax(168px, 0.75fr))` : undefined,
|
textCount > 0 ? `repeat(${textCount}, minmax(168px, 0.75fr))` : undefined,
|
||||||
"minmax(280px, 1fr)",
|
"minmax(280px, 1fr)",
|
||||||
"148px",
|
"148px",
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { isCanvasNodeGenerating } from "@/lib/canvas/canvas-node-task-state";
|
import { isCanvasNodeGenerating } from "@/lib/canvas/canvas-node-task-state";
|
||||||
import { lazy, Suspense, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
|
import { lazy, Suspense, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
|
||||||
import type { Dispatch, MouseEvent as ReactMouseEvent, SetStateAction } from "react";
|
import type { Dispatch, MouseEvent as ReactMouseEvent, SetStateAction } from "react";
|
||||||
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
||||||
@@ -110,6 +110,7 @@ import { TapNowImportDialog } from "./components/tapnow-import-dialog";
|
|||||||
import { CanvasFocusModeBar } from "@/components/canvas/canvas-focus-mode-bar";
|
import { CanvasFocusModeBar } from "@/components/canvas/canvas-focus-mode-bar";
|
||||||
import { CanvasProjectContextMenu } from "./canvas-project-context-menu";
|
import { CanvasProjectContextMenu } from "./canvas-project-context-menu";
|
||||||
import { CanvasProjectMediaDialogs } from "./canvas-project-media-dialogs";
|
import { CanvasProjectMediaDialogs } from "./canvas-project-media-dialogs";
|
||||||
|
import { BatchGenerationSettingsDialog } from "@/components/canvas/batch-generation-settings-dialog";
|
||||||
import { CanvasProjectSelectionToolbar } from "./canvas-project-selection-toolbar";
|
import { CanvasProjectSelectionToolbar } from "./canvas-project-selection-toolbar";
|
||||||
import { CanvasProjectStatusDialogs } from "./canvas-project-status-dialogs";
|
import { CanvasProjectStatusDialogs } from "./canvas-project-status-dialogs";
|
||||||
import { CanvasProjectWorldLayers } from "./canvas-project-world-layers";
|
import { CanvasProjectWorldLayers } from "./canvas-project-world-layers";
|
||||||
@@ -1910,7 +1911,7 @@ function InfiniteCanvasPage() {
|
|||||||
handleGenerateNode,
|
handleGenerateNode,
|
||||||
});
|
});
|
||||||
|
|
||||||
const { addReferenceColumn: addBatchReferenceColumn, addTextColumn: addBatchTextColumn, addRow: addBatchRow, fillRowsFromConnections, generateRows: generateBatchRows, moveReferenceCell: moveBatchReferenceCell, patchTable: patchBatchTable, removeRow: removeBatchRow, reorderReferenceColumns: reorderBatchReferenceColumns, syncRowsFromConnections, updateRow: updateBatchRow } = useCanvasBatchTable({
|
const { addReferenceColumn: addBatchReferenceColumn, addTextColumn: addBatchTextColumn, addRow: addBatchRow, fillRowsFromConnections, generateRows: generateBatchRows, moveReferenceCell: moveBatchReferenceCell, patchTable: patchBatchTable, removeRow: removeBatchRow, reorderReferenceColumns: reorderBatchReferenceColumns, syncRowsFromConnections, updateRow: updateBatchRow, batchGenDialogOpen, batchGenDialogRowCount, batchGenDialogConcurrency, batchGenDialogConfig, closeBatchGenDialog, confirmBatchGenDialog } = useCanvasBatchTable({
|
||||||
nodesRef,
|
nodesRef,
|
||||||
connectionsRef,
|
connectionsRef,
|
||||||
setNodes,
|
setNodes,
|
||||||
@@ -3176,6 +3177,15 @@ function InfiniteCanvasPage() {
|
|||||||
config={effectiveConfig}
|
config={effectiveConfig}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<BatchGenerationSettingsDialog
|
||||||
|
open={batchGenDialogOpen}
|
||||||
|
config={batchGenDialogConfig}
|
||||||
|
rowCount={batchGenDialogRowCount}
|
||||||
|
concurrency={batchGenDialogConcurrency}
|
||||||
|
onClose={closeBatchGenDialog}
|
||||||
|
onConfirm={confirmBatchGenDialog}
|
||||||
|
/>
|
||||||
|
|
||||||
<CanvasProjectStatusDialogs
|
<CanvasProjectStatusDialogs
|
||||||
theme={theme}
|
theme={theme}
|
||||||
task={taskDetail}
|
task={taskDetail}
|
||||||
|
|||||||
@@ -1,14 +1,15 @@
|
|||||||
import { useCallback, type Dispatch, type SetStateAction } from "react";
|
import { useCallback, useMemo, useState, type Dispatch, type SetStateAction } from "react";
|
||||||
import { App } from "antd";
|
import { App } from "antd";
|
||||||
import { nanoid } from "nanoid";
|
import { nanoid } from "nanoid";
|
||||||
|
|
||||||
import { NODE_DEFAULT_SIZE } from "@/constant/canvas";
|
import { NODE_DEFAULT_SIZE } from "@/constant/canvas";
|
||||||
import { batchInputColumns, batchPromptForRow, batchReferenceColumns, batchTextInputColumns, createBatchRow, createBatchRowsFromColumns, moveBatchReferenceCell, reorderBatchReferenceColumns } from "@/lib/canvas/canvas-batch-table";
|
import { MAX_BATCH_REFERENCE_COLUMNS, batchInputColumns, batchPromptForRow, batchReferenceColumns, batchTextInputColumns, createBatchRow, createBatchRowsFromColumns, moveBatchReferenceCell, reorderBatchReferenceColumns } from "@/lib/canvas/canvas-batch-table";
|
||||||
import { createCanvasNode } from "@/lib/canvas/canvas-project-domain";
|
import { createCanvasNode } from "@/lib/canvas/canvas-project-domain";
|
||||||
import { buildGenerationConfig, resetGenerationTaskMetadata } from "@/lib/canvas/canvas-project-generation";
|
import { buildGenerationConfig, resetGenerationTaskMetadata } from "@/lib/canvas/canvas-project-generation";
|
||||||
import { navigateToSettings } from "@/lib/settings-navigation";
|
import { navigateToSettings } from "@/lib/settings-navigation";
|
||||||
import { modelDisplayName, useConfigStore, useEffectiveConfig } from "@/stores/use-config-store";
|
import { useConfigStore, useEffectiveConfig } from "@/stores/use-config-store";
|
||||||
import { CanvasNodeType, type CanvasBatchRow, type CanvasBatchTableData, type CanvasConnection, type CanvasGenerationBatchMode, type CanvasNodeData } from "@/types/canvas";
|
import { CanvasNodeType, type CanvasBatchRow, type CanvasBatchTableData, type CanvasConnection, type CanvasGenerationBatchMode, type CanvasNodeData } from "@/types/canvas";
|
||||||
|
import type { BatchGenerationSettings } from "@/components/canvas/batch-generation-settings-dialog";
|
||||||
|
|
||||||
type Options = {
|
type Options = {
|
||||||
nodesRef: { current: CanvasNodeData[] };
|
nodesRef: { current: CanvasNodeData[] };
|
||||||
@@ -19,11 +20,19 @@ type Options = {
|
|||||||
enqueueGenerationBatch: (sourceNodeId: string, mode: CanvasGenerationBatchMode, targets: Array<{ rowId: string; nodeId: string }>, options?: { concurrency?: number }) => string | undefined;
|
enqueueGenerationBatch: (sourceNodeId: string, mode: CanvasGenerationBatchMode, targets: Array<{ rowId: string; nodeId: string }>, options?: { concurrency?: number }) => string | undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type PendingBatchGen = {
|
||||||
|
nodeId: string;
|
||||||
|
rows: CanvasBatchRow[];
|
||||||
|
concurrency: number;
|
||||||
|
};
|
||||||
|
|
||||||
export function useCanvasBatchTable({ nodesRef, connectionsRef, setNodes, setConnections, setSelectedNodeIds, enqueueGenerationBatch }: Options) {
|
export function useCanvasBatchTable({ nodesRef, connectionsRef, setNodes, setConnections, setSelectedNodeIds, enqueueGenerationBatch }: Options) {
|
||||||
const { message, modal } = App.useApp();
|
const { message } = App.useApp();
|
||||||
const effectiveConfig = useEffectiveConfig();
|
const effectiveConfig = useEffectiveConfig();
|
||||||
const isAiConfigReady = useConfigStore((state) => state.isAiConfigReady);
|
const isAiConfigReady = useConfigStore((state) => state.isAiConfigReady);
|
||||||
|
|
||||||
|
const [batchGenDialog, setBatchGenDialog] = useState<{ open: boolean; pending: PendingBatchGen | null }>({ open: false, pending: null });
|
||||||
|
|
||||||
const patchTable = useCallback((nodeId: string, patch: Partial<CanvasBatchTableData>) => {
|
const patchTable = useCallback((nodeId: string, patch: Partial<CanvasBatchTableData>) => {
|
||||||
setNodes((current) => current.map((node) => node.id !== nodeId ? node : { ...node, metadata: { ...node.metadata, batchTable: { operation: "try_on", concurrency: 3, rows: [], ...node.metadata?.batchTable, ...patch } } }));
|
setNodes((current) => current.map((node) => node.id !== nodeId ? node : { ...node, metadata: { ...node.metadata, batchTable: { operation: "try_on", concurrency: 3, rows: [], ...node.metadata?.batchTable, ...patch } } }));
|
||||||
}, [setNodes]);
|
}, [setNodes]);
|
||||||
@@ -50,7 +59,7 @@ export function useCanvasBatchTable({ nodesRef, connectionsRef, setNodes, setCon
|
|||||||
const table = nodesRef.current.find((item) => item.id === nodeId)?.metadata?.batchTable;
|
const table = nodesRef.current.find((item) => item.id === nodeId)?.metadata?.batchTable;
|
||||||
if (!table) return;
|
if (!table) return;
|
||||||
const columns = batchReferenceColumns(table);
|
const columns = batchReferenceColumns(table);
|
||||||
if (columns.length >= 6) return message.info("最多支持 6 组参考图");
|
if (columns.length >= MAX_BATCH_REFERENCE_COLUMNS) return message.info("最多支持 10 组参考图");
|
||||||
const nextIndex = columns.length + 1;
|
const nextIndex = columns.length + 1;
|
||||||
patchTable(nodeId, { referenceColumns: [...columns, { id: `reference-${nanoid()}`, label: `参考图 ${nextIndex}` }] });
|
patchTable(nodeId, { referenceColumns: [...columns, { id: `reference-${nanoid()}`, label: `参考图 ${nextIndex}` }] });
|
||||||
}, [message, nodesRef, patchTable]);
|
}, [message, nodesRef, patchTable]);
|
||||||
@@ -117,35 +126,13 @@ export function useCanvasBatchTable({ nodesRef, connectionsRef, setNodes, setCon
|
|||||||
if (nextTable !== table) patchTable(nodeId, { rows: nextTable.rows });
|
if (nextTable !== table) patchTable(nodeId, { rows: nextTable.rows });
|
||||||
}, [nodesRef, patchTable]);
|
}, [nodesRef, patchTable]);
|
||||||
|
|
||||||
const generateRows = useCallback(async (nodeId: string, requestedRowIds?: string[]) => {
|
const executeBatchGeneration = useCallback((pending: PendingBatchGen, settings: BatchGenerationSettings) => {
|
||||||
|
const { nodeId, rows, concurrency } = pending;
|
||||||
const sourceNode = nodesRef.current.find((item) => item.id === nodeId);
|
const sourceNode = nodesRef.current.find((item) => item.id === nodeId);
|
||||||
const table = sourceNode?.metadata?.batchTable;
|
const table = sourceNode?.metadata?.batchTable;
|
||||||
if (!sourceNode || !table) return;
|
if (!sourceNode || !table) return;
|
||||||
const imageModel = effectiveConfig.imageModel || effectiveConfig.model;
|
|
||||||
if (!isAiConfigReady(effectiveConfig, imageModel)) {
|
const mergedConfig = { ...effectiveConfig, ...settings };
|
||||||
navigateToSettings({ continueCreation: true });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const activeNodeIds = new Set((sourceNode.metadata?.generationBatches || []).filter((batch) => batch.mode === "batch_image").flatMap((batch) => batch.items.filter((item) => ["waiting", "submitting", "queued", "running"].includes(item.status)).map((item) => item.nodeId)));
|
|
||||||
const requested = requestedRowIds?.length ? new Set(requestedRowIds) : null;
|
|
||||||
const rows = table.rows.filter((row) => {
|
|
||||||
if (row.enabled === false || (requested && !requested.has(row.id)) || !batchPromptForRow(table, row).trim()) return false;
|
|
||||||
if (table.operation === "try_on" && row.inputNodeIds.length < 2) return false;
|
|
||||||
if (!row.inputNodeIds.length || row.inputNodeIds.some((id) => !nodesRef.current.some((node) => node.id === id && node.type === CanvasNodeType.Image && Boolean(node.metadata?.content || node.metadata?.storageKey)))) return false;
|
|
||||||
const output = row.outputNodeId ? nodesRef.current.find((node) => node.id === row.outputNodeId) : undefined;
|
|
||||||
return !output?.metadata?.content && (!output || !activeNodeIds.has(output.id));
|
|
||||||
});
|
|
||||||
if (!rows.length) return message.info("没有可提交的未完成任务,请检查参考图和提示词");
|
|
||||||
const confirmed = await new Promise<boolean>((resolve) => modal.confirm({
|
|
||||||
title: `确认提交 ${rows.length} 个批量图片任务`,
|
|
||||||
content: `模型:${modelDisplayName(effectiveConfig, imageModel)};并发上限:${table.concurrency}。这些任务可能消耗积分或产生外部模型费用。`,
|
|
||||||
okText: "确认生成",
|
|
||||||
cancelText: "取消",
|
|
||||||
centered: true,
|
|
||||||
onOk: () => resolve(true),
|
|
||||||
onCancel: () => resolve(false),
|
|
||||||
}));
|
|
||||||
if (!confirmed) return;
|
|
||||||
|
|
||||||
const imageSpec = NODE_DEFAULT_SIZE[CanvasNodeType.Image];
|
const imageSpec = NODE_DEFAULT_SIZE[CanvasNodeType.Image];
|
||||||
const nextNodes = [...nodesRef.current];
|
const nextNodes = [...nodesRef.current];
|
||||||
@@ -162,7 +149,11 @@ export function useCanvasBatchTable({ nodesRef, connectionsRef, setNodes, setCon
|
|||||||
const textNode = nodesRef.current.find((node) => node.id === textNodeId);
|
const textNode = nodesRef.current.find((node) => node.id === textNodeId);
|
||||||
return textNode?.metadata?.content || textNode?.metadata?.prompt || "";
|
return textNode?.metadata?.content || textNode?.metadata?.prompt || "";
|
||||||
})].filter(Boolean).join("\n\n"),
|
})].filter(Boolean).join("\n\n"),
|
||||||
model: buildGenerationConfig(effectiveConfig, undefined, "image").model,
|
model: buildGenerationConfig(mergedConfig, undefined, "image").model,
|
||||||
|
size: mergedConfig.size,
|
||||||
|
quality: mergedConfig.quality,
|
||||||
|
transparentBackground: mergedConfig.transparentBackground,
|
||||||
|
count: Number(mergedConfig.count) || 1,
|
||||||
generationMode: "image" as const,
|
generationMode: "image" as const,
|
||||||
generationType: "edit" as const,
|
generationType: "edit" as const,
|
||||||
workflowKind: "final" as const,
|
workflowKind: "final" as const,
|
||||||
@@ -192,8 +183,62 @@ export function useCanvasBatchTable({ nodesRef, connectionsRef, setNodes, setCon
|
|||||||
setNodes(nextNodes);
|
setNodes(nextNodes);
|
||||||
setConnections(nextConnections);
|
setConnections(nextConnections);
|
||||||
setSelectedNodeIds(new Set(targets.map((target) => target.nodeId)));
|
setSelectedNodeIds(new Set(targets.map((target) => target.nodeId)));
|
||||||
if (enqueueGenerationBatch(nodeId, "batch_image", targets, { concurrency: table.concurrency })) message.success(`${targets.length} 个任务已加入并发队列`);
|
if (enqueueGenerationBatch(nodeId, "batch_image", targets, { concurrency })) message.success(`${targets.length} 个任务已加入并发队列`);
|
||||||
}, [connectionsRef, effectiveConfig, enqueueGenerationBatch, isAiConfigReady, message, modal, nodesRef, setConnections, setNodes, setSelectedNodeIds]);
|
}, [connectionsRef, effectiveConfig, enqueueGenerationBatch, message, nodesRef, setConnections, setNodes, setSelectedNodeIds]);
|
||||||
|
|
||||||
return { addReferenceColumn, addTextColumn, addRow, fillRowsFromConnections, generateRows, moveReferenceCell, patchTable, removeRow, reorderReferenceColumns, syncRowsFromConnections, updateRow };
|
const generateRows = useCallback((nodeId: string, requestedRowIds?: string[]) => {
|
||||||
|
const sourceNode = nodesRef.current.find((item) => item.id === nodeId);
|
||||||
|
const table = sourceNode?.metadata?.batchTable;
|
||||||
|
if (!sourceNode || !table) return;
|
||||||
|
const imageModel = effectiveConfig.imageModel || effectiveConfig.model;
|
||||||
|
if (!isAiConfigReady(effectiveConfig, imageModel)) {
|
||||||
|
navigateToSettings({ continueCreation: true });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const activeNodeIds = new Set((sourceNode.metadata?.generationBatches || []).filter((batch) => batch.mode === "batch_image").flatMap((batch) => batch.items.filter((item) => ["waiting", "submitting", "queued", "running"].includes(item.status)).map((item) => item.nodeId)));
|
||||||
|
const requested = requestedRowIds?.length ? new Set(requestedRowIds) : null;
|
||||||
|
const rows = table.rows.filter((row) => {
|
||||||
|
if (row.enabled === false || (requested && !requested.has(row.id)) || !batchPromptForRow(table, row).trim()) return false;
|
||||||
|
if (table.operation === "try_on" && row.inputNodeIds.length < 2) return false;
|
||||||
|
if (!row.inputNodeIds.length || row.inputNodeIds.some((id) => !nodesRef.current.some((node) => node.id === id && node.type === CanvasNodeType.Image && Boolean(node.metadata?.content || node.metadata?.storageKey)))) return false;
|
||||||
|
const output = row.outputNodeId ? nodesRef.current.find((node) => node.id === row.outputNodeId) : undefined;
|
||||||
|
return !output?.metadata?.content && (!output || !activeNodeIds.has(output.id));
|
||||||
|
});
|
||||||
|
if (!rows.length) return message.info("没有可提交的未完成任务,请检查参考图和提示词");
|
||||||
|
|
||||||
|
setBatchGenDialog({ open: true, pending: { nodeId, rows, concurrency: table.concurrency } });
|
||||||
|
}, [effectiveConfig, isAiConfigReady, message, nodesRef]);
|
||||||
|
|
||||||
|
const closeBatchGenDialog = useCallback(() => {
|
||||||
|
setBatchGenDialog({ open: false, pending: null });
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const confirmBatchGenDialog = useCallback((settings: BatchGenerationSettings) => {
|
||||||
|
if (batchGenDialog.pending) {
|
||||||
|
executeBatchGeneration(batchGenDialog.pending, settings);
|
||||||
|
}
|
||||||
|
setBatchGenDialog({ open: false, pending: null });
|
||||||
|
}, [batchGenDialog.pending, executeBatchGeneration]);
|
||||||
|
|
||||||
|
const dialogConfig = useMemo(() => effectiveConfig, [effectiveConfig]);
|
||||||
|
|
||||||
|
return {
|
||||||
|
addReferenceColumn,
|
||||||
|
addTextColumn,
|
||||||
|
addRow,
|
||||||
|
fillRowsFromConnections,
|
||||||
|
generateRows,
|
||||||
|
moveReferenceCell,
|
||||||
|
patchTable,
|
||||||
|
removeRow,
|
||||||
|
reorderReferenceColumns,
|
||||||
|
syncRowsFromConnections,
|
||||||
|
updateRow,
|
||||||
|
batchGenDialogOpen: batchGenDialog.open,
|
||||||
|
batchGenDialogRowCount: batchGenDialog.pending?.rows.length ?? 0,
|
||||||
|
batchGenDialogConcurrency: batchGenDialog.pending?.concurrency ?? 1,
|
||||||
|
batchGenDialogConfig: dialogConfig,
|
||||||
|
closeBatchGenDialog,
|
||||||
|
confirmBatchGenDialog,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user