Showing
1 changed file
with
29 additions
and
12 deletions
@@ -93,6 +93,7 @@ export const useNodeFieldDisplay = ({ | @@ -93,6 +93,7 @@ export const useNodeFieldDisplay = ({ | ||
93 | (node) => !['default_DF_BRANCH'].includes(node.type), | 93 | (node) => !['default_DF_BRANCH'].includes(node.type), |
94 | ) || [], | 94 | ) || [], |
95 | ); | 95 | ); |
96 | + const [targetParentNodes, setTargetParentNodes] = useState<INode[]>([]); | ||
96 | 97 | ||
97 | const [inputDisplay, setInputDisplay] = useState<React.ReactNode>(); | 98 | const [inputDisplay, setInputDisplay] = useState<React.ReactNode>(); |
98 | const [optionalNodes, setOptionalNodes] = useState<FiledType[]>([]); // 根据 fieldType 过滤后的 nodes | 99 | const [optionalNodes, setOptionalNodes] = useState<FiledType[]>([]); // 根据 fieldType 过滤后的 nodes |
@@ -294,6 +295,8 @@ export const useNodeFieldDisplay = ({ | @@ -294,6 +295,8 @@ export const useNodeFieldDisplay = ({ | ||
294 | console.error(error); | 295 | console.error(error); |
295 | } | 296 | } |
296 | } | 297 | } |
298 | + | ||
299 | + setTargetParentNodes(sourceParentNodes); | ||
297 | return sourceParentNodes; | 300 | return sourceParentNodes; |
298 | }; | 301 | }; |
299 | 302 | ||
@@ -366,15 +369,19 @@ export const useNodeFieldDisplay = ({ | @@ -366,15 +369,19 @@ export const useNodeFieldDisplay = ({ | ||
366 | /** | 369 | /** |
367 | * 根据 limitType 获取可选择的字段 | 370 | * 根据 limitType 获取可选择的字段 |
368 | */ | 371 | */ |
369 | - function getEffectiveResult(result: FiledType[]) { | 372 | + function getEffectiveResult(child: FiledType[]) { |
370 | const newResult = []; | 373 | const newResult = []; |
371 | 374 | ||
372 | - for (let i = 0; i < result.length; i++) { | ||
373 | - const resultItem = result[i] || {}; | 375 | + for (let i = 0; i < child.length; i++) { |
376 | + const resultItem = child[i] || {}; | ||
374 | 377 | ||
378 | + const _limitTypes = limitTypes?.map( | ||
379 | + (limit) => | ||
380 | + FieldBaseType[limit as keyof typeof FieldBaseType] || limit, | ||
381 | + ); | ||
375 | if ( | 382 | if ( |
376 | // 先将表单字段类型或流程参数类型转换为基础类型再做过滤 | 383 | // 先将表单字段类型或流程参数类型转换为基础类型再做过滤 |
377 | - limitTypes?.includes( | 384 | + _limitTypes?.includes( |
378 | FieldBaseType[resultItem.type as keyof typeof FieldBaseType] || | 385 | FieldBaseType[resultItem.type as keyof typeof FieldBaseType] || |
379 | resultItem.type, | 386 | resultItem.type, |
380 | ) | 387 | ) |
@@ -383,28 +390,32 @@ export const useNodeFieldDisplay = ({ | @@ -383,28 +390,32 @@ export const useNodeFieldDisplay = ({ | ||
383 | } | 390 | } |
384 | 391 | ||
385 | if (Array.isArray(resultItem.child) && resultItem.child.length) { | 392 | if (Array.isArray(resultItem.child) && resultItem.child.length) { |
386 | - resultItem.child = getEffectiveResult(resultItem.child); | 393 | + const child = getEffectiveResult(resultItem.child); |
394 | + if (child && child.length) { | ||
395 | + resultItem.child = child | ||
396 | + newResult.push(resultItem); | ||
397 | + } | ||
387 | } | 398 | } |
388 | } | 399 | } |
389 | 400 | ||
390 | return newResult; | 401 | return newResult; |
391 | } | 402 | } |
392 | 403 | ||
393 | - function getEffectiveNodes(nodes: INode[]) { | 404 | + function getEffectiveNodes(nodes: FiledType[]) { |
394 | for (let i = 0; i <= nodes.length; i++) { | 405 | for (let i = 0; i <= nodes.length; i++) { |
395 | const node = nodes[i] || {}; | 406 | const node = nodes[i] || {}; |
396 | - const nodeResult = node.data?.result; | ||
397 | - if (Array.isArray(nodeResult) && nodeResult.length) { | ||
398 | - node.data.result = getEffectiveResult(nodeResult); | 407 | + const child = node.child; |
408 | + if (Array.isArray(child) && child.length) { | ||
409 | + node.child = getEffectiveResult(child); | ||
399 | } | 410 | } |
400 | } | 411 | } |
401 | 412 | ||
402 | - return nodes as unknown as FiledType[]; | 413 | + return nodes; |
403 | } | 414 | } |
404 | 415 | ||
405 | // 有类型限制根据 limitType 筛选出可选的节点和 result | 416 | // 有类型限制根据 limitType 筛选出可选的节点和 result |
406 | if (limitTypes && Array.isArray(limitTypes) && limitTypes.length) { | 417 | if (limitTypes && Array.isArray(limitTypes) && limitTypes.length) { |
407 | - newNodes = getEffectiveNodes(targetParentNodes); | 418 | + newNodes = getEffectiveNodes(cloneDeep(newNodes)); |
408 | } | 419 | } |
409 | 420 | ||
410 | setOptionalNodes(newNodes); | 421 | setOptionalNodes(newNodes); |
@@ -424,6 +435,10 @@ export const useNodeFieldDisplay = ({ | @@ -424,6 +435,10 @@ export const useNodeFieldDisplay = ({ | ||
424 | }); | 435 | }); |
425 | }; | 436 | }; |
426 | 437 | ||
438 | + // useEffect(() => { | ||
439 | + // handleFormTypeAddChild(); // 给 form 类型的字段添加 child | ||
440 | + // }, []) | ||
441 | + | ||
427 | useEffect(() => { | 442 | useEffect(() => { |
428 | getOptionalNodes(); | 443 | getOptionalNodes(); |
429 | }, []); | 444 | }, []); |
@@ -622,7 +637,9 @@ export const QxFlowNodeFieldSelector = React.forwardRef< | @@ -622,7 +637,9 @@ export const QxFlowNodeFieldSelector = React.forwardRef< | ||
622 | props.children | 637 | props.children |
623 | ) : ( | 638 | ) : ( |
624 | <div | 639 | <div |
625 | - className={cls(`qx-node-select-input ${props?.disabled ? 'disabled' : null}`)} | 640 | + className={cls( |
641 | + `qx-node-select-input ${props?.disabled ? 'disabled' : null}`, | ||
642 | + )} | ||
626 | onClick={() => setVisible(!visible)} | 643 | onClick={() => setVisible(!visible)} |
627 | > | 644 | > |
628 | {/* {inputDisplay} */} | 645 | {/* {inputDisplay} */} |