func-node.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /**
  2. * Func 功能节点逻辑
  3. */
  4. /**
  5. * 创建功能节点数据
  6. * @param {string} funcType - 功能类型
  7. * @param {Object} config - 节点配置
  8. */
  9. export function createFuncNodeData(funcType, config = {}) {
  10. const { id, label, inputs = [], outputs = [], data = {} } = config;
  11. return {
  12. id: id || `node_${funcType}_${Date.now()}`,
  13. type: funcType,
  14. label: label || funcType,
  15. inputs: [
  16. { id: 'input_0', label: '', type: 'execution' },
  17. ...inputs
  18. ],
  19. outputs: [
  20. { id: 'output_0', label: '', type: 'execution' },
  21. ...outputs
  22. ],
  23. data
  24. };
  25. }
  26. /**
  27. * 验证功能节点
  28. */
  29. export function validateFuncNode(node) {
  30. const errors = [];
  31. const execInput = node.inputs?.find(p => p.type === 'execution');
  32. const execOutput = node.outputs?.find(p => p.type === 'execution');
  33. if (!execInput) {
  34. errors.push('功能节点必须有执行输入端口');
  35. }
  36. if (!execOutput) {
  37. errors.push('功能节点必须有执行输出端口');
  38. }
  39. return {
  40. valid: errors.length === 0,
  41. errors
  42. };
  43. }
  44. /**
  45. * 功能节点转换为工作流数据
  46. */
  47. export function funcNodeToWorkflow(node) {
  48. return {
  49. type: node.type,
  50. data: node.data || {}
  51. };
  52. }