import React, { ReactNode, useMemo, useRef } from 'react'; import Icon from '../Icon/index'; import { Tree, Tooltip, Popover } from 'antd'; function LargeScreenComponentTree(props: ILargeScreenComponentTree) { const { list, autoExpandParent, expandedKeys, change, styles,height } = props; const dragDom = useRef(null); const onExpand = (expandedKeys) => { change?.(expandedKeys, 'treeExpand'); }; //树的点击事件 const clickTree = (item: IList, type: string) => { change?.(item, type); }; //拖拽事件 const drag = (e: React.DragEvent, item: IList) => { e.stopPropagation(); let itemObj = { url: item?.url, key: item?.key, title: item?.title, type: item?.type, componentType: item?.componentType }; e.dataTransfer.dropEffect = 'copy'; e.dataTransfer.setData('text/plain', JSON.stringify(itemObj)); change?.(JSON.stringify(itemObj), 'cardStart'); }; //处理树的数据 const treeData = (list) => { let newList = Array.isArray(list) && list?.length > 0 && list?.map((item, index) => { if (item?.children?.length > 0) { return { title: ( {item?.title} ), key: item?.key, icon: typeof item?.icon === 'string' ? ( ) : ( item?.icon ), children: treeData(item?.children) }; } else { if (item.type === 'folder') { return { title: typeof item?.title === 'string' ? ( {item?.title} ) : ( item.title ), key: item?.key, icon: typeof item?.icon === 'string' ? ( ) : ( item?.icon ), children: [] }; } else { return { title: typeof item?.title === 'string' ? (
{item?.title}
) : ( item?.url ) } > { clickTree(item, 'clickTree'); }} onDragStart={(e) => { drag(e, item); }} > {typeof item?.title === 'string' ? ( {item?.title} ) : ( item?.title )}
) : ( item?.title ), key: item?.key, icon: typeof item?.icon === 'string' ? ( { clickTree(item.key, 'clickTree'); }} /> ) : ( item?.icon ), children: [] }; } } }); return newList; }; const Dom = useMemo(() => { return (
{list?.length > 0 ? ( ) : (
暂无图表
)}
); }, [list, autoExpandParent, expandedKeys, styles]); return Dom; } export default LargeScreenComponentTree; export interface ILargeScreenComponentTree { list: IList[]; autoExpandParent?: boolean; expandedKeys?: string[] | number[]; change?: Function; styles?: React.CSSProperties; height?:number } export interface IList { key: string[]; title: string | ReactNode; type?: string; icon?: string | ReactNode; children?: IList[]; url?: string | ReactNode; componentType?: string; }