2017-01-12 08:53:51 +08:00
'use strict' ;
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
var _extends = Object . assign || function ( target ) { for ( var i = 1 ; i < arguments . length ; i ++ ) { var source = arguments [ i ] ; for ( var key in source ) { if ( Object . prototype . hasOwnProperty . call ( source , key ) ) { target [ key ] = source [ key ] ; } } } return target ; } ;
var _react = require ( 'react' ) ;
var _react2 = _interopRequireDefault ( _react ) ;
2017-06-03 20:34:07 +08:00
var _propTypes = require ( 'prop-types' ) ;
var _propTypes2 = _interopRequireDefault ( _propTypes ) ;
2018-12-03 16:55:10 +08:00
var _componentClasses = require ( 'component-classes' ) ;
var _componentClasses2 = _interopRequireDefault ( _componentClasses ) ;
2017-01-12 08:53:51 +08:00
var _TableRow = require ( './TableRow' ) ;
var _TableRow2 = _interopRequireDefault ( _TableRow ) ;
var _TableHeader = require ( './TableHeader' ) ;
var _TableHeader2 = _interopRequireDefault ( _TableHeader ) ;
2019-07-26 09:47:18 +08:00
var _utils = require ( './lib/utils' ) ;
2017-01-12 08:53:51 +08:00
var _shallowequal = require ( 'shallowequal' ) ;
var _shallowequal2 = _interopRequireDefault ( _shallowequal ) ;
2017-06-03 20:34:07 +08:00
var _addEventListener = require ( 'tinper-bee-core/lib/addEventListener' ) ;
2017-01-12 08:53:51 +08:00
var _addEventListener2 = _interopRequireDefault ( _addEventListener ) ;
var _ColumnManager = require ( './ColumnManager' ) ;
var _ColumnManager2 = _interopRequireDefault ( _ColumnManager ) ;
var _createStore = require ( './createStore' ) ;
var _createStore2 = _interopRequireDefault ( _createStore ) ;
2018-01-31 19:46:40 +08:00
var _beeLoading = require ( 'bee-loading' ) ;
var _beeLoading2 = _interopRequireDefault ( _beeLoading ) ;
2019-04-24 09:49:33 +08:00
var _beeIcon = require ( 'bee-icon' ) ;
var _beeIcon2 = _interopRequireDefault ( _beeIcon ) ;
2019-05-21 19:31:38 +08:00
var _i18n = require ( './lib/i18n' ) ;
var _i18n2 = _interopRequireDefault ( _i18n ) ;
var _tool = require ( 'bee-locale/build/tool' ) ;
2017-01-12 08:53:51 +08:00
function _interopRequireDefault ( obj ) { return obj && obj . _ _esModule ? obj : { "default" : obj } ; }
function _defaults ( obj , defaults ) { var keys = Object . getOwnPropertyNames ( defaults ) ; for ( var i = 0 ; i < keys . length ; i ++ ) { var key = keys [ i ] ; var value = Object . getOwnPropertyDescriptor ( defaults , key ) ; if ( value && value . configurable && obj [ key ] === undefined ) { Object . defineProperty ( obj , key , value ) ; } } return obj ; }
function _toConsumableArray ( arr ) { if ( Array . isArray ( arr ) ) { for ( var i = 0 , arr2 = Array ( arr . length ) ; i < arr . length ; i ++ ) { arr2 [ i ] = arr [ i ] ; } return arr2 ; } else { return Array . from ( arr ) ; } }
function _classCallCheck ( instance , Constructor ) { if ( ! ( instance instanceof Constructor ) ) { throw new TypeError ( "Cannot call a class as a function" ) ; } }
function _possibleConstructorReturn ( self , call ) { if ( ! self ) { throw new ReferenceError ( "this hasn't been initialised - super() hasn't been called" ) ; } return call && ( typeof call === "object" || typeof call === "function" ) ? call : self ; }
function _inherits ( subClass , superClass ) { if ( typeof superClass !== "function" && superClass !== null ) { throw new TypeError ( "Super expression must either be null or a function, not " + typeof superClass ) ; } subClass . prototype = Object . create ( superClass && superClass . prototype , { constructor : { value : subClass , enumerable : false , writable : true , configurable : true } } ) ; if ( superClass ) Object . setPrototypeOf ? Object . setPrototypeOf ( subClass , superClass ) : _defaults ( subClass , superClass ) ; }
var propTypes = {
2017-06-03 20:34:07 +08:00
data : _propTypes2 [ "default" ] . array ,
expandIconAsCell : _propTypes2 [ "default" ] . bool ,
defaultExpandAllRows : _propTypes2 [ "default" ] . bool ,
expandedRowKeys : _propTypes2 [ "default" ] . array ,
defaultExpandedRowKeys : _propTypes2 [ "default" ] . array ,
useFixedHeader : _propTypes2 [ "default" ] . bool ,
columns : _propTypes2 [ "default" ] . array ,
clsPrefix : _propTypes2 [ "default" ] . string ,
bodyStyle : _propTypes2 [ "default" ] . object ,
style : _propTypes2 [ "default" ] . object ,
2017-01-12 08:53:51 +08:00
//特殊的渲染规则的key值
2017-06-03 20:34:07 +08:00
rowKey : _propTypes2 [ "default" ] . oneOfType ( [ _propTypes2 [ "default" ] . string , _propTypes2 [ "default" ] . func ] ) ,
rowClassName : _propTypes2 [ "default" ] . func ,
expandedRowClassName : _propTypes2 [ "default" ] . func ,
childrenColumnName : _propTypes2 [ "default" ] . string ,
onExpand : _propTypes2 [ "default" ] . func ,
2019-02-18 14:54:33 +08:00
onRowHover : _propTypes2 [ "default" ] . func ,
2017-06-03 20:34:07 +08:00
onExpandedRowsChange : _propTypes2 [ "default" ] . func ,
indentSize : _propTypes2 [ "default" ] . number ,
onRowClick : _propTypes2 [ "default" ] . func ,
onRowDoubleClick : _propTypes2 [ "default" ] . func ,
expandIconColumnIndex : _propTypes2 [ "default" ] . number ,
2017-01-12 08:53:51 +08:00
//是否显示表头
2017-06-03 20:34:07 +08:00
showHeader : _propTypes2 [ "default" ] . bool ,
title : _propTypes2 [ "default" ] . func ,
footer : _propTypes2 [ "default" ] . func ,
emptyText : _propTypes2 [ "default" ] . func ,
scroll : _propTypes2 [ "default" ] . object ,
rowRef : _propTypes2 [ "default" ] . func ,
getBodyWrapper : _propTypes2 [ "default" ] . func ,
2018-05-11 09:29:43 +08:00
children : _propTypes2 [ "default" ] . node ,
2018-09-12 14:14:05 +08:00
draggable : _propTypes2 [ "default" ] . bool ,
2018-12-14 13:30:24 +08:00
minColumnWidth : _propTypes2 [ "default" ] . number ,
filterable : _propTypes2 [ "default" ] . bool ,
filterDelay : _propTypes2 [ "default" ] . number ,
onFilterChange : _propTypes2 [ "default" ] . func ,
onFilterClear : _propTypes2 [ "default" ] . func ,
2018-12-28 10:02:54 +08:00
syncHover : _propTypes2 [ "default" ] . bool ,
2019-02-18 14:56:02 +08:00
tabIndex : _propTypes2 [ "default" ] . string ,
2019-04-23 16:59:47 +08:00
hoverContent : _propTypes2 [ "default" ] . func ,
2019-04-25 14:19:48 +08:00
size : _propTypes2 [ "default" ] . oneOf ( [ 'sm' , 'md' , 'lg' ] ) ,
2019-05-22 18:20:13 +08:00
rowDraggAble : _propTypes2 [ "default" ] . bool ,
2019-07-16 11:30:02 +08:00
onDropRow : _propTypes2 [ "default" ] . func ,
2019-08-23 13:48:27 +08:00
onDragRowStart : _propTypes2 [ "default" ] . func ,
2019-08-27 11:10:47 +08:00
onBodyScroll : _propTypes2 [ "default" ] . func ,
2019-08-23 13:48:27 +08:00
bodyDisplayInRow : _propTypes2 [ "default" ] . bool , // 表格内容超出列宽度时进行换行 or 以...形式展现
headerDisplayInRow : _propTypes2 [ "default" ] . bool , // 表头内容超出列宽度时进行换行 or 以...形式展现
2019-08-29 20:43:47 +08:00
showRowNum : _propTypes2 [ "default" ] . oneOfType ( [ _propTypes2 [ "default" ] . bool , _propTypes2 [ "default" ] . object ] ) // 表格是否自动生成序号,格式为{base:number || 0,defaultKey:string || '_index',defaultName:string || '序号'}
2017-01-12 08:53:51 +08:00
} ;
var defaultProps = {
data : [ ] ,
useFixedHeader : false ,
expandIconAsCell : false ,
defaultExpandAllRows : false ,
defaultExpandedRowKeys : [ ] ,
rowKey : 'key' ,
rowClassName : function rowClassName ( ) {
return '' ;
} ,
expandedRowClassName : function expandedRowClassName ( ) {
return '' ;
} ,
onExpand : function onExpand ( ) { } ,
onExpandedRowsChange : function onExpandedRowsChange ( ) { } ,
onRowClick : function onRowClick ( ) { } ,
onRowDoubleClick : function onRowDoubleClick ( ) { } ,
clsPrefix : 'u-table' ,
bodyStyle : { } ,
style : { } ,
childrenColumnName : 'children' ,
indentSize : 15 ,
expandIconColumnIndex : 0 ,
showHeader : true ,
scroll : { } ,
rowRef : function rowRef ( ) {
return null ;
} ,
getBodyWrapper : function getBodyWrapper ( body ) {
return body ;
} ,
2019-05-21 19:31:38 +08:00
// emptyText: () => <div><Icon type="uf-nodata" className="table-nodata"></Icon><span>{locale["no_data"]}</span></div>,
2018-10-24 21:59:54 +08:00
columns : [ ] ,
2018-11-01 14:35:46 +08:00
minColumnWidth : 80 ,
2018-12-14 13:30:24 +08:00
locale : { } ,
2018-12-28 10:02:54 +08:00
syncHover : true ,
2019-01-07 14:57:58 +08:00
setRowHeight : function setRowHeight ( ) { } ,
setRowParentIndex : function setRowParentIndex ( ) { } ,
2019-03-06 10:42:06 +08:00
tabIndex : '0' ,
2019-04-23 16:59:47 +08:00
heightConsistent : false ,
2019-04-25 14:19:48 +08:00
size : 'md' ,
2019-05-22 18:20:13 +08:00
rowDraggAble : false ,
2019-07-16 11:30:02 +08:00
onDropRow : function onDropRow ( ) { } ,
2019-08-23 13:48:27 +08:00
onDragRowStart : function onDragRowStart ( ) { } ,
2019-08-27 11:10:47 +08:00
onBodyScroll : function onBodyScroll ( ) { } ,
2019-08-23 13:48:27 +08:00
bodyDisplayInRow : true ,
headerDisplayInRow : true ,
showRowNum : false
2017-01-12 08:53:51 +08:00
} ;
var Table = function ( _Component ) {
_inherits ( Table , _Component ) ;
function Table ( props ) {
_classCallCheck ( this , Table ) ;
var _this = _possibleConstructorReturn ( this , _Component . call ( this , props ) ) ;
2019-04-23 16:04:02 +08:00
_this . resize = function ( ) {
( 0 , _utils . debounce ) ( _this . syncFixedTableRowHeight , 150 ) ;
_this . computeTableWidth ( ) ;
var renderFlag = _this . state . renderFlag ;
_this . setState ( {
renderFlag : ! renderFlag
} ) ;
} ;
2019-04-26 18:10:57 +08:00
_this . getTableUID = function ( ) {
var uid = "_table_uid_" + new Date ( ) . getTime ( ) ;
_this . tableUid = uid ;
var div = document . createElement ( "div" ) ;
// div.className = "u-table-drag-hidden-cont";
div . className = "u-table-drag-hidden-cont" ;
div . id = uid ;
_this . contentTable . appendChild ( div ) ;
} ;
2019-04-25 14:19:48 +08:00
2019-11-14 09:49:40 +08:00
_this . getColumnsChildrenList = function ( columns ) {
columns . forEach ( function ( da ) {
da . children ? _this . getColumnsChildrenList ( da . children ) : _this . columnsChildrenList . push ( da ) ;
} ) ;
} ;
2019-07-16 11:30:02 +08:00
_this . onDragRowStart = function ( currentKey ) {
var data = _this . state . data ,
currentIndex = void 0 ,
record = void 0 ;
data . forEach ( function ( da , i ) {
// tr 的唯一标识通过 data.key 或 rowKey 两种方式传进来
var trKey = da . key ? da . key : _this . getRowKey ( da , i ) ;
if ( trKey == currentKey ) {
currentIndex = i ;
record = da ;
}
} ) ;
_this . props . onDragRowStart && _this . props . onDragRowStart ( record , currentIndex ) ;
} ;
2019-04-26 18:10:57 +08:00
_this . onDragRow = function ( currentKey , targetKey ) {
var data = _this . state . data ,
currentIndex = void 0 ,
2019-05-22 18:20:13 +08:00
targetIndex = void 0 ,
record = void 0 ;
2019-04-26 18:10:57 +08:00
data . forEach ( function ( da , i ) {
2019-05-22 18:20:13 +08:00
// tr 的唯一标识通过 data.key 或 rowKey 两种方式传进来
var trKey = da . key ? da . key : _this . getRowKey ( da , i ) ;
if ( trKey == currentKey ) {
2019-04-26 18:10:57 +08:00
currentIndex = i ;
2019-05-22 18:20:13 +08:00
record = da ;
2019-04-26 18:10:57 +08:00
}
2019-05-22 18:20:13 +08:00
if ( trKey == targetKey ) {
2019-04-26 18:10:57 +08:00
targetIndex = i ;
}
} ) ;
2019-05-24 10:59:10 +08:00
data = _this . swapArray ( data , currentIndex , targetIndex ) ;
2019-05-22 18:20:13 +08:00
_this . props . onDropRow && _this . props . onDropRow ( data , record ) ;
2019-04-25 14:19:48 +08:00
_this . setState ( {
data : data
} ) ;
} ;
2019-05-24 10:59:10 +08:00
_this . swapArray = function ( arr , index1 , index2 ) {
2019-08-05 17:23:38 +08:00
var value1 = arr [ index1 ] ;
arr . splice ( index1 , 1 ) ;
if ( index1 < index2 ) {
arr . splice ( index2 , 0 , value1 ) ;
} else {
arr . splice ( index2 + 1 , 0 , value1 ) ;
}
2019-08-07 10:32:05 +08:00
2019-05-24 10:59:10 +08:00
return arr ;
} ;
2018-05-11 11:30:56 +08:00
_this . renderDragHideTable = function ( ) {
2018-05-14 10:01:06 +08:00
var _this$props = _this . props ,
columns = _this$props . columns ,
dragborder = _this$props . dragborder ,
dragborderKey = _this$props . dragborderKey ;
2018-05-11 11:30:56 +08:00
2018-05-14 10:01:06 +08:00
if ( ! dragborder ) return null ;
2018-05-11 11:30:56 +08:00
var sum = 0 ;
return _react2 [ "default" ] . createElement (
'div' ,
2018-05-14 10:01:06 +08:00
{ id : 'u-table-drag-hide-table-' + dragborderKey , className : _this . props . clsPrefix + '-hiden-drag' } ,
2018-05-11 11:30:56 +08:00
columns . map ( function ( da , i ) {
sum += da . width ? da . width : 0 ;
return _react2 [ "default" ] . createElement ( 'div' , { className : _this . props . clsPrefix + '-hiden-drag-li' , key : da + "_hiden_" + i , style : { left : sum + "px" } } ) ;
} )
) ;
} ;
2019-02-18 14:54:33 +08:00
_this . onRowHoverMouseEnter = function ( ) {
_this . store . setState ( {
currentHoverKey : _this . currentHoverKey
} ) ;
_this . hoverDom . style . display = 'block' ;
} ;
_this . onRowHoverMouseLeave = function ( ) { } ;
2019-01-05 11:06:52 +08:00
_this . onFocus = function ( e ) {
_this . props . onKeyTab && _this . props . onKeyTab ( ) ;
} ;
2018-12-26 14:39:20 +08:00
_this . onKeyDown = function ( e ) {
var event = _utils . Event . getEvent ( e ) ;
// event.preventDefault?event.preventDefault():event.returnValue = false;
2019-01-05 11:06:52 +08:00
if ( event . keyCode === 38 ) {
2018-12-26 14:39:20 +08:00
//up
2019-01-05 11:06:52 +08:00
event . preventDefault && event . preventDefault ( ) ;
2018-12-26 14:39:20 +08:00
_this . props . onKeyUp && _this . props . onKeyUp ( ) ;
} else if ( event . keyCode === 40 ) {
//down
2019-01-05 11:06:52 +08:00
event . preventDefault && event . preventDefault ( ) ;
2018-12-26 14:39:20 +08:00
_this . props . onKeyDown && _this . props . onKeyDown ( ) ;
}
2018-12-28 10:02:54 +08:00
_this . props . onTableKeyDown && _this . props . onTableKeyDown ( ) ;
2018-12-26 14:39:20 +08:00
} ;
2017-01-12 08:53:51 +08:00
var expandedRowKeys = [ ] ;
var rows = [ ] . concat ( _toConsumableArray ( props . data ) ) ;
2019-08-23 13:48:27 +08:00
_this . columnManager = new _ColumnManager2 [ "default" ] ( props . columns , props . children , props . originWidth , props . rowDraggAble , props . showRowNum ) ; // 加入props.showRowNum参数
2017-01-12 08:53:51 +08:00
_this . store = ( 0 , _createStore2 [ "default" ] ) ( { currentHoverKey : null } ) ;
2019-03-14 10:20:13 +08:00
_this . firstDid = true ;
2017-01-12 08:53:51 +08:00
if ( props . defaultExpandAllRows ) {
for ( var i = 0 ; i < rows . length ; i ++ ) {
var row = rows [ i ] ;
expandedRowKeys . push ( _this . getRowKey ( row , i ) ) ;
rows = rows . concat ( row [ props . childrenColumnName ] || [ ] ) ;
}
} else {
expandedRowKeys = props . expandedRowKeys || props . defaultExpandedRowKeys ;
}
2019-11-14 09:49:40 +08:00
_this . columnsChildrenList = [ ] ; //复杂表头、所有叶子节点
_this . getColumnsChildrenList ( props . columns ) ; //复杂表头、所有叶子节点
2017-01-12 08:53:51 +08:00
_this . state = {
expandedRowKeys : expandedRowKeys ,
data : props . data ,
currentHoverKey : null ,
scrollPosition : 'left' ,
fixedColumnsHeadRowsHeight : [ ] ,
2019-09-09 10:46:35 +08:00
fixedColumnsBodyRowsHeight : [ ] ,
fixedColumnsExpandedRowsHeight : { } //扩展行的高度
2017-01-12 08:53:51 +08:00
} ;
_this . onExpandedRowsChange = _this . onExpandedRowsChange . bind ( _this ) ;
_this . onExpanded = _this . onExpanded . bind ( _this ) ;
_this . onRowDestroy = _this . onRowDestroy . bind ( _this ) ;
_this . getRowKey = _this . getRowKey . bind ( _this ) ;
_this . getExpandedRows = _this . getExpandedRows . bind ( _this ) ;
_this . getHeader = _this . getHeader . bind ( _this ) ;
_this . getHeaderRows = _this . getHeaderRows . bind ( _this ) ;
_this . getExpandedRow = _this . getExpandedRow . bind ( _this ) ;
_this . getRowsByData = _this . getRowsByData . bind ( _this ) ;
_this . getRows = _this . getRows . bind ( _this ) ;
_this . getColGroup = _this . getColGroup . bind ( _this ) ;
_this . getLeftFixedTable = _this . getLeftFixedTable . bind ( _this ) ;
_this . getRightFixedTable = _this . getRightFixedTable . bind ( _this ) ;
_this . getTable = _this . getTable . bind ( _this ) ;
_this . getTitle = _this . getTitle . bind ( _this ) ;
_this . getFooter = _this . getFooter . bind ( _this ) ;
_this . getEmptyText = _this . getEmptyText . bind ( _this ) ;
_this . getHeaderRowStyle = _this . getHeaderRowStyle . bind ( _this ) ;
_this . syncFixedTableRowHeight = _this . syncFixedTableRowHeight . bind ( _this ) ;
2019-03-01 16:59:17 +08:00
_this . resetScrollX = _this . resetScrollX . bind ( _this ) ;
2017-01-12 08:53:51 +08:00
_this . findExpandedRow = _this . findExpandedRow . bind ( _this ) ;
_this . isRowExpanded = _this . isRowExpanded . bind ( _this ) ;
_this . detectScrollTarget = _this . detectScrollTarget . bind ( _this ) ;
_this . handleBodyScroll = _this . handleBodyScroll . bind ( _this ) ;
_this . handleRowHover = _this . handleRowHover . bind ( _this ) ;
2018-09-12 14:14:05 +08:00
_this . computeTableWidth = _this . computeTableWidth . bind ( _this ) ;
2019-02-18 14:54:33 +08:00
_this . onBodyMouseLeave = _this . onBodyMouseLeave . bind ( _this ) ;
2019-04-26 18:10:57 +08:00
_this . tableUid = null ;
2019-07-18 11:25:29 +08:00
_this . contentTable = null ;
2019-08-26 15:03:04 +08:00
_this . leftColumnsLength ; //左侧固定列的长度
2019-11-14 09:49:40 +08:00
_this . centerColumnsLength ; //非固定列的长度
2017-01-12 08:53:51 +08:00
return _this ;
}
2019-08-26 15:03:04 +08:00
Table . prototype . componentWillMount = function componentWillMount ( ) {
this . centerColumnsLength = this . columnManager . centerColumns ( ) . length ;
this . leftColumnsLength = this . columnManager . leftColumns ( ) . length ;
} ;
2017-01-12 08:53:51 +08:00
Table . prototype . componentDidMount = function componentDidMount ( ) {
2019-04-26 18:10:57 +08:00
this . getTableUID ( ) ;
2019-01-05 11:06:52 +08:00
_utils . EventUtil . addHandler ( this . contentTable , 'keydown' , this . onKeyDown ) ;
_utils . EventUtil . addHandler ( this . contentTable , 'focus' , this . onFocus ) ;
2019-03-01 16:59:17 +08:00
setTimeout ( this . resetScrollX , 300 ) ;
2018-11-08 17:55:09 +08:00
//含有纵向滚动条
2019-06-26 16:40:46 +08:00
// if(this.props.scroll.y){
this . scrollbarWidth = ( 0 , _utils . measureScrollbar ) ( ) ;
// }
2018-09-12 14:14:05 +08:00
//后续也放在recevice里面
if ( ! this . props . originWidth ) {
this . computeTableWidth ( ) ;
}
2017-01-12 08:53:51 +08:00
if ( this . columnManager . isAnyColumnsFixed ( ) ) {
this . syncFixedTableRowHeight ( ) ;
2019-04-23 16:04:02 +08:00
this . resizeEvent = ( 0 , _addEventListener2 [ "default" ] ) ( window , 'resize' , this . resize ) ;
2017-01-12 08:53:51 +08:00
}
} ;
Table . prototype . componentWillReceiveProps = function componentWillReceiveProps ( nextProps ) {
if ( 'data' in nextProps ) {
this . setState ( {
data : nextProps . data
} ) ;
}
if ( 'expandedRowKeys' in nextProps ) {
this . setState ( {
expandedRowKeys : nextProps . expandedRowKeys
} ) ;
}
if ( nextProps . columns && nextProps . columns !== this . props . columns ) {
2019-08-23 13:48:27 +08:00
this . columnManager . reset ( nextProps . columns , null , this . props . showRowNum ) ; // 加入this.props.showRowNum参数
2019-05-05 14:07:34 +08:00
if ( nextProps . columns . length !== this . props . columns . length && this . refs && this . bodyTable ) {
this . scrollTop = this . bodyTable . scrollTop ;
2018-10-17 17:16:23 +08:00
}
2017-01-12 08:53:51 +08:00
} else if ( nextProps . children !== this . props . children ) {
2019-09-19 15:50:30 +08:00
this . columnManager . reset ( null , nextProps . children , this . props . showRowNum ) ; // 加入this.props.showRowNum参数
2017-01-12 08:53:51 +08:00
}
2018-12-20 09:41:51 +08:00
//适配lazyload
2019-01-25 11:26:06 +08:00
if ( nextProps . scrollTop > - 1 ) {
2019-05-05 14:07:34 +08:00
// this.bodyTable.scrollTop = nextProps.scrollTop;
2018-12-20 09:41:51 +08:00
this . scrollTop = nextProps . scrollTop ;
}
2018-09-12 14:14:05 +08:00
if ( ! nextProps . originWidth ) {
this . computeTableWidth ( ) ;
2019-01-07 14:57:58 +08:00
this . firstDid = true ; //避免重复update
2018-09-12 14:14:05 +08:00
}
2019-02-14 14:34:12 +08:00
if ( nextProps . resetScroll ) {
2019-03-01 16:59:17 +08:00
this . resetScrollX ( ) ;
2019-02-14 14:34:12 +08:00
}
2019-05-27 10:16:46 +08:00
// fix:模态框中使用table, 计算的滚动条宽度为0的bug
2019-08-08 11:14:23 +08:00
// fix:表格首次渲染时 display:none, 再显示时, 未重新计算, 导致表行出现错位的bug
2019-05-27 10:16:46 +08:00
if ( this . scrollbarWidth <= 0 && this . props . scroll . y ) {
this . scrollbarWidth = ( 0 , _utils . measureScrollbar ) ( ) ;
}
2019-01-07 14:57:58 +08:00
// console.log('this.scrollTop**********',this.scrollTop);
2017-01-12 08:53:51 +08:00
} ;
2019-03-01 16:59:17 +08:00
Table . prototype . componentDidUpdate = function componentDidUpdate ( prevProps ) {
2018-09-14 13:43:22 +08:00
2018-08-28 09:57:44 +08:00
if ( this . columnManager . isAnyColumnsFixed ( ) ) {
this . syncFixedTableRowHeight ( ) ;
}
2018-10-16 19:06:18 +08:00
//适应模态框中表格、以及父容器宽度变化的情况
2019-01-07 14:57:58 +08:00
if ( typeof this . props . scroll . x !== 'number' && this . contentTable . getBoundingClientRect ( ) . width !== this . contentDomWidth && this . firstDid ) {
2018-10-11 22:53:27 +08:00
this . computeTableWidth ( ) ;
2019-01-07 14:57:58 +08:00
this . firstDid = false ; //避免重复update
2018-10-11 22:53:27 +08:00
}
2019-01-25 11:26:06 +08:00
if ( this . scrollTop > - 1 ) {
2018-10-25 09:52:00 +08:00
this . refs . fixedColumnsBodyLeft && ( this . refs . fixedColumnsBodyLeft . scrollTop = this . scrollTop ) ;
this . refs . fixedColumnsBodyRight && ( this . refs . fixedColumnsBodyRight . scrollTop = this . scrollTop ) ;
2019-05-05 14:07:34 +08:00
this . bodyTable . scrollTop = this . scrollTop ;
2019-01-25 11:26:06 +08:00
this . scrollTop = - 1 ;
2018-10-25 09:52:00 +08:00
}
2019-03-01 16:59:17 +08:00
if ( prevProps . data . length === 0 || this . props . data . length === 0 ) {
this . resetScrollX ( ) ;
}
2019-05-22 14:19:13 +08:00
2019-03-06 14:46:26 +08:00
// 是否传入 scroll中的y属性, 如果传入判断是否是整数, 如果是则进行比较 。bodyTable 的clientHeight进行判断
2019-05-27 10:28:15 +08:00
this . isShowScrollY ( ) ;
2017-01-12 08:53:51 +08:00
} ;
Table . prototype . componentWillUnmount = function componentWillUnmount ( ) {
2019-08-23 13:48:27 +08:00
// 移除绑定事件,避免内存泄漏
2019-07-18 11:25:29 +08:00
this . contentTable = null ;
2019-01-05 11:06:52 +08:00
_utils . EventUtil . removeHandler ( this . contentTable , 'keydown' , this . onKeyDown ) ;
_utils . EventUtil . removeHandler ( this . contentTable , 'focus' , this . onFocus ) ;
2017-01-12 08:53:51 +08:00
if ( this . resizeEvent ) {
this . resizeEvent . remove ( ) ;
}
} ;
2018-09-12 14:14:05 +08:00
Table . prototype . computeTableWidth = function computeTableWidth ( ) {
2018-11-08 22:46:18 +08:00
2018-09-13 10:28:28 +08:00
//如果用户传了scroll.x按用户传的为主
var setWidthParam = this . props . scroll . x ;
2018-11-21 22:23:40 +08:00
2018-09-14 13:43:22 +08:00
if ( typeof setWidthParam == 'number' ) {
var numSetWidthParam = parseInt ( setWidthParam ) ;
this . contentWidth = numSetWidthParam ;
} else {
2018-10-16 19:06:18 +08:00
// this.preContentDomWidth = this.contentDomWidth;
2018-09-14 13:43:22 +08:00
//计算总表格宽度、根据表格宽度和各列的宽度和比较,重置最后一列
2018-09-14 13:54:28 +08:00
this . contentDomWidth = this . contentTable . getBoundingClientRect ( ) . width ; //表格容器宽度
2018-10-12 16:35:35 +08:00
2018-09-14 13:54:28 +08:00
this . contentWidth = this . contentDomWidth ; //默认与容器宽度一样
2018-11-21 22:23:40 +08:00
}
var computeObj = this . columnManager . getColumnWidth ( this . contentWidth ) ;
var lastShowIndex = computeObj . lastShowIndex ;
this . computeWidth = computeObj . computeWidth ;
this . domWidthDiff = this . contentDomWidth - this . computeWidth ;
if ( typeof setWidthParam == 'string' && setWidthParam . indexOf ( '%' ) ) {
this . contentWidth = this . contentWidth * parseInt ( setWidthParam ) / 100 ;
this . domWidthDiff = this . contentDomWidth - this . contentWidth ;
2018-09-13 10:28:28 +08:00
}
2018-11-12 17:50:47 +08:00
2019-08-17 11:36:55 +08:00
if ( this . computeWidth < this . contentWidth ) {
2018-11-08 17:55:09 +08:00
var contentWidthDiff = this . scrollbarWidth ? this . contentWidth - this . computeWidth - this . scrollbarWidth : this . contentWidth - this . computeWidth ;
2018-11-08 22:46:18 +08:00
//bordered的表格需要减去边框的差值1
if ( this . props . bordered ) {
contentWidthDiff = contentWidthDiff - 1 ;
}
2018-09-13 10:28:28 +08:00
this . setState ( { contentWidthDiff : contentWidthDiff , lastShowIndex : lastShowIndex } ) ;
2018-09-27 15:24:29 +08:00
} else {
this . contentWidth = this . computeWidth ;
2018-09-30 16:05:40 +08:00
this . setState ( { contentWidthDiff : 0 , lastShowIndex : lastShowIndex } ) ; //重新渲染,为了显示滚动条
2018-09-12 14:14:05 +08:00
}
} ;
2019-03-06 14:46:26 +08:00
//根据内容动态的判断是否显示纵向滚动条
Table . prototype . isShowScrollY = function isShowScrollY ( ) {
var props = this . props ;
var y = props . scroll && props . scroll . y ;
if ( y ) {
2019-05-05 14:07:34 +08:00
var bodyH = this . bodyTable . clientHeight ;
var bodyContentH = this . bodyTable . querySelector ( 'table' ) . clientHeight ;
2019-03-06 14:46:26 +08:00
var rightBodyTable = this . refs . fixedColumnsBodyRight ;
2019-05-27 10:28:15 +08:00
// const leftBodyTable = this.refs.fixedColumnsBodyLeft;
2019-04-09 15:56:33 +08:00
var overflowy = bodyContentH <= bodyH ? 'auto' : 'scroll' ;
2019-05-05 14:07:34 +08:00
this . bodyTable . style . overflowY = overflowy ;
2019-05-13 11:28:16 +08:00
2019-05-22 14:19:13 +08:00
this . headTable . style . overflowY = overflowy ;
2019-04-09 15:56:33 +08:00
rightBodyTable && ( rightBodyTable . style . overflowY = overflowy ) ;
2019-05-22 14:19:13 +08:00
// 没有纵向滚动条时,表头横向滚动条根据内容动态显示 待验证
// if(overflowy == 'auto'){
// this.fixedHeadTable && (this.fixedHeadTable.style.overflowX = 'auto');
// rightBodyTable && (rightBodyTable.style.overflowX = 'auto');
// leftBodyTable && (leftBodyTable.style.overflowX = 'auto');
// }
2019-03-06 14:46:26 +08:00
}
} ;
2018-09-12 14:14:05 +08:00
2017-01-12 08:53:51 +08:00
Table . prototype . onExpandedRowsChange = function onExpandedRowsChange ( expandedRowKeys ) {
if ( ! this . props . expandedRowKeys ) {
this . setState ( { expandedRowKeys : expandedRowKeys } ) ;
}
this . props . onExpandedRowsChange ( expandedRowKeys ) ;
} ;
2017-06-03 20:34:07 +08:00
Table . prototype . onExpanded = function onExpanded ( expanded , record , index , e ) {
2017-01-12 08:53:51 +08:00
if ( e ) {
e . preventDefault ( ) ;
e . stopPropagation ( ) ;
}
2018-10-24 20:00:27 +08:00
var info = this . findExpandedRow ( record ) ;
2017-01-12 08:53:51 +08:00
if ( typeof info !== 'undefined' && ! expanded ) {
2019-11-06 15:03:26 +08:00
this . onRowDestroy ( record , index , true ) ;
2017-01-12 08:53:51 +08:00
} else if ( ! info && expanded ) {
var expandedRows = this . getExpandedRows ( ) . concat ( ) ;
expandedRows . push ( this . getRowKey ( record , index ) ) ;
this . onExpandedRowsChange ( expandedRows ) ;
}
2019-02-25 14:40:28 +08:00
this . props . onExpand ( expanded , record , index ) ;
2017-01-12 08:53:51 +08:00
} ;
2019-11-06 15:03:26 +08:00
Table . prototype . onRowDestroy = function onRowDestroy ( record , rowIndex , isExpandOperation ) {
2017-01-12 08:53:51 +08:00
var expandedRows = this . getExpandedRows ( ) . concat ( ) ;
var rowKey = this . getRowKey ( record , rowIndex ) ;
var index = - 1 ;
expandedRows . forEach ( function ( r , i ) {
if ( r === rowKey ) {
index = i ;
}
} ) ;
if ( index !== - 1 ) {
expandedRows . splice ( index , 1 ) ;
}
2019-03-11 09:53:34 +08:00
//
if ( this . currentHoverKey == rowKey && this . hoverDom ) {
this . hoverDom . style . display = 'none' ;
}
2019-11-06 15:03:26 +08:00
// todo:如果是TableRow组件卸载触发的该方法, 需要加判断, 解决懒加载时, 持续触发onExpandedRowsChange的问题
if ( isExpandOperation ) {
this . onExpandedRowsChange ( expandedRows ) ;
} else {
var info = this . findExpandedRow ( record ) ;
if ( typeof info === 'undefined' ) {
this . onExpandedRowsChange ( expandedRows ) ;
}
}
2017-01-12 08:53:51 +08:00
} ;
Table . prototype . getRowKey = function getRowKey ( record , index ) {
var rowKey = this . props . rowKey ;
var key = typeof rowKey === 'function' ? rowKey ( record , index ) : record [ rowKey ] ;
( 0 , _utils . warningOnce ) ( key !== undefined , 'Each record in table should have a unique `key` prop,' + 'or set `rowKey` to an unique primary key.' ) ;
return key ;
} ;
Table . prototype . getExpandedRows = function getExpandedRows ( ) {
return this . props . expandedRowKeys || this . state . expandedRowKeys ;
} ;
2019-11-14 09:49:40 +08:00
//todo 后续改进
2019-08-17 10:00:40 +08:00
Table . prototype . getHeader = function getHeader ( columns , fixed , leftFixedWidth , rightFixedWidth ) {
2017-01-12 08:53:51 +08:00
var _props = this . props ,
2018-09-27 15:24:29 +08:00
filterDelay = _props . filterDelay ,
2018-12-04 14:29:45 +08:00
onFilterChange = _props . onFilterChange ,
onFilterClear = _props . onFilterClear ,
2018-09-27 15:24:29 +08:00
filterable = _props . filterable ,
2017-01-12 08:53:51 +08:00
showHeader = _props . showHeader ,
expandIconAsCell = _props . expandIconAsCell ,
2018-05-11 09:29:43 +08:00
clsPrefix = _props . clsPrefix ,
onDragStart = _props . onDragStart ,
onDragEnter = _props . onDragEnter ,
onDragOver = _props . onDragOver ,
onDrop = _props . onDrop ,
2019-08-21 16:29:11 +08:00
onDragEnd = _props . onDragEnd ,
2018-05-11 09:29:43 +08:00
draggable = _props . draggable ,
onMouseDown = _props . onMouseDown ,
onMouseMove = _props . onMouseMove ,
onMouseUp = _props . onMouseUp ,
2018-05-14 10:01:06 +08:00
dragborder = _props . dragborder ,
onThMouseMove = _props . onThMouseMove ,
2018-09-12 14:14:05 +08:00
dragborderKey = _props . dragborderKey ,
2018-09-14 13:43:22 +08:00
minColumnWidth = _props . minColumnWidth ,
2018-10-25 19:21:05 +08:00
headerHeight = _props . headerHeight ,
2018-11-22 23:09:53 +08:00
afterDragColWidth = _props . afterDragColWidth ,
headerScroll = _props . headerScroll ,
2019-01-24 19:52:48 +08:00
bordered = _props . bordered ,
2019-08-01 14:39:57 +08:00
onDropBorder = _props . onDropBorder ,
onDraggingBorder = _props . onDraggingBorder ;
2017-01-12 08:53:51 +08:00
var rows = this . getHeaderRows ( columns ) ;
if ( expandIconAsCell && fixed !== 'right' ) {
rows [ 0 ] . unshift ( {
2017-06-03 20:34:07 +08:00
key : 'u-table-expandIconAsCell' ,
2017-01-12 08:53:51 +08:00
className : clsPrefix + '-expand-icon-th' ,
title : '' ,
rowSpan : rows . length
} ) ;
}
2018-11-12 17:49:58 +08:00
var trStyle = headerHeight && ! fixed ? { height : headerHeight } : fixed ? this . getHeaderRowStyle ( columns , rows ) : null ;
2019-08-21 16:29:11 +08:00
var drop = draggable ? { onDragStart : onDragStart , onDragOver : onDragOver , onDrop : onDrop , onDragEnd : onDragEnd , onDragEnter : onDragEnter , draggable : draggable } : { } ;
2019-08-01 14:39:57 +08:00
var dragBorder = dragborder ? { onMouseDown : onMouseDown , onMouseMove : onMouseMove , onMouseUp : onMouseUp , dragborder : dragborder , onThMouseMove : onThMouseMove , dragborderKey : dragborderKey , onDropBorder : onDropBorder , onDraggingBorder : onDraggingBorder } : { } ;
2018-09-12 14:14:05 +08:00
var contentWidthDiff = 0 ;
//非固定表格,宽度不够时自动扩充
if ( ! fixed ) {
contentWidthDiff = this . state . contentWidthDiff ;
}
2018-05-11 09:29:43 +08:00
return showHeader ? _react2 [ "default" ] . createElement ( _TableHeader2 [ "default" ] , _extends ( { } , drop , dragBorder , {
2019-11-14 09:49:40 +08:00
columnsChildrenList : this . columnsChildrenList ,
2018-11-01 14:35:46 +08:00
locale : this . props . locale ,
2018-09-12 14:14:05 +08:00
minColumnWidth : minColumnWidth ,
contentWidthDiff : contentWidthDiff ,
2018-10-16 19:06:18 +08:00
contentWidth : this . contentWidth ,
2018-09-13 10:28:28 +08:00
lastShowIndex : this . state . lastShowIndex ,
2017-01-12 08:53:51 +08:00
clsPrefix : clsPrefix ,
rows : rows ,
2018-09-12 14:14:05 +08:00
contentTable : this . contentTable ,
rowStyle : trStyle ,
2018-09-27 15:24:29 +08:00
fixed : fixed ,
filterable : filterable ,
2018-12-04 14:29:45 +08:00
onFilterChange : onFilterChange ,
onFilterClear : onFilterClear ,
2018-12-03 17:29:39 +08:00
filterDelay : filterDelay ,
2018-11-22 23:09:53 +08:00
afterDragColWidth : afterDragColWidth ,
contentDomWidth : this . contentDomWidth ,
scrollbarWidth : this . scrollbarWidth ,
headerScroll : headerScroll ,
2019-08-17 10:00:40 +08:00
bordered : bordered ,
leftFixedWidth : leftFixedWidth ,
rightFixedWidth : rightFixedWidth
2018-05-11 09:29:43 +08:00
} ) ) : null ;
2017-01-12 08:53:51 +08:00
} ;
Table . prototype . getHeaderRows = function getHeaderRows ( columns ) {
var _this2 = this ;
var currentRow = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : 0 ;
var rows = arguments [ 2 ] ;
2018-11-27 15:23:03 +08:00
var _state = this . state ,
_state$contentWidthDi = _state . contentWidthDiff ,
contentWidthDiff = _state$contentWidthDi === undefined ? 0 : _state$contentWidthDi ,
_state$lastShowIndex = _state . lastShowIndex ,
2018-11-28 11:52:09 +08:00
lastShowIndex = _state$lastShowIndex === undefined ? - 1 : _state$lastShowIndex ;
2017-01-12 08:53:51 +08:00
2018-09-27 15:24:29 +08:00
var filterCol = [ ] ;
2017-01-12 08:53:51 +08:00
rows = rows || [ ] ;
rows [ currentRow ] = rows [ currentRow ] || [ ] ;
2018-11-27 15:23:03 +08:00
columns . forEach ( function ( column , i ) {
2017-01-12 08:53:51 +08:00
if ( column . rowSpan && rows . length < column . rowSpan ) {
while ( rows . length < column . rowSpan ) {
rows . push ( [ ] ) ;
}
}
2018-11-27 15:23:03 +08:00
var width = column . width ;
if ( typeof width == 'string' && width . indexOf ( '%' ) > - 1 && _this2 . contentWidth ) {
width = parseInt ( _this2 . contentWidth * parseInt ( width ) / 100 ) ;
} else if ( width ) {
width = parseInt ( width ) ;
}
if ( lastShowIndex == i && width ) {
width = width + contentWidthDiff ;
}
2017-01-12 08:53:51 +08:00
var cell = {
key : column . key ,
className : column . className || '' ,
2018-05-11 09:29:43 +08:00
children : column . title ,
drgHover : column . drgHover ,
2018-09-12 14:14:05 +08:00
fixed : column . fixed ,
2018-11-27 15:23:03 +08:00
width : width ,
2019-01-17 18:42:57 +08:00
dataindex : column . dataIndex ,
2019-08-26 13:58:29 +08:00
textAlign : column . textAlign ,
titleAlign : column . titleAlign , // 标题水平对齐方式
required : column . required // 标题是否展示必填标志
2017-01-12 08:53:51 +08:00
} ;
2018-05-11 11:37:55 +08:00
if ( column . onHeadCellClick ) {
cell . onClick = column . onHeadCellClick ;
}
2017-01-12 08:53:51 +08:00
if ( column . children ) {
_this2 . getHeaderRows ( column . children , currentRow + 1 , rows ) ;
}
if ( 'colSpan' in column ) {
cell . colSpan = column . colSpan ;
}
if ( 'rowSpan' in column ) {
cell . rowSpan = column . rowSpan ;
}
if ( cell . colSpan !== 0 ) {
rows [ currentRow ] . push ( cell ) ;
}
2018-09-27 15:24:29 +08:00
//判断是否启用过滤
if ( _this2 . props . filterable ) {
//组装Filter需要的Col
filterCol . push ( {
key : column . key ,
children : "过滤渲染" ,
width : column . width ,
2018-11-26 20:42:18 +08:00
filtertype : column . filterType , //下拉的类型 包括['text','dropdown','date','daterange','number']
dataindex : column . dataIndex , //field
datasource : _this2 . props . data , //需要单独拿到数据处理
format : column . format , //设置日期的格式
filterdropdown : column . filterDropdown , //是否显示 show hide
2018-10-11 22:53:27 +08:00
filterdropdownauto : column . filterDropdownAuto , //是否自定义数据
2018-10-15 14:59:53 +08:00
filterdropdowndata : column . filterDropdownData , //自定义数据格式
2018-11-26 20:42:18 +08:00
filterdropdownfocus : column . filterDropdownFocus , //焦点触发函数回调
2018-12-11 16:54:25 +08:00
filterdropdowntype : column . filterDropdownType , //下拉的类型分为 String,Number 默认是String
2018-12-14 10:52:32 +08:00
filterdropdownincludekeys : column . filterDropdownIncludeKeys , //下拉条件按照指定的keys去显示
filterinputnumberoptions : column . filterInputNumberOptions //设置数值框内的详细属性
2018-09-27 15:24:29 +08:00
} ) ;
}
2017-01-12 08:53:51 +08:00
} ) ;
2018-09-27 15:24:29 +08:00
if ( this . props . filterable ) {
rows . push ( filterCol ) ;
}
2017-01-12 08:53:51 +08:00
return rows . filter ( function ( row ) {
return row . length > 0 ;
} ) ;
} ;
Table . prototype . getExpandedRow = function getExpandedRow ( key , content , visible , className , fixed ) {
var _props2 = this . props ,
clsPrefix = _props2 . clsPrefix ,
expandIconAsCell = _props2 . expandIconAsCell ;
var colCount = void 0 ;
if ( fixed === 'left' ) {
colCount = this . columnManager . leftLeafColumns ( ) . length ;
} else if ( fixed === 'right' ) {
colCount = this . columnManager . rightLeafColumns ( ) . length ;
} else {
2019-07-27 14:10:02 +08:00
colCount = this . columnManager . centerColumns ( ) . length ; //计算非固定列的个数, fix: 嵌套表格场景,右侧列断开的问题
2017-01-12 08:53:51 +08:00
}
2018-04-16 14:30:20 +08:00
2019-09-09 10:46:35 +08:00
var expandedRowHeight = this . state . fixedColumnsExpandedRowsHeight [ key ] || 'auto' ;
2018-04-16 14:30:20 +08:00
function contentContainer ( ) {
if ( content && content . props && content . props . style ) {
return _react2 [ "default" ] . createElement ( 'div' , { style : { height : content . props . style . height } } ) ;
} else {
return ' ' ;
}
}
2017-01-12 08:53:51 +08:00
var columns = [ {
key : 'extra-row' ,
render : function render ( ) {
return {
props : {
colSpan : colCount
} ,
2018-09-18 10:36:42 +08:00
children : ! fixed ? content : contentContainer ( )
2017-01-12 08:53:51 +08:00
} ;
}
} ] ;
if ( expandIconAsCell && fixed !== 'right' ) {
columns . unshift ( {
key : 'expand-icon-placeholder' ,
render : function render ( ) {
return null ;
}
} ) ;
}
return _react2 [ "default" ] . createElement ( _TableRow2 [ "default" ] , {
columns : columns ,
visible : visible ,
className : className ,
key : key + '-extra-row' ,
clsPrefix : clsPrefix + '-expanded-row' ,
indent : 1 ,
expandable : false ,
2018-05-14 10:01:06 +08:00
store : this . store ,
2019-04-25 14:19:48 +08:00
dragborderKey : this . props . dragborderKey ,
2019-04-25 15:44:18 +08:00
rowDraggAble : this . props . rowDraggAble ,
2019-07-16 11:30:02 +08:00
onDragRow : this . onDragRow ,
2019-09-09 10:46:35 +08:00
onDragRowStart : this . onDragRowStart ,
height : expandedRowHeight
2017-01-12 08:53:51 +08:00
} ) ;
} ;
2019-04-25 14:19:48 +08:00
2019-07-16 11:30:02 +08:00
/ * *
* 行拖拽开始时触发
* @ param currentKey 当前拖拽目标的key
* /
2019-05-22 18:20:13 +08:00
/ * *
* 行拖拽结束时触发
* @ param currentKey 当前拖拽目标的key
* @ param targetKey 拖拽结束时 , 目标位置的key
* /
2019-05-24 10:59:10 +08:00
/ * *
* 数组元素交换位置
* @ param { array } arr 数组
* @ param { number } index1 添加项目的位置
* @ param { number } index2 删除项目的位置
* /
2019-05-22 18:20:13 +08:00
2019-01-07 14:57:58 +08:00
/ * *
*
*
* @ param { * } data
* @ param { * } visible
* @ param { * } indent 层级
* @ param { * } columns
* @ param { * } fixed
* @ param { number } [ rootIndex = - 1 ] 祖级节点
* @ returns
* @ memberof Table
* /
2017-01-12 08:53:51 +08:00
Table . prototype . getRowsByData = function getRowsByData ( data , visible , indent , columns , fixed ) {
2019-01-07 14:57:58 +08:00
var rootIndex = arguments . length > 5 && arguments [ 5 ] !== undefined ? arguments [ 5 ] : - 1 ;
2017-01-12 08:53:51 +08:00
var props = this . props ;
var childrenColumnName = props . childrenColumnName ;
var expandedRowRender = props . expandedRowRender ;
var expandRowByClick = props . expandRowByClick ;
var fixedColumnsBodyRowsHeight = this . state . fixedColumnsBodyRowsHeight ;
var rst = [ ] ;
2018-09-14 13:43:22 +08:00
var height = void 0 ;
2017-01-12 08:53:51 +08:00
var rowClassName = props . rowClassName ;
var rowRef = props . rowRef ;
var expandedRowClassName = props . expandedRowClassName ;
var needIndentSpaced = props . data . some ( function ( record ) {
return record [ childrenColumnName ] ;
} ) ;
var onRowClick = props . onRowClick ;
var onRowDoubleClick = props . onRowDoubleClick ;
var expandIconAsCell = fixed !== 'right' ? props . expandIconAsCell : false ;
2019-08-26 15:03:04 +08:00
var expandIconColumnIndex = props . expandIconColumnIndex ;
2019-01-07 14:57:58 +08:00
if ( props . lazyLoad && props . lazyLoad . preHeight && indent == 0 ) {
2019-03-20 12:38:43 +08:00
rst . push ( _react2 [ "default" ] . createElement ( _TableRow2 [ "default" ] , { height : props . lazyLoad . preHeight , columns : [ ] , className : '' , key : 'table_row_first' , store : this . store , visible : true } ) ) ;
2018-12-20 09:41:51 +08:00
}
2018-12-20 18:07:30 +08:00
var lazyCurrentIndex = props . lazyLoad && props . lazyLoad . startIndex ? props . lazyLoad . startIndex : 0 ;
2019-01-07 14:57:58 +08:00
var lazyParentIndex = props . lazyLoad && props . lazyLoad . startParentIndex ? props . lazyLoad . startParentIndex : 0 ;
2019-07-02 17:11:40 +08:00
var lazyEndIndex = props . lazyLoad && props . lazyLoad . endIndex ? props . lazyLoad . endIndex : - 1 ;
2017-01-12 08:53:51 +08:00
for ( var i = 0 ; i < data . length ; i ++ ) {
2019-02-25 14:40:28 +08:00
var isHiddenExpandIcon = void 0 ;
2019-08-29 20:43:47 +08:00
// if ( props.showRowNum ){
// switch(props.showRowNum.type){
// case 'number':{
// data[i][props.showRowNum.key || '_index'] = (props.showRowNum.base || 0) + i;
// break;
// }
// case 'ascii': {
// data[i][props.showRowNum.key || '_index'] = String.fromCharCode(i + (props.showRowNum.base || '0').charCodeAt());
// break;
// }
// default: {
// data[i][props.showRowNum.key || '_index'] = (props.showRowNum.base || 0) + i;
// break;
// }
// }
// }
2017-01-12 08:53:51 +08:00
var record = data [ i ] ;
var key = this . getRowKey ( record , i ) ;
2019-08-31 11:32:29 +08:00
var isLeaf = typeof record [ 'isLeaf' ] === 'boolean' && record [ 'isLeaf' ] || false ;
var childrenColumn = isLeaf ? false : record [ childrenColumnName ] ;
2017-01-12 08:53:51 +08:00
var isRowExpanded = this . isRowExpanded ( record , i ) ;
var expandedRowContent = void 0 ;
2018-12-26 16:33:36 +08:00
var expandedContentHeight = 0 ;
2019-02-25 14:40:28 +08:00
//fixedIndex一般是跟index是一个值的, 只有是树结构时, 会讲子节点的值也累计上
var fixedIndex = i ;
//判断是否是tree结构
if ( this . treeType ) {
fixedIndex = this . treeRowIndex ;
}
2017-01-12 08:53:51 +08:00
if ( expandedRowRender && isRowExpanded ) {
2019-02-25 14:40:28 +08:00
expandedRowContent = expandedRowRender ( record , fixedIndex + lazyCurrentIndex , indent ) ;
2019-01-07 14:57:58 +08:00
expandedContentHeight = parseInt ( expandedRowContent . props && expandedRowContent . props . style && expandedRowContent . props . style . height ? expandedRowContent . props . style . height : 0 ) ;
2017-01-12 08:53:51 +08:00
}
2018-01-31 19:46:40 +08:00
//只有当使用expandedRowRender参数的时候才去识别isHiddenExpandIcon( 隐藏行展开的icon)
if ( expandedRowRender && typeof props . haveExpandIcon == 'function' ) {
isHiddenExpandIcon = props . haveExpandIcon ( record , i ) ;
}
2017-01-12 08:53:51 +08:00
var onHoverProps = { } ;
2019-02-18 14:54:33 +08:00
onHoverProps . onHover = this . handleRowHover ;
2019-09-02 17:53:53 +08:00
if ( props . bodyDisplayInRow && props . height ) {
2018-12-20 09:41:51 +08:00
height = props . height ;
2019-03-06 10:42:06 +08:00
} else if ( fixed || props . heightConsistent ) {
2018-12-20 09:41:51 +08:00
height = fixedColumnsBodyRowsHeight [ fixedIndex ] ;
2018-09-14 13:43:22 +08:00
}
2017-01-12 08:53:51 +08:00
var leafColumns = void 0 ;
if ( fixed === 'left' ) {
leafColumns = this . columnManager . leftLeafColumns ( ) ;
} else if ( fixed === 'right' ) {
leafColumns = this . columnManager . rightLeafColumns ( ) ;
} else {
leafColumns = this . columnManager . leafColumns ( ) ;
}
2019-02-25 14:40:28 +08:00
var className = rowClassName ( record , fixedIndex + lazyCurrentIndex , indent ) ;
2017-01-12 08:53:51 +08:00
2018-12-16 22:22:45 +08:00
//合计代码如果是最后一行并且有合计功能时,最后一行为合计列
if ( i == data . length - 1 && props . showSum ) {
className = className + ' sumrow' ;
}
2019-01-07 14:57:58 +08:00
var paramRootIndex = rootIndex ;
//小于0说明为第一层节点, 她的子孙节点要保存自己的根节点
if ( paramRootIndex < 0 ) {
paramRootIndex = i + lazyParentIndex ;
}
var index = i ;
if ( rootIndex == - 1 ) {
index = i + lazyParentIndex ;
}
2017-01-12 08:53:51 +08:00
rst . push ( _react2 [ "default" ] . createElement ( _TableRow2 [ "default" ] , _extends ( {
indent : indent ,
indentSize : props . indentSize ,
needIndentSpaced : needIndentSpaced ,
2019-04-26 18:10:57 +08:00
className : className + ' ' + ( this . props . rowDraggAble ? ' row-dragg-able ' : '' ) ,
2017-01-12 08:53:51 +08:00
record : record ,
expandIconAsCell : expandIconAsCell ,
onDestroy : this . onRowDestroy ,
2019-01-07 14:57:58 +08:00
index : index ,
2017-01-12 08:53:51 +08:00
visible : visible ,
expandRowByClick : expandRowByClick ,
onExpand : this . onExpanded ,
2019-02-26 16:57:47 +08:00
expandable : childrenColumn || expandedRowRender ,
2017-01-12 08:53:51 +08:00
expanded : isRowExpanded ,
clsPrefix : props . clsPrefix + '-row' ,
childrenColumnName : childrenColumnName ,
columns : leafColumns ,
expandIconColumnIndex : expandIconColumnIndex ,
onRowClick : onRowClick ,
onRowDoubleClick : onRowDoubleClick ,
2018-01-31 19:46:40 +08:00
height : height ,
isHiddenExpandIcon : isHiddenExpandIcon
2017-01-12 08:53:51 +08:00
} , onHoverProps , {
2019-03-20 12:38:43 +08:00
key : "table_row_" + key + "_" + index ,
2017-01-12 08:53:51 +08:00
hoverKey : key ,
2017-10-26 16:39:21 +08:00
ref : rowRef ,
2018-09-12 14:14:05 +08:00
store : this . store ,
2018-12-20 09:41:51 +08:00
fixed : fixed ,
expandedContentHeight : expandedContentHeight ,
2019-01-07 14:57:58 +08:00
setRowHeight : props . setRowHeight ,
setRowParentIndex : props . setRowParentIndex ,
treeType : childrenColumn || this . treeType ? true : false ,
fixedIndex : fixedIndex + lazyCurrentIndex ,
2019-02-25 14:40:28 +08:00
rootIndex : rootIndex ,
2019-04-23 16:04:02 +08:00
syncHover : props . syncHover ,
2019-04-25 14:19:48 +08:00
bodyDisplayInRow : props . bodyDisplayInRow ,
2019-04-25 15:44:18 +08:00
rowDraggAble : this . props . rowDraggAble ,
2019-04-25 14:19:48 +08:00
onDragRow : this . onDragRow ,
2019-07-16 11:30:02 +08:00
onDragRowStart : this . onDragRowStart ,
2019-04-26 18:10:57 +08:00
contentTable : this . contentTable ,
2019-05-10 09:40:48 +08:00
tableUid : this . tableUid ,
expandedIcon : props . expandedIcon ,
2019-07-02 17:11:40 +08:00
collapsedIcon : props . collapsedIcon ,
lazyStartIndex : lazyCurrentIndex ,
2019-08-26 15:03:04 +08:00
lazyEndIndex : lazyEndIndex ,
centerColumnsLength : this . centerColumnsLength ,
leftColumnsLength : this . leftColumnsLength
2017-01-12 08:53:51 +08:00
} ) ) ) ;
2018-08-29 14:54:30 +08:00
this . treeRowIndex ++ ;
2017-01-12 08:53:51 +08:00
var subVisible = visible && isRowExpanded ;
if ( expandedRowContent && isRowExpanded ) {
rst . push ( this . getExpandedRow ( key , expandedRowContent , subVisible , expandedRowClassName ( record , i , indent ) , fixed ) ) ;
}
if ( childrenColumn ) {
2019-09-11 21:08:18 +08:00
this . isTreeType = true ; //增加该标志位,为了兼容老版本,不修改以前的 `this.treeType` 的相关逻辑
2018-12-20 09:41:51 +08:00
this . treeType = true ; //证明是tree表形式visible = {true}
2019-01-07 14:57:58 +08:00
rst = rst . concat ( this . getRowsByData ( childrenColumn , subVisible , indent + 1 , columns , fixed , paramRootIndex ) ) ;
2017-01-12 08:53:51 +08:00
}
}
2018-12-20 09:41:51 +08:00
2019-01-07 14:57:58 +08:00
if ( props . lazyLoad && props . lazyLoad . sufHeight && indent == 0 ) {
2019-03-20 12:38:43 +08:00
rst . push ( _react2 [ "default" ] . createElement ( _TableRow2 [ "default" ] , { height : props . lazyLoad . sufHeight , key : 'table_row_end' , columns : [ ] , className : '' , store : this . store , visible : true } ) ) ;
2018-12-20 09:41:51 +08:00
}
2019-09-11 21:08:18 +08:00
if ( ! this . isTreeType ) {
this . treeType = false ;
}
2017-01-12 08:53:51 +08:00
return rst ;
} ;
Table . prototype . getRows = function getRows ( columns , fixed ) {
2019-07-11 20:52:45 +08:00
//统计index, 只有含有树表结构才有用, 因为树表结构时, 固定列的索引取值有问题
2018-08-29 14:54:30 +08:00
this . treeRowIndex = 0 ;
2019-09-11 21:08:18 +08:00
//每次遍历 data 前, 将this.isTreeType置为 false, 若遍历完 data, 此变量仍为 false, 说明是普通表格
this . isTreeType = false ;
2019-03-20 12:38:43 +08:00
var rs = this . getRowsByData ( this . state . data , true , 0 , columns , fixed ) ;
return rs ;
2017-01-12 08:53:51 +08:00
} ;
Table . prototype . getColGroup = function getColGroup ( columns , fixed ) {
2018-12-06 13:39:51 +08:00
var _this3 = this ;
2017-01-12 08:53:51 +08:00
var cols = [ ] ;
2018-10-08 15:41:14 +08:00
var self = this ;
2018-12-06 13:39:51 +08:00
2018-11-27 15:23:03 +08:00
var _state2 = this . state ,
_state2$contentWidthD = _state2 . contentWidthDiff ,
contentWidthDiff = _state2$contentWidthD === undefined ? 0 : _state2$contentWidthD ,
_state2$lastShowIndex = _state2 . lastShowIndex ,
lastShowIndex = _state2$lastShowIndex === undefined ? 0 : _state2$lastShowIndex ;
2018-09-12 14:14:05 +08:00
2017-01-12 08:53:51 +08:00
if ( this . props . expandIconAsCell && fixed !== 'right' ) {
cols . push ( _react2 [ "default" ] . createElement ( 'col' , {
className : this . props . clsPrefix + '-expand-icon-col' ,
2017-06-03 20:34:07 +08:00
key : 'u-table-expand-icon-col'
2017-01-12 08:53:51 +08:00
} ) ) ;
}
var leafColumns = void 0 ;
if ( fixed === 'left' ) {
2018-09-12 14:14:05 +08:00
contentWidthDiff = 0 ;
2017-01-12 08:53:51 +08:00
leafColumns = this . columnManager . leftLeafColumns ( ) ;
} else if ( fixed === 'right' ) {
2018-09-12 14:14:05 +08:00
contentWidthDiff = 0 ;
2017-01-12 08:53:51 +08:00
leafColumns = this . columnManager . rightLeafColumns ( ) ;
} else {
leafColumns = this . columnManager . leafColumns ( ) ;
}
2018-09-12 14:14:05 +08:00
cols = cols . concat ( leafColumns . map ( function ( c , i , arr ) {
2018-12-06 13:39:51 +08:00
var fixedClass = '' ;
2018-09-12 14:14:05 +08:00
var width = c . width ;
2018-10-11 14:12:19 +08:00
if ( typeof width == 'string' && width . indexOf ( '%' ) > - 1 && self . contentWidth ) {
2018-10-08 15:41:14 +08:00
width = parseInt ( self . contentWidth * parseInt ( width ) / 100 ) ;
2018-10-11 14:12:19 +08:00
} else if ( width ) {
2018-10-08 15:41:14 +08:00
width = parseInt ( width ) ;
}
2018-11-21 22:23:40 +08:00
if ( lastShowIndex == i && width ) {
2018-10-08 15:41:14 +08:00
width = width + contentWidthDiff ;
2018-09-12 14:14:05 +08:00
}
2018-12-06 13:39:51 +08:00
if ( ! fixed && c . fixed ) {
2018-12-20 09:41:51 +08:00
fixedClass = ' ' + _this3 . props . clsPrefix + '-row-fixed-columns-in-body' ;
2018-12-06 13:39:51 +08:00
}
return _react2 [ "default" ] . createElement ( 'col' , { key : c . key , style : { width : width , minWidth : c . width } , className : fixedClass } ) ;
2017-01-12 08:53:51 +08:00
} ) ) ;
return _react2 [ "default" ] . createElement (
'colgroup' ,
2019-01-24 19:52:48 +08:00
{ id : 'bee-table-colgroup' } ,
2017-01-12 08:53:51 +08:00
cols
) ;
} ;
Table . prototype . getLeftFixedTable = function getLeftFixedTable ( ) {
return this . getTable ( {
columns : this . columnManager . leftColumns ( ) ,
fixed : 'left'
} ) ;
} ;
Table . prototype . getRightFixedTable = function getRightFixedTable ( ) {
return this . getTable ( {
columns : this . columnManager . rightColumns ( ) ,
fixed : 'right'
} ) ;
} ;
Table . prototype . getTable = function getTable ( ) {
2018-12-06 13:39:51 +08:00
var _this4 = this ;
2017-01-12 08:53:51 +08:00
var options = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : { } ;
var columns = options . columns ,
fixed = options . fixed ;
var _props3 = this . props ,
clsPrefix = _props3 . clsPrefix ,
_props3$scroll = _props3 . scroll ,
scroll = _props3$scroll === undefined ? { } : _props3$scroll ,
2018-01-03 14:19:24 +08:00
getBodyWrapper = _props3 . getBodyWrapper ,
2018-10-30 16:40:25 +08:00
footerScroll = _props3 . footerScroll ,
2019-07-09 11:09:51 +08:00
headerScroll = _props3 . headerScroll ,
_props3$hideHeaderScr = _props3 . hideHeaderScroll ,
2019-07-11 20:52:45 +08:00
hideHeaderScroll = _props3$hideHeaderScr === undefined ? false : _props3$hideHeaderScr ,
expandIconAsCell = _props3 . expandIconAsCell ;
2019-05-22 14:19:13 +08:00
var _props4 = this . props ,
useFixedHeader = _props4 . useFixedHeader ,
data = _props4 . data ;
2017-01-12 08:53:51 +08:00
2019-08-23 13:48:27 +08:00
var bodyStyle = _extends ( { } , this . props . bodyStyle ) ; // 这里为什么不写在上面?
2017-01-12 08:53:51 +08:00
var headStyle = { } ;
2018-10-26 15:04:25 +08:00
var innerBodyStyle = { } ;
2019-08-17 10:00:40 +08:00
var leftFixedWidth = this . columnManager . getLeftColumnsWidth ( this . contentWidth ) ;
var rightFixedWidth = this . columnManager . getRightColumnsWidth ( this . contentWidth ) ;
2017-01-12 08:53:51 +08:00
var tableClassName = '' ;
2018-09-15 13:47:32 +08:00
//表格元素的宽度大于容器的宽度也显示滚动条
if ( scroll . x || fixed || this . contentDomWidth < this . contentWidth ) {
2017-01-12 08:53:51 +08:00
tableClassName = clsPrefix + '-fixed' ;
2018-12-06 16:41:35 +08:00
//没有数据并且含有顶部菜单时
if ( this . props . data . length == 0 && this . props . headerScroll ) {
bodyStyle . overflowX = 'hidden' ;
}
2018-01-03 14:19:24 +08:00
if ( ! footerScroll ) {
bodyStyle . overflowX = bodyStyle . overflowX || 'auto' ;
}
2017-01-12 08:53:51 +08:00
}
if ( scroll . y ) {
// maxHeight will make fixed-Table scrolling not working
// so we only set maxHeight to body-Table here
if ( fixed ) {
2018-10-26 15:04:25 +08:00
// bodyStyle.height = bodyStyle.height || scroll.y;
innerBodyStyle . maxHeight = bodyStyle . maxHeight || scroll . y ;
2018-11-06 16:37:45 +08:00
innerBodyStyle . overflowY = bodyStyle . overflowY || 'scroll' ;
2017-01-12 08:53:51 +08:00
} else {
bodyStyle . maxHeight = bodyStyle . maxHeight || scroll . y ;
}
2018-11-06 16:37:45 +08:00
bodyStyle . overflowY = bodyStyle . overflowY || 'scroll' ;
2017-01-12 08:53:51 +08:00
useFixedHeader = true ;
// Add negative margin bottom for scroll bar overflow bug
2018-11-30 16:31:53 +08:00
var scrollbarWidth = this . scrollbarWidth ;
2018-01-03 14:19:24 +08:00
if ( scrollbarWidth >= 0 ) {
2017-01-12 08:53:51 +08:00
( fixed ? bodyStyle : headStyle ) . paddingBottom = '0px' ;
2018-10-30 16:40:25 +08:00
//显示表头滚动条
if ( headerScroll ) {
if ( fixed ) {
2019-02-26 16:57:00 +08:00
2018-11-13 14:36:12 +08:00
if ( this . domWidthDiff <= 0 ) {
headStyle . marginBottom = scrollbarWidth + 'px' ;
2019-05-22 18:07:03 +08:00
bodyStyle . marginBottom = '-' + scrollbarWidth + 'px' ;
2018-11-13 14:36:12 +08:00
} else {
innerBodyStyle . overflowX = 'auto' ;
}
2018-10-30 16:40:25 +08:00
} else {
2018-11-13 14:36:12 +08:00
//内容少,不用显示滚动条
if ( this . domWidthDiff > 0 ) {
2018-11-28 15:36:11 +08:00
headStyle . overflowX = 'hidden' ;
2018-11-13 14:36:12 +08:00
}
2018-10-30 16:40:25 +08:00
headStyle . marginBottom = '0px' ;
}
} else {
2018-11-12 17:50:47 +08:00
if ( fixed ) {
if ( this . domWidthDiff > 0 ) {
2019-01-27 16:52:11 +08:00
headStyle . overflow = 'hidden' ;
2019-08-17 11:36:55 +08:00
innerBodyStyle . overflowX = 'auto' ; //兼容expand场景、子表格含有固定列的场景
2018-11-12 17:50:47 +08:00
} else {
2019-05-22 18:07:03 +08:00
bodyStyle . marginBottom = '-' + scrollbarWidth + 'px' ;
}
2018-11-12 17:50:47 +08:00
} else {
2019-05-22 14:19:13 +08:00
// 没有数据时,表头滚动条隐藏问题
if ( data . length == 0 && this . domWidthDiff < 0 ) {
headStyle . marginBottom = '0px' ;
} else {
headStyle . marginBottom = '-' + scrollbarWidth + 'px' ;
}
2018-11-12 17:50:47 +08:00
}
2018-10-30 16:40:25 +08:00
}
2017-01-12 08:53:51 +08:00
}
}
2019-07-09 15:18:32 +08:00
if ( data . length == 0 && hideHeaderScroll ) {
//支持 NCC 需求:表格无数据时,去掉表头滚动条 (https://github.com/iuap-design/tinper-bee/issues/207)
headStyle . marginBottom = '-' + this . scrollbarWidth + 'px' ;
}
2017-01-12 08:53:51 +08:00
var renderTable = function renderTable ( ) {
var hasHead = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : true ;
var hasBody = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : true ;
var tableStyle = { } ;
if ( ! fixed && scroll . x ) {
// not set width, then use content fixed width
if ( scroll . x === true ) {
tableStyle . tableLayout = 'fixed' ;
} else {
2018-12-24 17:13:56 +08:00
tableStyle . width = _this4 . contentWidth - _this4 . columnManager . getLeftColumnsWidth ( _this4 . contentWidth ) - _this4 . columnManager . getRightColumnsWidth ( _this4 . contentWidth ) ;
2017-01-12 08:53:51 +08:00
}
}
2018-10-11 14:12:19 +08:00
// 自动出现滚动条
2018-12-06 13:39:51 +08:00
if ( ! fixed && _this4 . contentDomWidth < _this4 . contentWidth ) {
2018-12-24 17:13:56 +08:00
tableStyle . width = _this4 . contentWidth - _this4 . columnManager . getLeftColumnsWidth ( _this4 . contentWidth ) - _this4 . columnManager . getRightColumnsWidth ( _this4 . contentWidth ) ;
2018-10-11 14:12:19 +08:00
}
2017-01-12 08:53:51 +08:00
var tableBody = hasBody ? getBodyWrapper ( _react2 [ "default" ] . createElement (
'tbody' ,
2019-02-18 14:54:33 +08:00
{ className : clsPrefix + '-tbody' , onMouseLeave : _this4 . onBodyMouseLeave } ,
2018-12-06 13:39:51 +08:00
_this4 . getRows ( columns , fixed )
2017-01-12 08:53:51 +08:00
) ) : null ;
2018-12-06 13:39:51 +08:00
var _drag _class = _this4 . props . dragborder ? "table-drag-bordered" : "" ;
2017-01-12 08:53:51 +08:00
return _react2 [ "default" ] . createElement (
'table' ,
2019-05-31 15:33:59 +08:00
{ className : ' ' + tableClassName + ' table-bordered ' + _drag _class + ' ' , style : tableStyle } ,
2018-12-06 13:39:51 +08:00
_this4 . getColGroup ( columns , fixed ) ,
2019-08-17 10:00:40 +08:00
hasHead ? _this4 . getHeader ( columns , fixed , leftFixedWidth , rightFixedWidth ) : null ,
2017-01-12 08:53:51 +08:00
tableBody
) ;
} ;
var headTable = void 0 ;
if ( useFixedHeader ) {
headTable = _react2 [ "default" ] . createElement (
'div' ,
{
className : clsPrefix + '-header' ,
2019-05-22 14:19:13 +08:00
ref : function ref ( el ) {
fixed ? _this4 . fixedHeadTable = el : _this4 . headTable = el ;
} ,
2017-01-12 08:53:51 +08:00
style : headStyle ,
onMouseOver : this . detectScrollTarget ,
onTouchStart : this . detectScrollTarget ,
onScroll : this . handleBodyScroll
} ,
renderTable ( true , false )
) ;
}
var BodyTable = _react2 [ "default" ] . createElement (
'div' ,
{
className : clsPrefix + '-body' ,
style : bodyStyle ,
2019-05-05 14:07:34 +08:00
ref : function ref ( el ) {
_this4 . bodyTable = el ;
} ,
2017-01-12 08:53:51 +08:00
onMouseOver : this . detectScrollTarget ,
onTouchStart : this . detectScrollTarget ,
2019-02-18 14:54:33 +08:00
onScroll : this . handleBodyScroll ,
onMouseLeave : this . onBodyMouseLeave
2017-01-12 08:53:51 +08:00
} ,
2018-05-11 11:30:56 +08:00
this . renderDragHideTable ( ) ,
2017-01-12 08:53:51 +08:00
renderTable ( ! useFixedHeader )
) ;
if ( fixed && columns . length ) {
var refName = void 0 ;
if ( columns [ 0 ] . fixed === 'left' || columns [ 0 ] . fixed === true ) {
refName = 'fixedColumnsBodyLeft' ;
} else if ( columns [ 0 ] . fixed === 'right' ) {
refName = 'fixedColumnsBodyRight' ;
}
delete bodyStyle . overflowX ;
delete bodyStyle . overflowY ;
BodyTable = _react2 [ "default" ] . createElement (
'div' ,
{
className : clsPrefix + '-body-outer' ,
style : _extends ( { } , bodyStyle )
} ,
_react2 [ "default" ] . createElement (
'div' ,
{
2018-10-26 15:04:25 +08:00
style : _extends ( { } , innerBodyStyle ) ,
2017-01-12 08:53:51 +08:00
className : clsPrefix + '-body-inner' ,
ref : refName ,
onMouseOver : this . detectScrollTarget ,
onTouchStart : this . detectScrollTarget ,
onScroll : this . handleBodyScroll
} ,
2019-05-10 13:21:33 +08:00
renderTable ( ! useFixedHeader )
2017-01-12 08:53:51 +08:00
)
) ;
}
2019-08-17 10:00:40 +08:00
// const leftFixedWidth = this.columnManager.getLeftColumnsWidth(this.contentWidth);
// const rightFixedWidth = this.columnManager.getRightColumnsWidth(this.contentWidth);
2019-07-11 20:52:45 +08:00
var expandIconWidth = expandIconAsCell ? 33 : 0 ;
2018-12-16 22:22:45 +08:00
var parStyle = { } ;
if ( ! fixed ) {
2019-07-11 20:52:45 +08:00
parStyle = { 'marginLeft' : leftFixedWidth + expandIconWidth , 'marginRight' : rightFixedWidth } ;
2018-12-16 22:22:45 +08:00
}
2017-01-12 08:53:51 +08:00
return _react2 [ "default" ] . createElement (
2018-12-16 22:22:45 +08:00
'div' ,
{ style : parStyle } ,
2017-01-12 08:53:51 +08:00
headTable ,
BodyTable
) ;
} ;
Table . prototype . getTitle = function getTitle ( ) {
2019-05-22 14:19:13 +08:00
var _props5 = this . props ,
title = _props5 . title ,
clsPrefix = _props5 . clsPrefix ;
2017-01-12 08:53:51 +08:00
return title ? _react2 [ "default" ] . createElement (
'div' ,
{ className : clsPrefix + '-title' } ,
title ( this . state . data )
) : null ;
} ;
Table . prototype . getFooter = function getFooter ( ) {
2019-05-22 14:19:13 +08:00
var _props6 = this . props ,
footer = _props6 . footer ,
clsPrefix = _props6 . clsPrefix ;
2017-01-12 08:53:51 +08:00
return footer ? _react2 [ "default" ] . createElement (
'div' ,
{ className : clsPrefix + '-footer' } ,
footer ( this . state . data )
) : null ;
} ;
Table . prototype . getEmptyText = function getEmptyText ( ) {
2019-05-22 14:19:13 +08:00
var _props7 = this . props ,
2019-05-22 14:20:04 +08:00
defaultEmptyText = _props7 . emptyText ,
2019-05-22 14:19:13 +08:00
clsPrefix = _props7 . clsPrefix ,
data = _props7 . data ;
2017-01-12 08:53:51 +08:00
2019-05-21 19:31:38 +08:00
var locale = ( 0 , _tool . getComponentLocale ) ( this . props , this . context , 'Table' , function ( ) {
return _i18n2 [ "default" ] ;
} ) ;
2019-05-22 15:47:15 +08:00
var emptyText = defaultEmptyText !== undefined ? defaultEmptyText : function ( ) {
2019-05-21 19:31:38 +08:00
return _react2 [ "default" ] . createElement (
'div' ,
null ,
_react2 [ "default" ] . createElement ( _beeIcon2 [ "default" ] , { type : 'uf-nodata' , className : 'table-nodata' } ) ,
_react2 [ "default" ] . createElement (
'span' ,
null ,
locale [ "no_data" ]
)
) ;
} ;
2017-01-12 08:53:51 +08:00
return ! data . length ? _react2 [ "default" ] . createElement (
'div' ,
{ className : clsPrefix + '-placeholder' } ,
emptyText ( )
) : null ;
} ;
Table . prototype . getHeaderRowStyle = function getHeaderRowStyle ( columns , rows ) {
var fixedColumnsHeadRowsHeight = this . state . fixedColumnsHeadRowsHeight ;
var headerHeight = fixedColumnsHeadRowsHeight [ 0 ] ;
2018-09-14 13:43:22 +08:00
2017-01-12 08:53:51 +08:00
if ( headerHeight && columns ) {
if ( headerHeight === 'auto' ) {
return { height : 'auto' } ;
}
return { height : headerHeight / rows . length } ;
}
return null ;
} ;
Table . prototype . syncFixedTableRowHeight = function syncFixedTableRowHeight ( ) {
2018-09-14 13:43:22 +08:00
//this.props.height、headerHeight分别为用户传入的行高和表头高度, 如果有值, 所有行的高度都是固定的, 主要为了避免在千行数据中有固定列时获取行高度有问题
2019-05-22 14:19:13 +08:00
var _props8 = this . props ,
clsPrefix = _props8 . clsPrefix ,
height = _props8 . height ,
headerHeight = _props8 . headerHeight ,
columns = _props8 . columns ,
2019-09-02 17:53:53 +08:00
heightConsistent = _props8 . heightConsistent ,
bodyDisplayInRow = _props8 . bodyDisplayInRow ;
2017-01-12 08:53:51 +08:00
2019-05-22 14:19:13 +08:00
var headRows = this . headTable ? this . headTable . querySelectorAll ( 'thead' ) : this . bodyTable . querySelectorAll ( 'thead' ) ;
2019-09-09 10:46:35 +08:00
var expandedRows = this . bodyTable . querySelectorAll ( '.' + clsPrefix + '-expanded-row' ) || [ ] ;
2019-05-05 14:07:34 +08:00
var bodyRows = this . bodyTable . querySelectorAll ( '.' + clsPrefix + '-row' ) || [ ] ;
2019-03-06 10:42:06 +08:00
var leftBodyRows = this . refs . fixedColumnsBodyLeft && this . refs . fixedColumnsBodyLeft . querySelectorAll ( '.' + clsPrefix + '-row' ) || [ ] ;
var rightBodyRows = this . refs . fixedColumnsBodyRight && this . refs . fixedColumnsBodyRight . querySelectorAll ( '.' + clsPrefix + '-row' ) || [ ] ;
2017-01-12 08:53:51 +08:00
var fixedColumnsHeadRowsHeight = [ ] . map . call ( headRows , function ( row ) {
2018-11-12 17:49:58 +08:00
var height = headerHeight ;
if ( headerHeight ) {
height = ( ( 0 , _utils . getMaxColChildrenLength ) ( columns ) + 1 ) * headerHeight ;
}
return headerHeight ? height : row . getBoundingClientRect ( ) . height || 'auto' ;
2017-01-12 08:53:51 +08:00
} ) ;
2019-03-06 10:42:06 +08:00
var fixedColumnsBodyRowsHeight = [ ] . map . call ( bodyRows , function ( row , index ) {
var rsHeight = height ;
2019-09-02 17:53:53 +08:00
if ( bodyDisplayInRow && rsHeight ) {
2019-03-06 10:42:06 +08:00
return rsHeight ;
} else {
// 为了提高性能,默认获取主表的高度,但是有的场景中固定列的高度比主表的高度高,所以提供此属性,会统计所有列的高度取最大的,设置
2019-09-02 17:53:53 +08:00
// 内容折行显示,并又设置了 height 的情况下,也要获取主表高度
if ( heightConsistent || ! bodyDisplayInRow && rsHeight ) {
2019-03-06 10:42:06 +08:00
var leftHeight = void 0 ,
rightHeight = void 0 ,
currentHeight = void 0 ,
maxHeight = void 0 ;
leftHeight = leftBodyRows [ index ] ? leftBodyRows [ index ] . getBoundingClientRect ( ) . height : 0 ;
rightHeight = rightBodyRows [ index ] ? rightBodyRows [ index ] . getBoundingClientRect ( ) . height : 0 ;
currentHeight = row . getBoundingClientRect ( ) . height ;
maxHeight = Math . max ( leftHeight , rightHeight , currentHeight ) ;
return maxHeight || 'auto' ;
} else {
return row . getBoundingClientRect ( ) . height || 'auto' ;
}
}
2017-01-12 08:53:51 +08:00
} ) ;
2019-09-09 10:46:35 +08:00
var fixedColumnsExpandedRowsHeight = { } ;
expandedRows . length > 0 && expandedRows . forEach ( function ( row ) {
var parentRowKey = row && row . previousSibling && row . previousSibling . getAttribute ( "data-row-key" ) ,
height = row && row . getBoundingClientRect ( ) . height || 'auto' ;
fixedColumnsExpandedRowsHeight [ parentRowKey ] = height ;
} ) ;
if ( ( 0 , _shallowequal2 [ "default" ] ) ( this . state . fixedColumnsHeadRowsHeight , fixedColumnsHeadRowsHeight ) && ( 0 , _shallowequal2 [ "default" ] ) ( this . state . fixedColumnsBodyRowsHeight , fixedColumnsBodyRowsHeight ) && ( 0 , _shallowequal2 [ "default" ] ) ( this . state . fixedColumnsExpandedRowsHeight , fixedColumnsExpandedRowsHeight ) ) {
2017-01-12 08:53:51 +08:00
return ;
}
this . setState ( {
fixedColumnsHeadRowsHeight : fixedColumnsHeadRowsHeight ,
2019-09-09 10:46:35 +08:00
fixedColumnsBodyRowsHeight : fixedColumnsBodyRowsHeight ,
fixedColumnsExpandedRowsHeight : fixedColumnsExpandedRowsHeight
2017-01-12 08:53:51 +08:00
} ) ;
} ;
2019-03-01 16:59:17 +08:00
Table . prototype . resetScrollX = function resetScrollX ( ) {
2019-05-22 14:19:13 +08:00
if ( this . headTable ) {
this . headTable . scrollLeft = 0 ;
2017-01-12 08:53:51 +08:00
}
2019-05-05 14:07:34 +08:00
if ( this . bodyTable ) {
this . bodyTable . scrollLeft = 0 ;
2017-01-12 08:53:51 +08:00
}
} ;
Table . prototype . findExpandedRow = function findExpandedRow ( record , index ) {
2018-12-06 13:39:51 +08:00
var _this5 = this ;
2017-01-12 08:53:51 +08:00
2018-10-24 20:00:27 +08:00
var rows = this . getExpandedRows ( ) . filter ( function ( i ) {
2018-12-06 13:39:51 +08:00
return i === _this5 . getRowKey ( record , index ) ;
2017-01-12 08:53:51 +08:00
} ) ;
return rows [ 0 ] ;
} ;
Table . prototype . isRowExpanded = function isRowExpanded ( record , index ) {
return typeof this . findExpandedRow ( record , index ) !== 'undefined' ;
} ;
2019-02-18 14:54:33 +08:00
Table . prototype . onBodyMouseLeave = function onBodyMouseLeave ( e ) {
this . hideHoverDom ( e ) ;
} ;
2017-01-12 08:53:51 +08:00
Table . prototype . detectScrollTarget = function detectScrollTarget ( e ) {
if ( this . scrollTarget !== e . currentTarget ) {
this . scrollTarget = e . currentTarget ;
}
} ;
2019-02-18 14:54:33 +08:00
Table . prototype . hideHoverDom = function hideHoverDom ( e ) {
if ( this . hoverDom ) {
this . hoverDom . style . display = 'none' ;
}
} ;
2017-01-12 08:53:51 +08:00
Table . prototype . handleBodyScroll = function handleBodyScroll ( e ) {
2019-05-22 14:19:13 +08:00
var headTable = this . headTable ;
var _props9 = this . props ,
_props9$scroll = _props9 . scroll ,
scroll = _props9$scroll === undefined ? { } : _props9$scroll ,
clsPrefix = _props9 . clsPrefix ,
handleScrollY = _props9 . handleScrollY ,
2019-08-27 11:10:47 +08:00
handleScrollX = _props9 . handleScrollX ,
onBodyScroll = _props9 . onBodyScroll ;
2017-01-12 08:53:51 +08:00
var _refs = this . refs ,
fixedColumnsBodyLeft = _refs . fixedColumnsBodyLeft ,
fixedColumnsBodyRight = _refs . fixedColumnsBodyRight ;
2018-06-06 11:57:26 +08:00
// Prevent scrollTop setter trigger onScroll event
// http://stackoverflow.com/q/1386696
2017-01-12 08:53:51 +08:00
2019-02-26 16:57:00 +08:00
if ( e . currentTarget !== e . target ) {
2018-06-06 11:57:26 +08:00
return ;
}
2018-09-27 15:24:29 +08:00
if ( e . target . scrollLeft !== this . lastScrollLeft ) {
2018-12-03 16:55:10 +08:00
var position = '' ;
2019-05-08 17:29:40 +08:00
if ( e . target === this . bodyTable && headTable ) {
2017-01-12 08:53:51 +08:00
headTable . scrollLeft = e . target . scrollLeft ;
2019-05-08 17:29:40 +08:00
} else if ( e . target === headTable && this . bodyTable ) {
this . bodyTable . scrollLeft = e . target . scrollLeft ;
2017-01-12 08:53:51 +08:00
}
if ( e . target . scrollLeft === 0 ) {
2018-12-03 16:55:10 +08:00
position = 'left' ;
2017-01-12 08:53:51 +08:00
} else if ( e . target . scrollLeft + 1 >= e . target . children [ 0 ] . getBoundingClientRect ( ) . width - e . target . getBoundingClientRect ( ) . width ) {
2018-12-03 16:55:10 +08:00
position = 'right' ;
2017-01-12 08:53:51 +08:00
} else if ( this . state . scrollPosition !== 'middle' ) {
2018-12-03 16:55:10 +08:00
position = 'middle' ;
}
if ( position ) {
2018-12-03 17:29:39 +08:00
( 0 , _componentClasses2 [ "default" ] ) ( this . contentTable ) . remove ( new RegExp ( '^' + clsPrefix + '-scroll-position-.+$' ) ) . add ( clsPrefix + '-scroll-position-' + position ) ;
2017-01-12 08:53:51 +08:00
}
2019-01-10 19:42:30 +08:00
if ( handleScrollX ) {
( 0 , _utils . debounce ) ( handleScrollX ( e . target . scrollLeft , this . treeType ) , 300 ) ;
}
2017-01-12 08:53:51 +08:00
}
2019-01-07 15:01:11 +08:00
// console.log('lastScrollTop--'+this.lastScrollTop+'--eventScrollTop--'+ e.target.scrollTop);
2019-03-01 16:59:17 +08:00
if ( scroll . y && this . lastScrollTop != e . target . scrollTop && e . target !== headTable ) {
2017-01-12 08:53:51 +08:00
if ( fixedColumnsBodyLeft && e . target !== fixedColumnsBodyLeft ) {
fixedColumnsBodyLeft . scrollTop = e . target . scrollTop ;
}
if ( fixedColumnsBodyRight && e . target !== fixedColumnsBodyRight ) {
fixedColumnsBodyRight . scrollTop = e . target . scrollTop ;
}
2019-05-08 17:29:40 +08:00
if ( this . bodyTable && e . target !== this . bodyTable ) {
this . bodyTable . scrollTop = e . target . scrollTop ;
2017-01-12 08:53:51 +08:00
}
2019-02-19 09:30:18 +08:00
if ( this . hoverDom ) {
this . hoverDom . style . display = 'none' ;
}
2018-12-20 09:41:51 +08:00
this . lastScrollTop = e . target . scrollTop ;
2019-01-10 19:42:30 +08:00
if ( handleScrollY ) {
2019-08-27 11:10:47 +08:00
( 0 , _utils . debounce ) ( handleScrollY ( this . lastScrollTop , this . treeType , onBodyScroll ) , 300 ) ;
2018-12-20 09:41:51 +08:00
}
2017-01-12 08:53:51 +08:00
}
2018-12-20 09:41:51 +08:00
2017-01-12 08:53:51 +08:00
// Remember last scrollLeft for scroll direction detecting.
this . lastScrollLeft = e . target . scrollLeft ;
} ;
2019-10-29 17:14:58 +08:00
Table . prototype . handleRowHover = function handleRowHover ( isHover , key , event , currentIndex , propsRecord ) {
2018-12-14 13:30:24 +08:00
//增加新的API, 设置是否同步Hover状态, 提高性能, 避免无关的渲染
2019-05-22 14:19:13 +08:00
var _props10 = this . props ,
syncHover = _props10 . syncHover ,
onRowHover = _props10 . onRowHover ,
data = _props10 . data ;
2019-10-29 17:14:58 +08:00
//fix:树形表, onRowHover返回参数异常
2018-12-14 13:30:24 +08:00
2019-10-29 17:14:58 +08:00
var isTreeType = this . isTreeType ;
var record = isTreeType ? propsRecord : data [ currentIndex ] ;
2019-02-18 14:56:02 +08:00
// 固定列、或者含有hoverdom时情况下同步hover状态
2019-02-18 14:54:33 +08:00
if ( this . columnManager . isAnyColumnsFixed ( ) && syncHover ) {
this . hoverKey = key ;
2018-12-14 13:30:24 +08:00
this . store . setState ( {
currentHoverKey : isHover ? key : null
} ) ;
}
2019-03-11 09:53:34 +08:00
if ( this . hoverDom ) {
if ( isHover ) {
this . currentHoverKey = key ;
var td = ( 0 , _utils . closest ) ( event . target , 'td' ) ;
if ( td ) {
var scrollTop = this . lastScrollTop ? this . lastScrollTop : 0 ;
var top = td . offsetTop - scrollTop ;
2019-05-22 14:19:13 +08:00
if ( this . headTable ) {
top = top + this . headTable . clientHeight ;
2019-03-11 09:53:34 +08:00
}
this . hoverDom . style . top = top + 'px' ;
this . hoverDom . style . height = td . offsetHeight + 'px' ;
this . hoverDom . style . lineHeight = td . offsetHeight + 'px' ;
this . hoverDom . style . display = 'block' ;
2019-02-19 09:30:18 +08:00
}
2019-02-18 14:54:33 +08:00
}
}
2019-02-18 14:56:02 +08:00
onRowHover && onRowHover ( currentIndex , record ) ;
2017-01-12 08:53:51 +08:00
} ;
Table . prototype . render = function render ( ) {
2018-12-06 13:39:51 +08:00
var _this6 = this ;
2018-09-12 14:14:05 +08:00
2017-01-12 08:53:51 +08:00
var props = this . props ;
var clsPrefix = props . clsPrefix ;
2019-04-23 16:59:47 +08:00
var hasFixedLeft = this . columnManager . isAnyColumnsLeftFixed ( ) ;
2017-01-12 08:53:51 +08:00
var className = props . clsPrefix ;
if ( props . className ) {
className += ' ' + props . className ;
}
if ( props . useFixedHeader || props . scroll && props . scroll . y ) {
className += ' ' + clsPrefix + '-fixed-header' ;
}
2019-08-20 16:47:01 +08:00
if ( ! props . showHeader ) {
className += ' ' + clsPrefix + '-hide-header' ;
}
2017-12-24 22:54:32 +08:00
if ( props . bordered ) {
className += ' ' + clsPrefix + '-bordered' ;
}
2017-01-12 08:53:51 +08:00
className += ' ' + clsPrefix + '-scroll-position-' + this . state . scrollPosition ;
2018-12-20 09:41:51 +08:00
//如果传入height说明是固定高度
2019-09-02 17:53:53 +08:00
//内容过多折行显示时, height 属性会失效,为了避免产生错行
if ( props . bodyDisplayInRow && props . height ) {
2018-12-20 09:41:51 +08:00
className += ' fixed-height' ;
}
2019-04-23 16:04:02 +08:00
if ( props . bodyDisplayInRow ) {
className += ' body-dispaly-in-row' ;
}
if ( props . headerDisplayInRow ) {
className += ' header-dispaly-in-row' ;
}
2017-01-12 08:53:51 +08:00
var isTableScroll = this . columnManager . isAnyColumnsFixed ( ) || props . scroll . x || props . scroll . y ;
2018-01-31 19:46:40 +08:00
var loading = props . loading ;
if ( typeof loading === 'boolean' ) {
loading = {
show : loading
} ;
}
2019-04-23 16:59:47 +08:00
if ( props . size ) {
className += ' ' + clsPrefix + '-' + props . size ;
}
if ( hasFixedLeft ) {
className += ' has-fixed-left' ;
}
2018-12-20 09:41:51 +08:00
2017-01-12 08:53:51 +08:00
return _react2 [ "default" ] . createElement (
'div' ,
2018-09-12 14:14:05 +08:00
{ className : className , style : props . style , ref : function ref ( el ) {
2018-12-06 13:39:51 +08:00
return _this6 . contentTable = el ;
2019-01-05 11:06:52 +08:00
} ,
2019-01-16 13:57:31 +08:00
tabIndex : props . focusable && ( props . tabIndex ? props . tabIndex : '0' ) } ,
2017-01-12 08:53:51 +08:00
this . getTitle ( ) ,
_react2 [ "default" ] . createElement (
'div' ,
{ className : clsPrefix + '-content' } ,
_react2 [ "default" ] . createElement (
'div' ,
2018-12-16 22:22:45 +08:00
{ className : isTableScroll ? clsPrefix + '-scroll' : '' } ,
2017-01-12 08:53:51 +08:00
this . getTable ( { columns : this . columnManager . groupedColumns ( ) } ) ,
this . getEmptyText ( ) ,
this . getFooter ( )
) ,
2019-04-23 16:59:47 +08:00
hasFixedLeft && _react2 [ "default" ] . createElement (
2018-10-26 15:04:25 +08:00
'div' ,
{ className : clsPrefix + '-fixed-left' } ,
this . getLeftFixedTable ( )
) ,
2017-01-12 08:53:51 +08:00
this . columnManager . isAnyColumnsRightFixed ( ) && _react2 [ "default" ] . createElement (
'div' ,
{ className : clsPrefix + '-fixed-right' } ,
this . getRightFixedTable ( )
)
2018-01-31 19:46:40 +08:00
) ,
_react2 [ "default" ] . createElement ( _beeLoading2 [ "default" ] , _extends ( {
container : this
2019-02-18 14:54:33 +08:00
} , loading ) ) ,
props . hoverContent && _react2 [ "default" ] . createElement (
'div' ,
{ className : 'u-row-hover' ,
onMouseEnter : this . onRowHoverMouseEnter , onMouseLeave : this . onRowHoverMouseLeave , ref : function ref ( el ) {
return _this6 . hoverDom = el ;
} } ,
2019-02-18 14:56:02 +08:00
props . hoverContent ( )
2019-02-18 14:54:33 +08:00
)
2017-01-12 08:53:51 +08:00
) ;
} ;
return Table ;
} ( _react . Component ) ;
;
Table . propTypes = propTypes ;
Table . defaultProps = defaultProps ;
2019-05-21 19:31:38 +08:00
Table . contextTypes = {
beeLocale : _propTypes2 [ "default" ] . object
} ;
2017-01-12 08:53:51 +08:00
exports [ "default" ] = Table ;
module . exports = exports [ 'default' ] ;