import React, { ReactElement, useEffect } from 'react'; import { Tooltip, Checkbox } from 'antd'; import * as Tool from 'jad-tool' import { FilterColumnsMenu } from '../../FilterColumnsMenu/FilterColumnsMenu'; import { Iconfont } from '../../Iconfont/Iconfont'; import { PageCore, PageCoreProps } from './PageCore'; type PageTableCoreProps = { table: ReactElement, // 自定义列 tableColumns?: any[], // 自定义列: 原始column filterTableColumnsCacheKey?: string, // 自定义列: Key onHandleColumnsChange?: (key:any) => void, // 自定义列更新 // 下载报表 downloadTable?: (any) => void, dlLoading?: boolean, // 设置列宽 onResetTableWidth?: () => void, // 过滤总数为0的列 filterTableZeroDataChecked?: boolean, filterTableZeroDataCacheKey?: string, onFilterTableZeroData?: (any) => void, // 更多按钮 otherBtns?: ReactElement[], extraBtns?: ReactElement[] | ReactElement, } & PageCoreProps; const Tools = Tool.extend({ setCacheData(key: string, value: any[]) { window.localStorage.setItem('JG_FilterZeroData_Cache_' + key, JSON.stringify(value)) }, getCacheData(key: string) { var value = window.localStorage.getItem('JG_FilterZeroData_Cache_' + key) return value ? JSON.parse(value) : null }, }, Tool) export const PageTableCore:React.FunctionComponent = (props) => { const { table, tableColumns, filterTableColumnsCacheKey, downloadTable, onHandleColumnsChange, dlLoading, otherBtns, extraBtns, title, onResetTableWidth, filterTableZeroDataChecked, filterTableZeroDataCacheKey, onFilterTableZeroData, children, ...pageCoreProps } = props; const onHandleChecked = (e) => { const checked = e.target.checked Tools.setCacheData(filterTableZeroDataCacheKey, checked) onFilterTableZeroData && onFilterTableZeroData(checked) } const extra = ( <> { filterTableZeroDataCacheKey && filterTableZeroDataCacheKey.length > 0 && ( 过滤总数为0的列 ) } { onResetTableWidth && ( ) } { filterTableColumnsCacheKey && filterTableColumnsCacheKey.length > 0 && ( ) } { downloadTable && ( ) } { (otherBtns || extraBtns) } ); useEffect(() => { if (filterTableZeroDataCacheKey && filterTableZeroDataCacheKey.length > 0) { const cacheData = Tools.getCacheData(filterTableZeroDataCacheKey) if (cacheData === null) { Tools.setCacheData(filterTableZeroDataCacheKey, filterTableZeroDataChecked) return } onFilterTableZeroData && onFilterTableZeroData(cacheData) } }, [filterTableZeroDataCacheKey]) return ( { table } ); }