import { useState } from "react"; import { Modal, Button, Space, message, Card, Tag, Upload, List, Popconfirm, } from "antd"; import { UploadOutlined, DeleteOutlined, FileTextOutlined, ThunderboltOutlined, PaperClipOutlined, } from "@ant-design/icons"; import type { GenerationPoint, AIModel } from "../types"; import * as taskApi from "../api/tasks"; import request from "../api/request"; interface GenerateModalProps { open: boolean; onClose: () => void; templateId: string; points: GenerationPoint[]; models: AIModel[]; } interface FileItem { uid: string; name: string; path?: string; } export default function GenerateModal({ open, onClose, templateId, points, models, }: GenerateModalProps) { const [filesMap, setFilesMap] = useState>({}); const [generating, setGenerating] = useState(false); const handleUpload = async (pointId: string, fileList: File[]) => { if (fileList.length === 0) return; const formData = new FormData(); fileList.forEach((f) => formData.append("ref_files", f)); await request.post(`/generation-points/${pointId}/upload-ref`, formData); const newFiles = fileList.map((f) => ({ uid: f.name + Date.now(), name: f.name, })); setFilesMap((prev) => ({ ...prev, [pointId]: [...(prev[pointId] || []), ...newFiles], })); message.success(`已上传 ${fileList.length} 个文件`); }; const handleRemoveFile = (pointId: string, fileName: string) => { setFilesMap((prev) => ({ ...prev, [pointId]: (prev[pointId] || []).filter((f) => f.name !== fileName), })); }; const handleGenerate = async () => { setGenerating(true); try { const { task_id } = await taskApi.triggerGeneration(templateId); message.success("已创建生成任务,请前往任务历史查看"); onClose(); } catch (err: unknown) { if (err instanceof Error) message.error(err.message); } finally { setGenerating(false); } }; const getModelName = (modelId: string | null) => { if (!modelId) return "默认模型"; const m = models.find((x) => x.id === modelId); return m?.name || modelId; }; const pointsNeedRef = points.filter((p) => p.need_ref_file); const pointsNoRef = points.filter((p) => !p.need_ref_file); return ( } >

共 {points.length} 个 AI 生成点,请确认提示词并上传参考文件后点击生成。

{pointsNeedRef.length > 0 && (
需要上传文件 ({pointsNeedRef.length})
)} {points.map((point, idx) => { const uploadedFiles = filesMap[point.id] || []; const modelName = getModelName(point.model_id); return ( #{idx + 1} {point.prompt.slice(0, 30)}{point.prompt.length > 30 ? "..." : ""} } extra={ {modelName} } > {point.remark && (

备注:{point.remark}

)} {point.need_ref_file && (
{ handleUpload(point.id, [file]); return false; }} > {uploadedFiles.length > 0 && ( ( handleRemoveFile(point.id, item.name)} >
)}
); })}
); }