import { Space } from 'antd'; import classNames from 'classnames'; import React, { memo } from 'react'; import { shallow } from 'zustand/shallow'; import SourceHandle from '../../components/CustomNode/sourceHandle'; import TextEllipsis from '../../components/TextEllipsis'; import { useStore } from '../../hooks/useStore'; import { uuid } from '../../utils'; import './index.less'; export default memo((props: any) => { const { data, position, isConnectable, selected, isHovered, handleAddNode, CustomNodeWidget, isSwitchBottom, nodeSetting, id, } = props; const { switchExtra } = nodeSetting; const { nodes, edges } = useStore( (state: any) => ({ nodes: state.nodes, edges: state.edges, }), shallow ); const renderTitle = (item, index) => { const defTitle = item?.title || `条件${index}`; const title = switchExtra?.titleKey ? item[switchExtra?.titleKey] : defTitle; return (
{title}
flow?.sourceHandle === item?._id) ?.length === 0 } selected={selected} isHovered={isHovered} handleAddNode={data => { handleAddNode(data, item?._id); }} id={item?._id} className="item-handle" isConnected={ (edges || [])?.filter(flow => flow?.sourceHandle === item?._id) ?.length > 0 } nodeType={'switch'} />
); }; const renderContent = (item, index) => { const value = switchExtra?.valueKey ? item[switchExtra?.valueKey] : item?.value; return (
{CustomNodeWidget ? ( ) : (
{value && (
)}
)}
); }; return ( {(data?.list || [{ _id: `id_${uuid()}` }])?.map((item, index) => (
{isSwitchBottom ? ( <> {renderContent(item, index)} {renderTitle(item, index)} ) : ( <> {renderTitle(item, index)} {renderContent(item, index)} )}
))} {!switchExtra?.hideElse && (
默认
flow?.sourceHandle === 'id_else' && flow?.source === id )?.length === 0 } selected={selected} isHovered={isHovered} handleAddNode={data => { handleAddNode(data, 'id_else'); }} className="item-handle" id={'id_else'} isConnected={ (edges || [])?.filter( flow => flow?.sourceHandle === 'id_else' && flow?.source === id )?.length > 0 } nodeType={'Switch'} />
)}
); });