fix(tinyflow-ui): resolve typescript compilation errors in useRefOptions

This commit is contained in:
2026-03-01 16:00:55 +08:00
parent 05990072e6
commit f872db6c59

View File

@@ -31,9 +31,11 @@ const getChildren = (params: any, parentId: string, nodeIsChildren: boolean, nod
const nodeToOptions = (node: Node, nodeIsChildren: boolean, currentNode: Node) => { const nodeToOptions = (node: Node, nodeIsChildren: boolean, currentNode: Node) => {
const options = getOptions(); const options = getOptions();
let icon = nodeIcons[node.type]; const nodeType = node.type || '';
if (!icon && options?.customNodes && options.customNodes[node.type]) {
icon = options.customNodes[node.type].icon; let icon: string | undefined = nodeIcons[nodeType];
if (!icon && options?.customNodes && options.customNodes[nodeType]) {
icon = options.customNodes[nodeType].icon;
} }
// 如果仍然获取不到,尝试使用 data.icon (作为回退) // 如果仍然获取不到,尝试使用 data.icon (作为回退)
@@ -43,7 +45,7 @@ const nodeToOptions = (node: Node, nodeIsChildren: boolean, currentNode: Node) =
const title = node.data.title; const title = node.data.title;
if (node.type === 'startNode') { if (nodeType === 'startNode') {
const parameters = node.data.parameters as Array<Parameter>; const parameters = node.data.parameters as Array<Parameter>;
const children = []; const children = [];
if (parameters) if (parameters)
@@ -56,7 +58,7 @@ const nodeToOptions = (node: Node, nodeIsChildren: boolean, currentNode: Node) =
dataType: dataType, dataType: dataType,
value: node.id + '.' + parameter.name, value: node.id + '.' + parameter.name,
selectable: true, selectable: true,
nodeType: node.type nodeType: nodeType
}); });
} }
return { return {
@@ -64,30 +66,30 @@ const nodeToOptions = (node: Node, nodeIsChildren: boolean, currentNode: Node) =
icon: icon, icon: icon,
value: node.id, value: node.id,
selectable: false, selectable: false,
nodeType: node.type, nodeType: nodeType,
children children
}; };
} else if (node.type === 'loopNode' && currentNode.parentId) { } else if (nodeType === 'loopNode' && currentNode.parentId) {
return { return {
label: title, label: title,
icon: icon, icon: icon,
value: node.id, value: node.id,
selectable: false, selectable: false,
nodeType: node.type, nodeType: nodeType,
children: [ children: [
{ {
label: 'loopItem', label: 'loopItem',
dataType: 'Any', dataType: 'Any',
value: node.id + '.loopItem', value: node.id + '.loopItem',
selectable: true, selectable: true,
nodeType: node.type nodeType: nodeType
}, },
{ {
label: 'index', label: 'index',
dataType: 'Number', dataType: 'Number',
value: node.id + '.index', value: node.id + '.index',
selectable: true, selectable: true,
nodeType: node.type nodeType: nodeType
} }
] ]
}; };
@@ -99,8 +101,8 @@ const nodeToOptions = (node: Node, nodeIsChildren: boolean, currentNode: Node) =
icon: icon, icon: icon,
value: node.id, value: node.id,
selectable: false, selectable: false,
nodeType: node.type, nodeType: nodeType,
children: getChildren(outputDefs, node.id, nodeIsChildren, node.type) children: getChildren(outputDefs, node.id, nodeIsChildren, nodeType)
}; };
} }
} }