feat: loop start add index (#3101)

* feat: loop start add index

* update doc
This commit is contained in:
Archer
2024-11-08 17:21:19 +08:00
committed by GitHub
parent a7f881fc5e
commit 7537330a3b
8 changed files with 75 additions and 53 deletions

View File

@@ -256,9 +256,9 @@ export enum NodeOutputKeyEnum {
// loop
loopArray = 'loopArray',
// loop start
loopStartInput = 'loopStartInput',
loopArrayIndex = 'loopArrayIndex',
// form input
formInputResult = 'formInputResult'

View File

@@ -1,8 +1,13 @@
import { FlowNodeInputTypeEnum, FlowNodeTypeEnum } from '../../../node/constant';
import {
FlowNodeInputTypeEnum,
FlowNodeOutputTypeEnum,
FlowNodeTypeEnum
} from '../../../node/constant';
import { FlowNodeTemplateType } from '../../../type/node.d';
import {
FlowNodeTemplateTypeEnum,
NodeInputKeyEnum,
NodeOutputKeyEnum,
WorkflowIOValueTypeEnum
} from '../../../constants';
import { getHandleConfig } from '../../utils';
@@ -30,5 +35,13 @@ export const LoopStartNode: FlowNodeTemplateType = {
value: ''
}
],
outputs: []
outputs: [
{
id: NodeOutputKeyEnum.loopArrayIndex,
key: NodeOutputKeyEnum.loopArrayIndex,
label: i18nT('workflow:Array_element_index'),
type: FlowNodeOutputTypeEnum.static,
valueType: WorkflowIOValueTypeEnum.number
}
]
};

View File

@@ -43,6 +43,7 @@ export const dispatchLoop = async (props: Props): Promise<Response> => {
let totalPoints = 0;
let newVariables: Record<string, any> = props.variables;
let index = 0;
for await (const item of loopInputArray.filter(Boolean)) {
runtimeNodes.forEach((node) => {
if (
@@ -50,14 +51,21 @@ export const dispatchLoop = async (props: Props): Promise<Response> => {
node.flowNodeType === FlowNodeTypeEnum.loopStart
) {
node.isEntry = true;
node.inputs = node.inputs.map((input) =>
input.key === NodeInputKeyEnum.loopStartInput
? {
...input,
value: item
}
: input
);
node.inputs = node.inputs.map((input) => {
if (input.key === NodeInputKeyEnum.loopStartInput) {
return {
...input,
value: item
};
} else if (input.key === NodeInputKeyEnum.loopStartInput) {
return {
...input,
value: index++
};
} else {
return input;
}
});
}
});
const response = await dispatchWorkFlow({

View File

@@ -1,5 +1,6 @@
{
"Array_element": "Array element",
"Array_element_index": "Index",
"Code": "Code",
"Confirm_sync_node": "It will be updated to the latest node configuration and fields that do not exist in the template will be deleted (including all custom fields).\n\nIf the fields are complex, it is recommended that you copy a node first and then update the original node to facilitate parameter copying.",
"Node.Open_Node_Course": "Open node course",

View File

@@ -1,5 +1,6 @@
{
"Array_element": "数组元素",
"Array_element_index": "下标",
"Code": "代码",
"Confirm_sync_node": "将会更新至最新的节点配置,不存在模板中的字段将会被删除(包括所有自定义字段)。\n如果字段较为复杂建议您先复制一份节点再更新原来的节点便于参数复制。",
"Node.Open_Node_Course": "查看节点教程",