diff --git a/src/components/TableToolBar/index.tsx b/src/components/TableToolBar/index.tsx index de63140f5dd5e75bc896803fd8bf628280fd17c0..684ebdfbf42dc31b6e2ee62f4aa8dea8a24a2051 100644 --- a/src/components/TableToolBar/index.tsx +++ b/src/components/TableToolBar/index.tsx @@ -1,12 +1,32 @@ -import { Button, Space, Tooltip } from 'antd' +import { Button, Checkbox, Dropdown, Space, Tooltip } from 'antd' import { SearchOutlined, ReloadOutlined, UnorderedListOutlined } from '@ant-design/icons' +import { FC, useState } from 'react' +import type { ColType } from '@/pages/table-pages/standard' -const TableToolBar = (props: any) => { - const { toggleSearch, refreshData, showColumn = () => {} } = props +interface IProps { + toggleSearch: () => void + refreshData: () => void + changeColumn: (dataIndex:string) => void + columnData: ColType[] +} +const TableToolBar:FC = (props) => { + const { toggleSearch, refreshData, changeColumn, columnData = [] } = props const onSearch = toggleSearch const onRefresh = refreshData - const onColumn = showColumn + const onChange = changeColumn + + const items = columnData.map((item) => { + return { + label: ( onChange(item.dataIndex)} checked={item?.selected !== false}>{item.title as string}), + key: item.dataIndex, + } + }) + const [open, setOpen] = useState(false) + + const handleOpenChange = (flag: boolean) => { + setOpen(flag) + } return (
@@ -16,9 +36,9 @@ const TableToolBar = (props: any) => {
) diff --git a/src/pages/table-pages/standard/index.tsx b/src/pages/table-pages/standard/index.tsx index 3629b9219aaa7686349ebe7e8053570cac27a82c..ba84e2c48bb9a357888e39630aa32edd39bfa49c 100644 --- a/src/pages/table-pages/standard/index.tsx +++ b/src/pages/table-pages/standard/index.tsx @@ -19,7 +19,7 @@ interface DataType { age: number; address: string; } - +export type ColType=ColumnsType[number] & {selected?:boolean, dataIndex:string} const StandarTable = () => { const [state, setState] = useSetState({ showSearch: false }) const [isOpenEdit, setIsOpenEdit] = useState(false) @@ -29,6 +29,7 @@ const StandarTable = () => { useEffect(() => { setState({ showSearch: true }) + changeColumn() }, []) const { tableProps, search, run: getTableData } = useAntdTable(getUserList, { @@ -59,8 +60,7 @@ const StandarTable = () => { const onToggleSearch = () => { setState({ showSearch: !state.showSearch }) } - - const columns: ColumnsType = [ + const [columns, setColumns] = useState([ { title: '姓名', dataIndex: 'name.last', @@ -70,6 +70,7 @@ const StandarTable = () => { }, { title: '邮箱', + selected: false, dataIndex: 'email', }, { @@ -98,8 +99,15 @@ const StandarTable = () => { ), }, - ] - + ]) + const changeColumn = (dataIndex?:string) => { + columns.forEach((item) => { + if (item.dataIndex === dataIndex) { + item.selected = !item.selected + } + }) + setColumns([...columns]) + } const tip = () => { setIsOpenEdit(true) } @@ -242,7 +250,7 @@ const StandarTable = () => {
- +
@@ -251,7 +259,7 @@ const StandarTable = () => { rowKey="cell" size="middle" rowSelection={rowSelection} - columns={columns} + columns={columns.filter((item) => item.selected !== false)} {...tableProps} />