1
This commit is contained in:
parent
c1ddcce3bc
commit
fc88511544
@ -44,20 +44,11 @@ const NodeConfigDrawer: React.FC<NodeConfigDrawerProps> = ({
|
|||||||
}) => {
|
}) => {
|
||||||
const [panelValues, setPanelValues] = React.useState<Variables>({});
|
const [panelValues, setPanelValues] = React.useState<Variables>({});
|
||||||
const [localValues, setLocalValues] = React.useState<Variables>({});
|
const [localValues, setLocalValues] = React.useState<Variables>({});
|
||||||
const [formValues, setFormValues] = React.useState<Variables>({});
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (nodeDefinition) {
|
if (nodeDefinition) {
|
||||||
console.log('nodeDefinition:', nodeDefinition);
|
|
||||||
// 使用 convertJsonSchemaToColumns 获取字段配置
|
|
||||||
console.log('nodeDefinition.panelVariablesSchema:', JSON.stringify(nodeDefinition.panelVariablesSchema, null, 2));
|
|
||||||
|
|
||||||
// 使用修改后的 schema 获取字段配置
|
// 使用修改后的 schema 获取字段配置
|
||||||
const panelColumns = convertJsonSchemaToColumns(nodeDefinition.panelVariablesSchema || { type: 'object', properties: {} });
|
const panelColumns = convertJsonSchemaToColumns(nodeDefinition.panelVariablesSchema || { type: 'object', properties: {} });
|
||||||
console.log('转换后的 panelColumns:', panelColumns);
|
|
||||||
const localColumns = convertJsonSchemaToColumns(nodeDefinition.localVariablesSchema || { type: 'object', properties: {} });
|
const localColumns = convertJsonSchemaToColumns(nodeDefinition.localVariablesSchema || { type: 'object', properties: {} });
|
||||||
const formColumns = convertJsonSchemaToColumns(nodeDefinition.formVariablesSchema || { type: 'object', properties: {} });
|
|
||||||
|
|
||||||
// 初始化表单值,包括默认值
|
// 初始化表单值,包括默认值
|
||||||
const initialPanelValues = panelColumns.reduce((acc, column) => {
|
const initialPanelValues = panelColumns.reduce((acc, column) => {
|
||||||
if (column.initialValue !== undefined) {
|
if (column.initialValue !== undefined) {
|
||||||
@ -73,12 +64,6 @@ const NodeConfigDrawer: React.FC<NodeConfigDrawerProps> = ({
|
|||||||
return acc;
|
return acc;
|
||||||
}, {} as Variables);
|
}, {} as Variables);
|
||||||
|
|
||||||
const initialFormValues = formColumns.reduce((acc, column) => {
|
|
||||||
if (column.initialValue !== undefined) {
|
|
||||||
acc[column.dataIndex] = column.initialValue;
|
|
||||||
}
|
|
||||||
return acc;
|
|
||||||
}, {} as Variables);
|
|
||||||
// 设置初始值
|
// 设置初始值
|
||||||
setPanelValues({
|
setPanelValues({
|
||||||
...initialPanelValues,
|
...initialPanelValues,
|
||||||
@ -93,10 +78,6 @@ const NodeConfigDrawer: React.FC<NodeConfigDrawerProps> = ({
|
|||||||
...initialLocalValues,
|
...initialLocalValues,
|
||||||
...(nodeDefinition.localVariables || {})
|
...(nodeDefinition.localVariables || {})
|
||||||
});
|
});
|
||||||
setFormValues({
|
|
||||||
...initialFormValues,
|
|
||||||
...(nodeDefinition.formVariables || {})
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}, [nodeDefinition]);
|
}, [nodeDefinition]);
|
||||||
|
|
||||||
@ -104,8 +85,7 @@ const NodeConfigDrawer: React.FC<NodeConfigDrawerProps> = ({
|
|||||||
const updatedNodeDefinition = {
|
const updatedNodeDefinition = {
|
||||||
...nodeDefinition,
|
...nodeDefinition,
|
||||||
panelVariables: panelValues,
|
panelVariables: panelValues,
|
||||||
localVariables: localValues,
|
localVariables: localValues
|
||||||
formVariables: formValues
|
|
||||||
};
|
};
|
||||||
onOk(updatedNodeDefinition);
|
onOk(updatedNodeDefinition);
|
||||||
};
|
};
|
||||||
@ -211,15 +191,6 @@ const NodeConfigDrawer: React.FC<NodeConfigDrawerProps> = ({
|
|||||||
{renderFormFields(nodeDefinition.localVariablesSchema, localValues, handleLocalChange)}
|
{renderFormFields(nodeDefinition.localVariablesSchema, localValues, handleLocalChange)}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
},
|
|
||||||
nodeDefinition?.formVariablesSchema && {
|
|
||||||
key: 'form',
|
|
||||||
label: '表单配置(预览)',
|
|
||||||
children: (
|
|
||||||
<div className="space-y-4">
|
|
||||||
{renderFormFields(nodeDefinition.formVariablesSchema, formValues, handleFormChange)}
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
].filter(Boolean) as TabsProps['items'];
|
].filter(Boolean) as TabsProps['items'];
|
||||||
|
|
||||||
|
|||||||
@ -1055,8 +1055,7 @@ const WorkflowDesign: React.FC = () => {
|
|||||||
node.setProp('graph', {
|
node.setProp('graph', {
|
||||||
uiVariables: existingNode.uiVariables,
|
uiVariables: existingNode.uiVariables,
|
||||||
panelVariables: existingNode.panelVariables,
|
panelVariables: existingNode.panelVariables,
|
||||||
localVariables: existingNode.localVariables,
|
localVariables: existingNode.localVariables
|
||||||
formVariablesSchema: existingNode.formVariablesSchema
|
|
||||||
});
|
});
|
||||||
nodeMap.set(existingNode.id, node);
|
nodeMap.set(existingNode.id, node);
|
||||||
});
|
});
|
||||||
@ -1194,7 +1193,7 @@ const WorkflowDesign: React.FC = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// 首先添加合并 schema 的工具函数
|
// 首先添加合并 schema 的工具函数
|
||||||
const mergeFormVariablesSchemas = (schemas: any[]) => {
|
const mergeLocalVariablesSchemas = (schemas: any[]) => {
|
||||||
// 初始化合并后的 schema
|
// 初始化合并后的 schema
|
||||||
const mergedSchema = {
|
const mergedSchema = {
|
||||||
type: 'object',
|
type: 'object',
|
||||||
@ -1234,7 +1233,7 @@ const WorkflowDesign: React.FC = () => {
|
|||||||
// 处理保存工作流
|
// 处理保存工作流
|
||||||
const handleSaveWorkflow = async () => {
|
const handleSaveWorkflow = async () => {
|
||||||
if (!graph || !definitionData) return;
|
if (!graph || !definitionData) return;
|
||||||
|
console.log(definitionData)
|
||||||
try {
|
try {
|
||||||
// 校验流程图
|
// 校验流程图
|
||||||
const validationResult = validateWorkflow(graph);
|
const validationResult = validateWorkflow(graph);
|
||||||
@ -1247,14 +1246,16 @@ const WorkflowDesign: React.FC = () => {
|
|||||||
const nodes = graph.getNodes().map(node => {
|
const nodes = graph.getNodes().map(node => {
|
||||||
const nodeType = node.getProp('nodeType');
|
const nodeType = node.getProp('nodeType');
|
||||||
const graphData = node.getProp('graph') || {};
|
const graphData = node.getProp('graph') || {};
|
||||||
|
const nodeDefinition = nodeDefinitions.find(def => def.nodeType === nodeType);
|
||||||
const position = node.getPosition();
|
const position = node.getPosition();
|
||||||
|
|
||||||
const {
|
const {
|
||||||
uiVariables,
|
uiVariables,
|
||||||
panelVariables,
|
panelVariables,
|
||||||
localVariables,
|
localVariables,
|
||||||
formVariablesSchema,
|
|
||||||
...rest
|
...rest
|
||||||
} = graphData;
|
} = graphData;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: node.id,
|
id: node.id,
|
||||||
nodeCode: nodeType,
|
nodeCode: nodeType,
|
||||||
@ -1265,8 +1266,7 @@ const WorkflowDesign: React.FC = () => {
|
|||||||
position: position
|
position: position
|
||||||
},
|
},
|
||||||
panelVariables,
|
panelVariables,
|
||||||
localVariables,
|
localVariables: nodeDefinition?.localVariablesSchema || {}
|
||||||
formVariablesSchema
|
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -1288,9 +1288,14 @@ const WorkflowDesign: React.FC = () => {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
// 收集并合并所有节点的 formVariablesSchema
|
// 收集并合并所有节点的 localVariablesSchema
|
||||||
const allFormSchemas = nodes.map(node => node.formVariablesSchema).filter(schema => schema); // 过滤掉空值
|
const allLocalSchemas = nodes
|
||||||
const mergedFormSchema = mergeFormVariablesSchemas(allFormSchemas);
|
.map(node => {
|
||||||
|
const nodeDefinition = nodeDefinitions.find(def => def.nodeType === node.nodeType);
|
||||||
|
return nodeDefinition?.localVariablesSchema;
|
||||||
|
})
|
||||||
|
.filter(schema => schema); // 过滤掉空值
|
||||||
|
const mergedLocalSchema = mergeLocalVariablesSchemas(allLocalSchemas);
|
||||||
|
|
||||||
// 构建保存数据
|
// 构建保存数据
|
||||||
const saveData = {
|
const saveData = {
|
||||||
@ -1299,7 +1304,7 @@ const WorkflowDesign: React.FC = () => {
|
|||||||
nodes,
|
nodes,
|
||||||
edges
|
edges
|
||||||
},
|
},
|
||||||
formVariablesSchema: mergedFormSchema
|
localVariablesSchema: mergedLocalSchema
|
||||||
};
|
};
|
||||||
|
|
||||||
// 调用保存接口
|
// 调用保存接口
|
||||||
|
|||||||
@ -84,11 +84,3 @@ export interface NodeDefinition {
|
|||||||
orderNum: number;
|
orderNum: number;
|
||||||
enabled: boolean;
|
enabled: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 节点列表响应
|
|
||||||
export interface NodeDefinitionResponse {
|
|
||||||
success: boolean;
|
|
||||||
message: string;
|
|
||||||
data: NodeDefinition[];
|
|
||||||
code: number;
|
|
||||||
}
|
|
||||||
|
|||||||
@ -46,7 +46,6 @@ export interface WorkflowDefinitionNode {
|
|||||||
uiVariables: JSON;
|
uiVariables: JSON;
|
||||||
panelVariables: JSON;
|
panelVariables: JSON;
|
||||||
localVariables: JSON;
|
localVariables: JSON;
|
||||||
formVariables: JSON;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface WorkflowDefinitionQuery extends BaseQuery {
|
export interface WorkflowDefinitionQuery extends BaseQuery {
|
||||||
|
|||||||
@ -79,7 +79,6 @@ export interface NodeDesignDataResponse extends BaseResponse {
|
|||||||
description: string;
|
description: string;
|
||||||
panelVariablesSchema: NodeVariablesSchema | null;
|
panelVariablesSchema: NodeVariablesSchema | null;
|
||||||
localVariablesSchema: NodeVariablesSchema | null;
|
localVariablesSchema: NodeVariablesSchema | null;
|
||||||
formVariablesSchema: NodeVariablesSchema | null;
|
|
||||||
uiVariables: UIVariables;
|
uiVariables: UIVariables;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,8 +105,6 @@ export interface NodeDefinitionResponse extends BaseResponse {
|
|||||||
panelVariablesSchema: NodeVariablesSchema | null;
|
panelVariablesSchema: NodeVariablesSchema | null;
|
||||||
uiVariables: UIVariables | null;
|
uiVariables: UIVariables | null;
|
||||||
localVariablesSchema: NodeVariablesSchema | null;
|
localVariablesSchema: NodeVariablesSchema | null;
|
||||||
formVariablesSchema: NodeVariablesSchema | null;
|
|
||||||
panelVariables?: Record<string, any>;
|
panelVariables?: Record<string, any>;
|
||||||
localVariables?: Record<string, any>;
|
localVariables?: Record<string, any>;
|
||||||
formVariables?: Record<string, any>;
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user