diff --git a/packages/plugins/@nocobase/plugin-workflow/src/client/nodes/loop.tsx b/packages/plugins/@nocobase/plugin-workflow/src/client/nodes/loop.tsx index 927d0e4bc3..e05c1ad026 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/client/nodes/loop.tsx +++ b/packages/plugins/@nocobase/plugin-workflow/src/client/nodes/loop.tsx @@ -8,7 +8,14 @@ import { Branch } from '../Branch'; import { useFlowContext } from '../FlowContext'; import { NAMESPACE, lang } from '../locale'; import useStyles from '../style'; -import { VariableOption, WorkflowVariableInput, defaultFieldNames, nodesOptions, triggerOptions } from '../variable'; +import { + VariableOption, + WorkflowVariableInput, + defaultFieldNames, + nodesOptions, + scopeOptions, + triggerOptions, +} from '../variable'; function findOption(options: VariableOption[], paths: string[]) { let opts = options; @@ -121,8 +128,8 @@ export default { .split('.') .map((path) => path.trim()); - const targetOptions = [nodesOptions, triggerOptions].map((item: any) => { - const opts = item.useOptions(options).filter(Boolean); + const targetOptions = [scopeOptions, nodesOptions, triggerOptions].map((item: any) => { + const opts = item.useOptions({ ...options, current: node }).filter(Boolean); return { [fieldNames.label]: compile(item.label), [fieldNames.value]: item.value, diff --git a/packages/plugins/@nocobase/plugin-workflow/src/client/variable.tsx b/packages/plugins/@nocobase/plugin-workflow/src/client/variable.tsx index 41cf02c28e..e57f7a891b 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/client/variable.tsx +++ b/packages/plugins/@nocobase/plugin-workflow/src/client/variable.tsx @@ -34,6 +34,7 @@ export type OptionsOfUseVariableOptions = { }; appends?: string[] | null; depth?: number; + current?: any; }; export const defaultFieldNames = { label: 'label', value: 'value', children: 'children' } as const; @@ -70,9 +71,10 @@ export const scopeOptions = { label: `{{t("Scope variables", { ns: "${NAMESPACE}" })}}`, value: '$scopes', useOptions(options: OptionsOfUseVariableOptions) { - const { fieldNames = defaultFieldNames } = options; - const current = useNodeContext(); - const scopes = useUpstreamScopes(current); + const { fieldNames = defaultFieldNames, current } = options; + const source = useNodeContext(); + const from = current ?? source; + const scopes = useUpstreamScopes(from); const result: VariableOption[] = []; scopes.forEach((node) => { const instruction = instructions.get(node.type);