diff --git a/apps/desktop/src/components/comfyui/WorkflowTemplateCreator.tsx b/apps/desktop/src/components/comfyui/WorkflowTemplateCreator.tsx index 8e65e53..d77f878 100644 --- a/apps/desktop/src/components/comfyui/WorkflowTemplateCreator.tsx +++ b/apps/desktop/src/components/comfyui/WorkflowTemplateCreator.tsx @@ -14,6 +14,16 @@ import { AlertCircle, Plus, Trash2, + ChevronDown, + ChevronRight, + Type, + Hash, + ToggleLeft, + Image, + Music, + Video, + List, + Braces, } from 'lucide-react'; // 定义符合ComfyUI SDK的模板数据结构 @@ -101,6 +111,7 @@ export const WorkflowTemplateCreator: React.FC = ( const [isSaving, setIsSaving] = useState(false); const [workflowJsonText, setWorkflowJsonText] = useState('{}'); const [newParameterName, setNewParameterName] = useState(''); + const [expandedParameters, setExpandedParameters] = useState>(new Set()); // 重置表单数据 useEffect(() => { @@ -190,6 +201,19 @@ export const WorkflowTemplateCreator: React.FC = ( setNewParameterName(''); }; + // 切换参数展开/折叠状态 + const toggleParameterExpanded = (paramName: string) => { + setExpandedParameters(prev => { + const newSet = new Set(prev); + if (newSet.has(paramName)) { + newSet.delete(paramName); + } else { + newSet.add(paramName); + } + return newSet; + }); + }; + // 根据参数类型获取默认配置 const getDefaultConfigForType = (type: string): Partial => { switch (type) { @@ -274,6 +298,51 @@ export const WorkflowTemplateCreator: React.FC = ( return Object.keys(newErrors).length === 0; }; + // 获取参数类型的显示信息 + const getParameterTypeInfo = (type: string) => { + const typeMap = { + string: { label: '字符串', icon: Type, color: 'text-blue-600', bgColor: 'bg-blue-50' }, + integer: { label: '整数', icon: Hash, color: 'text-green-600', bgColor: 'bg-green-50' }, + float: { label: '浮点数', icon: Hash, color: 'text-green-600', bgColor: 'bg-green-50' }, + number: { label: '数字', icon: Hash, color: 'text-green-600', bgColor: 'bg-green-50' }, + boolean: { label: '布尔值', icon: ToggleLeft, color: 'text-purple-600', bgColor: 'bg-purple-50' }, + image: { label: '图片', icon: Image, color: 'text-pink-600', bgColor: 'bg-pink-50' }, + audio: { label: '音频', icon: Music, color: 'text-orange-600', bgColor: 'bg-orange-50' }, + video: { label: '视频', icon: Video, color: 'text-red-600', bgColor: 'bg-red-50' }, + array: { label: '数组', icon: List, color: 'text-indigo-600', bgColor: 'bg-indigo-50' }, + object: { label: '对象', icon: Braces, color: 'text-gray-600', bgColor: 'bg-gray-50' }, + }; + return typeMap[type as keyof typeof typeMap] || typeMap.string; + }; + + // 格式化参数值显示 + const formatParameterValue = (schema: ParameterSchema) => { + if (schema.default === undefined || schema.default === null || schema.default === '') { + return '未设置'; + } + + if (schema.param_type === 'boolean') { + return schema.default ? 'True' : 'False'; + } + + if (schema.param_type === 'integer' || schema.param_type === 'float' || schema.param_type === 'number') { + let value = String(schema.default); + if (schema.min !== undefined || schema.max !== undefined) { + const range = []; + if (schema.min !== undefined) range.push(`最小: ${schema.min}`); + if (schema.max !== undefined) range.push(`最大: ${schema.max}`); + if (range.length > 0) value += ` (${range.join(', ')})`; + } + return value; + } + + if (schema.param_type === 'image' || schema.param_type === 'audio' || schema.param_type === 'video') { + return schema.default || '未设置文件'; + } + + return String(schema.default); + }; + // 处理保存 const handleSave = async () => { if (!validateForm()) { @@ -608,21 +677,73 @@ export const WorkflowTemplateCreator: React.FC = (

添加参数来让模板更加灵活可配置

) : ( -
- {Object.entries(templateData.parameters).map(([paramName, schema]) => ( -
-
-

{paramName}

- -
+
+ {Object.entries(templateData.parameters).map(([paramName, schema]) => { + const typeInfo = getParameterTypeInfo(schema.param_type); + const isExpanded = expandedParameters.has(paramName); + const Icon = typeInfo.icon; -
+ return ( +
+ {/* 折叠头部 - 简洁信息展示 */} +
toggleParameterExpanded(paramName)} + > +
+
+
+ {isExpanded ? ( + + ) : ( + + )} +
+ +
+
+ +
+
+

{paramName}

+ + {typeInfo.label} + + {schema.required && ( + + 必填 + + )} +
+ +
+ 默认值: {formatParameterValue(schema)} + {schema.description && ( + 描述: {schema.description} + )} +
+
+
+ +
+ +
+
+
+ + {/* 展开的详细配置表单 */} + {isExpanded && ( +
+
+ )} +
)}
-
- ))} + ) + })}
)}