import { Col, Row } from 'knowdesign'; import { IconFont } from '@knowdesign/icons'; import React from 'react'; import { SortableContainer, SortableContainerProps, SortableHandle, SortableElement, SortableElementProps } from 'react-sortable-hoc'; import './index.less'; interface PropsType extends React.HTMLAttributes { children: React.ReactNode; sortableContainerProps?: SortableContainerProps; gridProps?: { span: number; gutter: [number, number]; }; dragItemProps?: Omit; } interface SortableItemProps { useDragHandle?: boolean; span: number; } // 拖拽容器 const DragContainer = SortableContainer(({ children, gutter }: any) => ( {children} )); // 拖拽按钮 const DragHandle = SortableHandle(() => ); // 拖拽项 const SortableItem = SortableElement( ({ children, sortableItemProps }: { children: React.ReactNode; sortableItemProps: SortableItemProps }) => ( {sortableItemProps?.useDragHandle && } {children} ) ); const DragGroup: React.FC = ({ children, gridProps = { span: 8, gutter: [10, 10] }, sortableContainerProps }) => { return ( {React.Children.map(children, (child: any, index: number) => { // 如果传入 child 有 key 值就复用,没有的话使用 index 作为 key const key = typeof child === 'object' && child !== null ? child.key || index : index; return ( {child} ); })} ); }; export default DragGroup;