diff --git a/packages/react-impression/src/components/Table/Table.js b/packages/react-impression/src/components/Table/Table.js index e74d9331c..bf029599f 100644 --- a/packages/react-impression/src/components/Table/Table.js +++ b/packages/react-impression/src/components/Table/Table.js @@ -1,6 +1,7 @@ import classnames from 'classnames' import React from 'react' import PropTypes from 'prop-types' +import PerfectScrollbar from 'perfect-scrollbar' import TableBody from '../TableBody' import TableHead from '../TableHead' import Pagination from '../Pagination' @@ -108,6 +109,11 @@ export default class Table extends React.PureComponent { componentWillMount() { this.handleInt() } + + componentWillUnmount() { + this.tableScroll && this.tableScroll.destroy() + } + /** * @description 初始化 * @memberof Table @@ -200,6 +206,11 @@ export default class Table extends React.PureComponent { componentDidMount() { const { rowSelection } = this.props + if (this.scrollEl) { + this.tableScroll = new PerfectScrollbar(this.scrollEl, { + suppressScrollY: true, + }) + } if (!rowSelection) return // 非受控组件 if (!this.isPuppet) { @@ -221,6 +232,12 @@ export default class Table extends React.PureComponent { }) } + updateScroll = () => { + window.requestAnimationFrame(() => { + this.scrollEl && this.tableScroll.update() + }) + } + /** * @description 更新左右固定项的宽度 * @author nmg @@ -261,9 +278,11 @@ export default class Table extends React.PureComponent { } = this.props if (columns && currentColumns && !R.equals(columns, currentColumns)) { this.handleInt(columns, children) + this.tableScroll && this.updateScroll() } if (children && currentChildren && !R.equals(children, currentChildren)) { this.handleInt(columns, children) + this.tableScroll && this.updateScroll() } if (!this.isPuppet) return @@ -638,136 +657,140 @@ export default class Table extends React.PureComponent { }} >
this.handleScroll(e)} + className='table-wrap table-scroll' ref={div => { this.scrollEl = div }} - className={classnames('table-wrap', 'table-scroll', { - 'table-border': border, - })} + onScroll={e => this.handleScroll(e)} >
{ - this.inner = div - }} - className='table-inner' + className={classnames('table-wrap', { + 'table-border': border, + })} > - - +
{ + this.inner = div + }} + className='table-inner' + > + + +
+ {(!!fixLeftColumns.length || + (rowSelection && rowSelection.fixed)) && ( +
+ + +
+ )} + {!!fixRightColumns.length && ( +
+ + +
+ )} + {!data.length && ( +

{placeholder}

+ )}
- {(!!fixLeftColumns.length || - (rowSelection && rowSelection.fixed)) && ( -
- - -
- )} - {!!fixRightColumns.length && ( -
- - -
- )} - {!data.length && ( -

{placeholder}

- )} {this.renderPagination()}