Commit fe97cd47c3d1d03e0a88b164815ad30e76dd5e20
Merge branch 'feature/dataflow' of http://gitlab.qgutech.com/tianqiang/qx-common…
… into feature/dataflow
Showing
1 changed file
with
33 additions
and
32 deletions
@@ -43,6 +43,7 @@ export const getParentNodes = ( | @@ -43,6 +43,7 @@ export const getParentNodes = ( | ||
43 | allNodes = getNodesMap(treeNodes!), | 43 | allNodes = getNodesMap(treeNodes!), |
44 | ) => { | 44 | ) => { |
45 | if (!node || !treeNodes) return []; | 45 | if (!node || !treeNodes) return []; |
46 | + | ||
46 | if (node.previousId) { | 47 | if (node.previousId) { |
47 | parentNode.unshift(allNodes[node.previousId]); | 48 | parentNode.unshift(allNodes[node.previousId]); |
48 | getParentNodes(allNodes[node.previousId], treeNodes, parentNode, allNodes); | 49 | getParentNodes(allNodes[node.previousId], treeNodes, parentNode, allNodes); |
@@ -96,9 +97,10 @@ export const useNodeFieldDisplay = ({ | @@ -96,9 +97,10 @@ export const useNodeFieldDisplay = ({ | ||
96 | (node) => !['default_DF_BRANCH'].includes(node.type), | 97 | (node) => !['default_DF_BRANCH'].includes(node.type), |
97 | ) || [], | 98 | ) || [], |
98 | ); | 99 | ); |
100 | + | ||
99 | const [inputDisplay, setInputDisplay] = useState<React.ReactNode>(); | 101 | const [inputDisplay, setInputDisplay] = useState<React.ReactNode>(); |
100 | const [optionalNodes, setOptionalNodes] = useState<FiledType[]>([]); // 根据 fieldType 过滤后的 nodes | 102 | const [optionalNodes, setOptionalNodes] = useState<FiledType[]>([]); // 根据 fieldType 过滤后的 nodes |
101 | - const displayResolved = useRef<boolean>(false) | 103 | + const displayResolved = useRef<boolean>(false); |
102 | 104 | ||
103 | const getResultFieldMap = (optionalNodes: FiledType[]) => { | 105 | const getResultFieldMap = (optionalNodes: FiledType[]) => { |
104 | const resultMap: Record<string, FiledType | INode> = {}; | 106 | const resultMap: Record<string, FiledType | INode> = {}; |
@@ -160,12 +162,11 @@ export const useNodeFieldDisplay = ({ | @@ -160,12 +162,11 @@ export const useNodeFieldDisplay = ({ | ||
160 | 162 | ||
161 | const getDisplayConfig = async (val = value): Promise<FiledType[]> => { | 163 | const getDisplayConfig = async (val = value): Promise<FiledType[]> => { |
162 | return new Promise((resolve, reject) => { | 164 | return new Promise((resolve, reject) => { |
163 | - if (displayResolved.current) resolve(handleGetDisplayConfig(val!)) | 165 | + if (displayResolved.current) resolve(handleGetDisplayConfig(val!)); |
164 | resolveDisplayConfig.current = () => { | 166 | resolveDisplayConfig.current = () => { |
165 | try { | 167 | try { |
166 | - console.log('handleGetDisplayConfig'); | ||
167 | resolve(handleGetDisplayConfig(val!)); | 168 | resolve(handleGetDisplayConfig(val!)); |
168 | - displayResolved.current = true | 169 | + displayResolved.current = true; |
169 | } catch (error) { | 170 | } catch (error) { |
170 | reject(error); | 171 | reject(error); |
171 | } | 172 | } |
@@ -175,7 +176,6 @@ export const useNodeFieldDisplay = ({ | @@ -175,7 +176,6 @@ export const useNodeFieldDisplay = ({ | ||
175 | 176 | ||
176 | const genDisplayDom = async (val = value) => { | 177 | const genDisplayDom = async (val = value) => { |
177 | const displayConfig = await getDisplayConfig(val); | 178 | const displayConfig = await getDisplayConfig(val); |
178 | - console.log('displayConfig', displayConfig); | ||
179 | return ( | 179 | return ( |
180 | <> | 180 | <> |
181 | {displayConfig?.map?.((item, idx) => ( | 181 | {displayConfig?.map?.((item, idx) => ( |
@@ -279,26 +279,31 @@ export const useNodeFieldDisplay = ({ | @@ -279,26 +279,31 @@ export const useNodeFieldDisplay = ({ | ||
279 | const data = await getAppsFields(ids as any[]); | 279 | const data = await getAppsFields(ids as any[]); |
280 | Object.keys(data).forEach((id) => { | 280 | Object.keys(data).forEach((id) => { |
281 | // 此处是引用类型,会间接修改 sourceParentNodes | 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 | } catch (error) { | 308 | } catch (error) { |
304 | console.error(error); | 309 | console.error(error); |
@@ -373,7 +378,8 @@ export const useNodeFieldDisplay = ({ | @@ -373,7 +378,8 @@ export const useNodeFieldDisplay = ({ | ||
373 | */ | 378 | */ |
374 | const getOptionalNodes = async () => { | 379 | const getOptionalNodes = async () => { |
375 | const _targetParentNodes = await handleFormTypeAddChild(); // 给 form 类型的字段添加 child | 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 | * 根据 limitType 获取可选择的字段 | 385 | * 根据 limitType 获取可选择的字段 |
@@ -396,9 +402,7 @@ export const useNodeFieldDisplay = ({ | @@ -396,9 +402,7 @@ export const useNodeFieldDisplay = ({ | ||
396 | ) | 402 | ) |
397 | ) { | 403 | ) { |
398 | newResult.push(resultItem); | 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 | const child = getEffectiveResult(resultItem.child); | 406 | const child = getEffectiveResult(resultItem.child); |
403 | if (child && child.length) { | 407 | if (child && child.length) { |
404 | resultItem.child = child; | 408 | resultItem.child = child; |
@@ -427,7 +431,6 @@ export const useNodeFieldDisplay = ({ | @@ -427,7 +431,6 @@ export const useNodeFieldDisplay = ({ | ||
427 | newNodes = getEffectiveNodes(cloneDeep(newNodes)); | 431 | newNodes = getEffectiveNodes(cloneDeep(newNodes)); |
428 | } | 432 | } |
429 | 433 | ||
430 | - // console.log('newNodes', newNodes); | ||
431 | setOptionalNodes(newNodes); | 434 | setOptionalNodes(newNodes); |
432 | resultFieldMap.current = getResultFieldMap(newNodes); | 435 | resultFieldMap.current = getResultFieldMap(newNodes); |
433 | resolveFieldResultMap.current?.(resultFieldMap.current); | 436 | resolveFieldResultMap.current?.(resultFieldMap.current); |
@@ -613,8 +616,6 @@ export const QxFlowNodeFieldSelector = React.forwardRef< | @@ -613,8 +616,6 @@ export const QxFlowNodeFieldSelector = React.forwardRef< | ||
613 | getInputDisplay: () => inputDisplay, | 616 | getInputDisplay: () => inputDisplay, |
614 | })); | 617 | })); |
615 | 618 | ||
616 | - console.log('resultFieldMap', resultFieldMap, inputDisplay); | ||
617 | - | ||
618 | return ( | 619 | return ( |
619 | <div | 620 | <div |
620 | className={cls('qx-node-select')} | 621 | className={cls('qx-node-select')} |