set-node.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /**
  2. * Set 变量节点逻辑
  3. */
  4. /**
  5. * 创建 Set 节点数据
  6. * @param {string} varName - 变量名
  7. * @param {string} varType - 变量类型
  8. */
  9. export function createSetNodeData(varName, varType = 'string') {
  10. return {
  11. id: `var_set_${varName}`,
  12. type: 'variable',
  13. varMode: 'set',
  14. varName,
  15. label: varName,
  16. inputs: [
  17. { id: 'input_exec', label: '', type: 'execution' },
  18. { id: 'input_value', label: varName, type: 'data', paramType: varType }
  19. ],
  20. outputs: [
  21. { id: 'output_exec', label: '', type: 'execution' }
  22. ],
  23. data: {}
  24. };
  25. }
  26. /**
  27. * 验证 Set 节点
  28. */
  29. export function validateSetNode(node) {
  30. const errors = [];
  31. if (!node.varName) {
  32. errors.push('Set节点必须指定变量名');
  33. }
  34. const execInput = node.inputs?.find(p => p.type === 'execution');
  35. const execOutput = node.outputs?.find(p => p.type === 'execution');
  36. const dataInput = node.inputs?.find(p => p.type === 'data');
  37. if (!execInput) {
  38. errors.push('Set节点必须有执行输入端口');
  39. }
  40. if (!execOutput) {
  41. errors.push('Set节点必须有执行输出端口');
  42. }
  43. if (!dataInput) {
  44. errors.push('Set节点必须有数据输入端口');
  45. }
  46. return {
  47. valid: errors.length === 0,
  48. errors
  49. };
  50. }