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