| | |
| | | import React, {Component} from 'react' |
| | | import PropTypes from 'prop-types' |
| | | // import { is, fromJS } from 'immutable' |
| | | import { is, fromJS } from 'immutable' |
| | | import { Table, message, Affix, Button } from 'antd' |
| | | import './index.scss' |
| | | |
| | |
| | | dict: PropTypes.object, // 字典项 |
| | | MenuID: PropTypes.string, // 菜单Id |
| | | setting: PropTypes.object, // 表格全局设置:tableType(表格是否可选、单选、多选)、columnfixed(列固定)、actionfixed(按钮固定) |
| | | pickup: PropTypes.any, // 数据收起 |
| | | setsingle: PropTypes.any, // 设置单选多选 |
| | | columns: PropTypes.array, // 表格列 |
| | | data: PropTypes.any, // 表格数据 |
| | | total: PropTypes.number, // 总数 |
| | |
| | | selectedRowKeys: [], // 表格中选中行 |
| | | pageIndex: 1, // 初始页面索引 |
| | | pageSize: 10, // 每页数据条数 |
| | | columns: null // 显示列 |
| | | columns: null, // 显示列 |
| | | selectId: '', |
| | | isSingleSelect: false |
| | | } |
| | | |
| | | UNSAFE_componentWillMount () { |
| | |
| | | } |
| | | _columns.push(cell) |
| | | }) |
| | | // {item.FieldName === 'MenuNo' ? <Icon onClick={(e) => {this.copycontent(e, record[item.FieldName])}} type="copy"/> : ''} |
| | | |
| | | this.setState({columns: _columns}) |
| | | } |
| | | |
| | | UNSAFE_componentWillReceiveProps(nextProps) { |
| | | if (!is(fromJS(this.props.setsingle), fromJS(nextProps.setsingle))) { |
| | | this.setState({ |
| | | isSingleSelect: nextProps.setsingle, |
| | | selectedRowKeys: [], |
| | | selectId: '' |
| | | }) |
| | | } |
| | | } |
| | | |
| | | getContent = (item, record) => { |
| | |
| | | } |
| | | |
| | | onSelectChange = selectedRowKeys => { |
| | | if (this.props.pickup) return |
| | | |
| | | let index = '' |
| | | if (selectedRowKeys.length > 0) { |
| | | index = selectedRowKeys[selectedRowKeys.length - 1] |
| | |
| | | |
| | | changeRow = (record, index) => { |
| | | // 点击整行,触发切换,判断是否可选,单选或多选,进行对应操作 |
| | | if (!this.props.setting.tableType) return |
| | | if (!this.props.setting.tableType || this.props.pickup) return |
| | | |
| | | let newkeys = JSON.parse(JSON.stringify(this.state.selectedRowKeys)) |
| | | let _re = newkeys.includes(index) |
| | | |
| | | if (this.props.setting.tableType === 'radio') { |
| | | if (this.props.setting.tableType === 'radio' || this.state.isSingleSelect) { |
| | | this.changedata(index) |
| | | this.setState({ selectedRowKeys: [index] }) |
| | | } else { |
| | | if (_re) { |
| | |
| | | _id = data[index][setting.primaryKey] |
| | | } |
| | | |
| | | this.setState({ |
| | | selectId: _id |
| | | }) |
| | | |
| | | this.props.handleTableId('mainTable', _id) |
| | | } |
| | | |
| | | resetTable = () => { |
| | | this.setState({ |
| | | pageIndex: 1, |
| | | selectId: '', |
| | | selectedRowKeys: [] |
| | | }) |
| | | } |
| | | |
| | | render() { |
| | | let { selectedRowKeys } = this.state |
| | | const { setting, pickup } = this.props |
| | | let { selectedRowKeys, isSingleSelect, selectId } = this.state |
| | | |
| | | let rowSelection = null |
| | | if (this.props.setting.tableType) { |
| | | if (setting.tableType) { |
| | | rowSelection = { |
| | | selectedRowKeys, |
| | | type: this.props.setting.tableType === 'radio' ? 'radio' : 'checkbox', |
| | | type: (setting.tableType === 'radio' || isSingleSelect) ? 'radio' : 'checkbox', |
| | | onChange: this.onSelectChange |
| | | } |
| | | } |
| | | let offset = null |
| | | if (this.props.setting.columnfixed) { |
| | | if (setting.columnfixed) { |
| | | // 表格头部固定于顶部时,判断距顶部高度 |
| | | if (!this.props.setting.actionfixed) { |
| | | if (!setting.actionfixed) { |
| | | offset = 48 |
| | | } else { |
| | | let box = document.getElementById(this.props.MenuID + 'mainaction') |
| | |
| | | } |
| | | } |
| | | |
| | | let _data = this.props.data ? this.props.data : [] |
| | | if (selectId && pickup && isSingleSelect) { |
| | | _data = _data.filter(item => item[setting.primaryKey] === selectId) |
| | | } |
| | | |
| | | return ( |
| | | <div className="main-table"> |
| | | {this.props.setting.columnfixed && <Affix offsetTop={offset} className="fix-header"> |
| | | {setting.columnfixed && <Affix offsetTop={offset} className="fix-header"> |
| | | <Table |
| | | size="middle" |
| | | bordered={true} |
| | |
| | | bordered={true} |
| | | rowSelection={rowSelection} |
| | | columns={this.state.columns} |
| | | dataSource={this.props.data ? this.props.data : []} |
| | | dataSource={_data} |
| | | loading={this.props.loading} |
| | | scroll={{ x: '100%', y: false }} |
| | | onRow={(record, index) => { |