Showing
1 changed file
with
33 additions
and
32 deletions
... | ... | @@ -43,6 +43,7 @@ export const getParentNodes = ( |
43 | 43 | allNodes = getNodesMap(treeNodes!), |
44 | 44 | ) => { |
45 | 45 | if (!node || !treeNodes) return []; |
46 | + | |
46 | 47 | if (node.previousId) { |
47 | 48 | parentNode.unshift(allNodes[node.previousId]); |
48 | 49 | getParentNodes(allNodes[node.previousId], treeNodes, parentNode, allNodes); |
... | ... | @@ -96,9 +97,10 @@ export const useNodeFieldDisplay = ({ |
96 | 97 | (node) => !['default_DF_BRANCH'].includes(node.type), |
97 | 98 | ) || [], |
98 | 99 | ); |
100 | + | |
99 | 101 | const [inputDisplay, setInputDisplay] = useState<React.ReactNode>(); |
100 | 102 | const [optionalNodes, setOptionalNodes] = useState<FiledType[]>([]); // 根据 fieldType 过滤后的 nodes |
101 | - const displayResolved = useRef<boolean>(false) | |
103 | + const displayResolved = useRef<boolean>(false); | |
102 | 104 | |
103 | 105 | const getResultFieldMap = (optionalNodes: FiledType[]) => { |
104 | 106 | const resultMap: Record<string, FiledType | INode> = {}; |
... | ... | @@ -160,12 +162,11 @@ export const useNodeFieldDisplay = ({ |
160 | 162 | |
161 | 163 | const getDisplayConfig = async (val = value): Promise<FiledType[]> => { |
162 | 164 | return new Promise((resolve, reject) => { |
163 | - if (displayResolved.current) resolve(handleGetDisplayConfig(val!)) | |
165 | + if (displayResolved.current) resolve(handleGetDisplayConfig(val!)); | |
164 | 166 | resolveDisplayConfig.current = () => { |
165 | 167 | try { |
166 | - console.log('handleGetDisplayConfig'); | |
167 | 168 | resolve(handleGetDisplayConfig(val!)); |
168 | - displayResolved.current = true | |
169 | + displayResolved.current = true; | |
169 | 170 | } catch (error) { |
170 | 171 | reject(error); |
171 | 172 | } |
... | ... | @@ -175,7 +176,6 @@ export const useNodeFieldDisplay = ({ |
175 | 176 | |
176 | 177 | const genDisplayDom = async (val = value) => { |
177 | 178 | const displayConfig = await getDisplayConfig(val); |
178 | - console.log('displayConfig', displayConfig); | |
179 | 179 | return ( |
180 | 180 | <> |
181 | 181 | {displayConfig?.map?.((item, idx) => ( |
... | ... | @@ -279,26 +279,31 @@ export const useNodeFieldDisplay = ({ |
279 | 279 | const data = await getAppsFields(ids as any[]); |
280 | 280 | Object.keys(data).forEach((id) => { |
281 | 281 | // 此处是引用类型,会间接修改 sourceParentNodes |
282 | - const form = forms.find((item) => item.qxProps?.formId === id); | |
283 | - if (!form) return; | |
284 | - | |
285 | - const childItem = data[id].map((item: FiledType) => ({ | |
286 | - ...item, | |
287 | - icon: ( | |
288 | - <span className="qx-node-select-item__icon"> | |
289 | - <QxWidgetIcon widgetName={item.extract?.widget || 'qxInput'} /> | |
290 | - </span> | |
291 | - ), | |
292 | - title: item.name, | |
293 | - id: item.code, | |
294 | - type: item.extract?.fieldType, | |
295 | - })); | |
296 | - | |
297 | - if (Array.isArray(form.child)) { | |
298 | - form.child.push(childItem); | |
299 | - } else { | |
300 | - form.child = childItem; | |
301 | - } | |
282 | + const targetForms = forms.filter( | |
283 | + (item) => item.qxProps?.formId === id, | |
284 | + ); | |
285 | + if (!targetForms.length) return; | |
286 | + targetForms.forEach((form) => { | |
287 | + const childItem = data[id].map((item: FiledType) => ({ | |
288 | + ...item, | |
289 | + icon: ( | |
290 | + <span className="qx-node-select-item__icon"> | |
291 | + <QxWidgetIcon | |
292 | + widgetName={item.extract?.widget || 'qxInput'} | |
293 | + /> | |
294 | + </span> | |
295 | + ), | |
296 | + title: item.name, | |
297 | + id: item.code, | |
298 | + type: item.extract?.fieldType, | |
299 | + })); | |
300 | + | |
301 | + if (Array.isArray(form.child)) { | |
302 | + form.child.push(childItem); | |
303 | + } else { | |
304 | + form.child = childItem; | |
305 | + } | |
306 | + }); | |
302 | 307 | }); |
303 | 308 | } catch (error) { |
304 | 309 | console.error(error); |
... | ... | @@ -373,7 +378,8 @@ export const useNodeFieldDisplay = ({ |
373 | 378 | */ |
374 | 379 | const getOptionalNodes = async () => { |
375 | 380 | const _targetParentNodes = await handleFormTypeAddChild(); // 给 form 类型的字段添加 child |
376 | - let newNodes = correctionNode(_targetParentNodes); | |
381 | + const correctedNodes = correctionNode(_targetParentNodes) || []; | |
382 | + let newNodes: FiledType[] = correctedNodes.filter(i => !!i.child); | |
377 | 383 | |
378 | 384 | /** |
379 | 385 | * 根据 limitType 获取可选择的字段 |
... | ... | @@ -396,9 +402,7 @@ export const useNodeFieldDisplay = ({ |
396 | 402 | ) |
397 | 403 | ) { |
398 | 404 | newResult.push(resultItem); |
399 | - } | |
400 | - | |
401 | - if (Array.isArray(resultItem.child) && resultItem.child.length) { | |
405 | + } else if (Array.isArray(resultItem.child) && resultItem.child.length) { | |
402 | 406 | const child = getEffectiveResult(resultItem.child); |
403 | 407 | if (child && child.length) { |
404 | 408 | resultItem.child = child; |
... | ... | @@ -427,7 +431,6 @@ export const useNodeFieldDisplay = ({ |
427 | 431 | newNodes = getEffectiveNodes(cloneDeep(newNodes)); |
428 | 432 | } |
429 | 433 | |
430 | - // console.log('newNodes', newNodes); | |
431 | 434 | setOptionalNodes(newNodes); |
432 | 435 | resultFieldMap.current = getResultFieldMap(newNodes); |
433 | 436 | resolveFieldResultMap.current?.(resultFieldMap.current); |
... | ... | @@ -613,8 +616,6 @@ export const QxFlowNodeFieldSelector = React.forwardRef< |
613 | 616 | getInputDisplay: () => inputDisplay, |
614 | 617 | })); |
615 | 618 | |
616 | - console.log('resultFieldMap', resultFieldMap, inputDisplay); | |
617 | - | |
618 | 619 | return ( |
619 | 620 | <div |
620 | 621 | className={cls('qx-node-select')} | ... | ... |