| | |
| | | import React, {Component} from 'react' |
| | | import PropTypes from 'prop-types' |
| | | import { Table, Icon, message } from 'antd' |
| | | // import { is, fromJS } from 'immutable' |
| | | import { Table, Icon, message, Affix } from 'antd' |
| | | import './index.scss' |
| | | |
| | | export default class MainTable extends Component { |
| | | static propTpyes = { |
| | | MenuNo: PropTypes.string, // 菜单参数 |
| | | fixed: PropTypes.object, // 表格头部是否固定于页面上方 |
| | | loading: PropTypes.bool, |
| | | total: PropTypes.number, |
| | | select: PropTypes.object, |
| | |
| | | } |
| | | |
| | | changeRow = (record, index) => { |
| | | // 点击整行,触发切换 |
| | | // 点击整行,触发切换,判断是否可选,单选或多选,进行对应操作 |
| | | if (!this.props.select || !this.props.select.selectable) return |
| | | |
| | | let newkeys = JSON.parse(JSON.stringify(this.state.selectedRowKeys)) |
| | | let _re = newkeys.includes(index) |
| | | if (_re) { |
| | | newkeys = newkeys.filter(item => item !== index) |
| | | |
| | | if (this.props.select.selectType === 'radio') { |
| | | this.setState({ selectedRowKeys: [index] }) |
| | | } else { |
| | | newkeys.push(index) |
| | | if (_re) { |
| | | newkeys = newkeys.filter(item => item !== index) |
| | | } else { |
| | | newkeys.push(index) |
| | | } |
| | | this.setState({ selectedRowKeys: newkeys }) |
| | | } |
| | | this.setState({ selectedRowKeys: newkeys }) |
| | | } |
| | | |
| | | changeTable = (pagination, filters, sorter) => { |
| | |
| | | selectedRowKeys: [] |
| | | }) |
| | | this.props.refreshdata(pagination, filters, sorter) |
| | | } |
| | | |
| | | resetTable = () => { |
| | | this.setState({ |
| | | pageIndex: 1, |
| | | selectedRowKeys: [] |
| | | }) |
| | | } |
| | | |
| | | render() { |
| | |
| | | onChange: this.onSelectChange |
| | | } |
| | | } |
| | | let offset = null |
| | | if (this.props.fixed.fixtable) { |
| | | // 表格头部固定于顶部时,判断距顶部高度 |
| | | if (!this.props.fixed.fixaction) { |
| | | offset = 48 |
| | | } else { |
| | | let box = document.getElementById(this.props.MenuNo + 'mainaction') |
| | | if (box) { |
| | | offset = 48 + box.offsetHeight |
| | | } else { |
| | | offset = 105 |
| | | } |
| | | } |
| | | } |
| | | return ( |
| | | <div className="main-table"> |
| | | {this.props.fixed.fixtable && <Affix offsetTop={offset} className="fix-header"> |
| | | <Table |
| | | bordered={true} |
| | | rowSelection={rowSelection} |
| | | size="middle" |
| | | columns={this.state.columns.map(column => { |
| | | return { |
| | | align: column.align, |
| | | dataIndex: column.dataIndex, |
| | | title: column.title, |
| | | width: column.width |
| | | } |
| | | })} |
| | | /> |
| | | </Affix>} |
| | | <Table |
| | | bordered={true} |
| | | rowSelection={rowSelection} |