|
@@ -1,4 +1,4 @@
|
|
|
-import React, { ReactNode ,useEffect, useRef, useState} from 'react'
|
|
|
+import React, { ReactNode, useEffect, useRef, useState } from 'react'
|
|
|
import { Table, Tag, message } from 'antd';
|
|
|
import { Excle } from '@/utils/Excle'
|
|
|
import style from './index.less'
|
|
@@ -12,7 +12,7 @@ const ResizableHeader = (props: { [x: string]: any; onResize: any; width: any })
|
|
|
if (!width) {
|
|
|
return <th {...restProps} />
|
|
|
}
|
|
|
- return <Resizable width={width} height={0} onResize={onResize} draggableOpts={{enableUserSelectHack:false}}>
|
|
|
+ return <Resizable width={width} height={0} onResize={onResize} draggableOpts={{ enableUserSelectHack: false }}>
|
|
|
<th {...restProps} />
|
|
|
</Resizable>
|
|
|
}
|
|
@@ -52,14 +52,14 @@ interface Props {
|
|
|
showHeader?: boolean,
|
|
|
hideOnSinglePage?: boolean,
|
|
|
className?: string,
|
|
|
- handelResize?:(columns:any)=>void//当表头被拖动改变宽度时回调设置对应的本地保存
|
|
|
+ handelResize?: (columns: any) => void//当表头被拖动改变宽度时回调设置对应的本地保存
|
|
|
sortDirections?: SortOrder[],
|
|
|
isShowTotal?: boolean, // 是否展示总计
|
|
|
}
|
|
|
|
|
|
function Tables(props: Props) {
|
|
|
// //导出数据
|
|
|
- let { columns, dataSource, excle, total,handelResize, rowSelection, onRow, isShowTotal = true, hideOnSinglePage, rowClassName, className, expandedRowRender, scroll, summary, showHeader = true, bordered, size = 'small', onChange, sortDirections, pagination, ...prop } = props
|
|
|
+ let { columns, dataSource, excle, total, handelResize, rowSelection, onRow, isShowTotal = true, hideOnSinglePage, rowClassName, className, expandedRowRender, scroll, summary, showHeader = true, bordered, size = 'small', onChange, sortDirections, pagination, ...prop } = props
|
|
|
let handleExcle = () => {
|
|
|
if (dataSource.length < 1) {
|
|
|
message.error('请先搜索再导出');
|
|
@@ -76,32 +76,33 @@ function Tables(props: Props) {
|
|
|
}
|
|
|
let ww = document.body.clientWidth < 415
|
|
|
// 拖动宽逻辑
|
|
|
- const [cols,setCols] = useState<any>(columns)
|
|
|
+ const [cols, setCols] = useState<any>(columns)
|
|
|
const colsRef = useRef<any[]>([])
|
|
|
- const components={
|
|
|
- header:{
|
|
|
- cell:ResizableHeader
|
|
|
+ const components = {
|
|
|
+ header: {
|
|
|
+ cell: ResizableHeader
|
|
|
}
|
|
|
}
|
|
|
- useEffect(()=>{
|
|
|
+ useEffect(() => {
|
|
|
setCols(columns)
|
|
|
- },[columns])
|
|
|
- const handleResize=(index:any)=>(e:any,{size}:any)=>{
|
|
|
- const nextColumns=[...cols]
|
|
|
- nextColumns[index]={
|
|
|
+ }, [columns])
|
|
|
+ const handleResize = (index: any) => (e: any, { size }: any) => {
|
|
|
+ const nextColumns = [...cols]
|
|
|
+ nextColumns[index] = {
|
|
|
...nextColumns[index],
|
|
|
- width:size.width
|
|
|
+ width: size.width
|
|
|
}
|
|
|
setCols(nextColumns)
|
|
|
handelResize && handelResize(nextColumns)
|
|
|
}
|
|
|
- colsRef.current = (cols||[]).map((col:any,index:any)=>({
|
|
|
+ colsRef.current = (cols || []).map((col: any, index: any) => ({
|
|
|
...col,
|
|
|
- onHeaderCell:(column:any)=>({
|
|
|
- width:column.width,
|
|
|
- onResize:handleResize(index)
|
|
|
+ onHeaderCell: (column: any) => ({
|
|
|
+ width: column.width,
|
|
|
+ onResize: handleResize(index)
|
|
|
})
|
|
|
}))
|
|
|
+
|
|
|
return <div className='components-table-resizable-column'>
|
|
|
{
|
|
|
excle && <Tag color='#f50' style={{ margin: '10px 0', float: 'right' }} onClick={handleExcle}><a>导出数据</a></Tag>
|
|
@@ -127,16 +128,6 @@ function Tables(props: Props) {
|
|
|
onClick: onRow?.onClick && onRow?.onClick.bind('', record) || undefined,
|
|
|
}
|
|
|
}}
|
|
|
- // rowClassName={(record: any) => {
|
|
|
- // if (rowClassName && record[rowClassName as string] === 2) {
|
|
|
- // return style.unfollow
|
|
|
- // }
|
|
|
- // if (rowClassName && !record[rowClassName as string]) {
|
|
|
- // return style.unfollow
|
|
|
- // }
|
|
|
- // }
|
|
|
- // }
|
|
|
- // rowClassName={rowClassName}
|
|
|
summary={summary}
|
|
|
className={className}
|
|
|
expandable={expandedRowRender ? {
|
|
@@ -180,7 +171,4 @@ function Tables(props: Props) {
|
|
|
</div>
|
|
|
}
|
|
|
|
|
|
-export default Tables
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+export default Tables
|