From d026303395e73223faa11aeb30a86bc202427aae Mon Sep 17 00:00:00 2001 From: "bai.zixv" Date: Mon, 15 Jul 2024 11:51:54 +0800 Subject: [PATCH] fix: data-mapping, fixed no data source (#1315) Reviewed-on: https://git.daoyoucloud.com/daoyoucloud/tachybase/pulls/1315 Co-authored-by: bai.zixv Co-committed-by: bai.zixv --- .../data-mapping/DataMapping.instruction.ts | 36 ++++++++++++------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/packages/plugins/@tachybase/plugin-workflow/src/server/features/data-mapping/DataMapping.instruction.ts b/packages/plugins/@tachybase/plugin-workflow/src/server/features/data-mapping/DataMapping.instruction.ts index 8afe0e20b..cf1bb2938 100644 --- a/packages/plugins/@tachybase/plugin-workflow/src/server/features/data-mapping/DataMapping.instruction.ts +++ b/packages/plugins/@tachybase/plugin-workflow/src/server/features/data-mapping/DataMapping.instruction.ts @@ -12,19 +12,29 @@ export class DataMappingInstruction extends Instruction { const { sourceArray, type, code = '', model } = node.config; // 1. 获取数据源 let data = {}; - if (sourceArray.length > 1) { - // 多个数据源, 进行合并 - data = sourceArray.reduce( - (cookedData, { keyName, sourcePath }) => ({ - ...cookedData, - [keyName]: processor.getParsedValue(sourcePath, node.id), - }), - {}, - ); - } else { - // 单数据源, 平铺为单对象 - const source = sourceArray[0]['sourcePath']; - data = processor.getParsedValue(source, node.id); + + switch (sourceArray.length) { + case 0: { + // 无数据源,使用默认值 + data = {}; + break; + } + case 1: { + // 单数据源, 平铺为单对象; 忽略keyName + const source = sourceArray[0]['sourcePath']; + data = processor.getParsedValue(source, node.id); + break; + } + default: { + // 多个数据源, 进行合并 + data = sourceArray.reduce( + (cookedData, { keyName, sourcePath }) => ({ + ...cookedData, + [keyName]: processor.getParsedValue(sourcePath, node.id), + }), + {}, + ); + } } try {