import React, { useState } from 'react'; import { SortableContainer, SortableElement, SortableHandle } from 'react-sortable-hoc'; import { MenuOutlined } from '@ant-design/icons'; import type { ProColumns } from '@ant-design/pro-table'; import ProTable from '@ant-design/pro-table'; import arrayMove from 'array-move'; import './drag.less'; const DragHandle = SortableHandle(() => ); const columns: ProColumns[] = [ { title: '排序', dataIndex: 'sort', width: 60, className: 'drag-visible', render: () => , }, { title: '姓名', dataIndex: 'name', className: 'drag-visible', }, { title: '年龄', dataIndex: 'age', }, { title: '地址', dataIndex: 'address', }, ]; const data = [ { key: '1', name: 'John Brown', age: 32, address: 'New York No. 1 Lake Park', index: 0, }, { key: '2', name: 'Jim Green', age: 42, address: 'London No. 1 Lake Park', index: 1, }, { key: '3', name: 'Joe Black', age: 32, address: 'Sidney No. 1 Lake Park', index: 2, }, ]; export default () => { const [dataSource, setDataSource] = useState(data); const SortableItem = SortableElement((props: any) => ); const SortContainer = SortableContainer((props: any) => ); const onSortEnd = ({ oldIndex, newIndex }: { oldIndex: number; newIndex: number }) => { if (oldIndex !== newIndex) { const newData = arrayMove([...dataSource], oldIndex, newIndex).filter((el) => !!el); setDataSource([...newData]); } }; const DraggableContainer = (props: any) => ( ); const DraggableBodyRow = (props: any) => { const { className, style, ...restProps } = props; // function findIndex base on Table rowKey props and should always be a right array index const index = dataSource.findIndex((x) => x.index === restProps['data-row-key']); return ; }; return ( ); };