import React, { useEffect } from 'react'; import { Input, Tooltip, Menu, Dropdown, Popover, Checkbox, Tree } from 'antd'; import { configItem } from '..'; export interface IProps { onSearch: ( value: any, event?: | React.ChangeEvent | React.MouseEvent | React.KeyboardEvent, ) => void; toolBarRender?: React.ReactNode[]; configs?: configItem[]; tablesize: string; handleChangeSize: (item?: object) => void; columns?: any; plainOptions?: any; checkedOptions?: any; handleCheckColumns?: (e: any) => void; handleNewDrop?: (data: any) => void; handleClickToolbar?: (key: string) => void; } const TableToolbar: React.FC = (props: IProps) => { const { Search } = Input; const { onSearch, handleChangeSize, handleCheckColumns, handleNewDrop, handleClickToolbar, toolBarRender, configs = [], tablesize, plainOptions, checkedOptions, } = props; const lineHeightMenu = ( 默认 中等 正常 ); const onSelectAll = (e: any) => { let keys = []; if (e.target.checked) { keys = plainOptions.map((item: any) => item.key); } if (handleCheckColumns) handleCheckColumns({ checked: keys }); }; const PopoverTitle = (
0 && checkedOptions.length === plainOptions.length } indeterminate={ checkedOptions.length > 0 && checkedOptions.length !== plainOptions.length } onChange={onSelectAll} > 列展示
{/* 重置 */}
); const handleDrop = (info: any) => { const dropKey = info.node.key; const dragKey = info.dragNode.key; const dropPos = info.node.pos.split('-'); const dropPosition = info.dropPosition - Number(dropPos[dropPos.length - 1]); const loop = (data: any, key: any, callback: Function) => { for (let i = 0; i < data.length; i++) { if (data[i].key === key) { return callback(data[i], i, data); } if (data[i].children) { loop(data[i].children, key, callback); } } }; const data = [...plainOptions]; let dragObj: any; loop(data, dragKey, (item: any, index: any, arr: any) => { arr.splice(index, 1); dragObj = item; }); if (!info.dropToGap) { // Drop on the content loop(data, dropKey, (item: { children: any[] }) => { item.children = item.children || []; // where to insert 示例添加到头部,可以是随意位置 item.children.unshift(dragObj); }); } else if ( (info.node.props.children || []).length > 0 && // Has children info.node.props.expanded && // Is expanded dropPosition === 1 // On the bottom gap ) { loop(data, dropKey, (item: { children: any[] }) => { item.children = item.children || []; // where to insert 示例添加到头部,可以是随意位置 item.children.unshift(dragObj); }); } else { let ar: any; let i: any; loop(data, dropKey, (item: any, index: any, arr: any) => { ar = arr; i = index; }); if (dropPosition === -1) { ar.splice(i, 0, dragObj); } else { ar.splice(i + 1, 0, dragObj); } } if (handleNewDrop) handleNewDrop(data); }; const newConfigs = configs.map(item => ({ ...item, render: item.render || (node => node), })); const searchConfig = newConfigs.find(item => item.text == '搜索'); const refreshConfig = newConfigs.find(item => item.text == '刷新'); const LineHeightConfig = newConfigs.find(item => item.text == '行高'); const exportConfig = newConfigs.find(item => item.text == '导出'); const setUpConfig = newConfigs.find(item => item.text == '设置'); return ( <>
{toolBarRender && toolBarRender?.length > 0 ? ( toolBarRender.map((item: any, index: number) => { return (
{item}
); }) ) : (
{toolBarRender}
)}
{searchConfig?.text == '搜索' ? searchConfig.render(
, ) : null} {refreshConfig?.text == '刷新' ? refreshConfig.render( , ) : null} {LineHeightConfig?.text == '行高' ? LineHeightConfig.render( , ) : null} {exportConfig?.text == '导出' ? exportConfig.render( , ) : null} {setUpConfig?.text == '设置' ? setUpConfig.render( } checkedKeys={checkedOptions} titleRender={nodeData => { return <>{nodeData.title}; }} checkStrictly onDrop={handleDrop} onCheck={handleCheckColumns} /> } trigger="click" > , ) : null}
); }; export default TableToolbar;