| | |
| | | |
| | | return !is(fromJS(this.props.column), fromJS(nextProps.column)) || |
| | | !is(fromJS(this.props.fields), fromJS(nextProps.fields)) || |
| | | this.props.index !== nextProps.index |
| | | this.props.index !== nextProps.index || |
| | | this.props.rowSpan !== nextProps.rowSpan || |
| | | this.props.colSpan !== nextProps.colSpan |
| | | } |
| | | |
| | | render() { |
| | |
| | | ) |
| | | } else if (column) { |
| | | return ( |
| | | <th {...restProps}> |
| | | <th {...restProps} key={column.uuid}> |
| | | <Popover overlayClassName="mk-popover-control-wrap" mouseLeaveDelay={0.2} mouseEnterDelay={0.2} content={ |
| | | <div className="mk-popover-control"> |
| | | {column && column.type === 'custom' ? |
| | | {column && ['custom', 'colspan'].includes(column.type) ? |
| | | <Icon className="plus" title="添加" type="plus" onClick={() => this.props.addElement(column)} /> : null |
| | | } |
| | | <Icon className="edit" title="编辑" type="edit" onClick={() => this.props.editColumn(column)} /> |
| | |
| | | return ( |
| | | <td style={{...style, minWidth: column.Width || 100}} className={className}> |
| | | {column.field} |
| | | {column.marks && column.marks.length > 0 ? <Icon className="profile" type="ant-design"/> : null} |
| | | {column.marks && column.marks.length ? <Icon className="profile" type="ant-design"/> : null} |
| | | </td> |
| | | ) |
| | | } else { |
| | |
| | | state = { |
| | | dict: localStorage.getItem('lang') !== 'en-US' ? zhCN : enUS, |
| | | data: [{uuid: Utils.getuuid()}], |
| | | refresh: false, // 强制刷新 |
| | | columns: [], |
| | | fields: [], |
| | | lineMarks: [] |
| | |
| | | }) |
| | | } |
| | | |
| | | updateCol = (col, action) => { |
| | | let _columns = fromJS(this.state.columns).toJS() |
| | | |
| | | if (col.isSub) { |
| | | _columns = _columns.map(column => { |
| | | loopCol = (columns, col) => { |
| | | return columns.map(column => { |
| | | if (column.type === 'colspan') { |
| | | column.subcols = column.subcols.map(item => { |
| | | if (item.uuid === col.uuid) { |
| | | return col |
| | | column.subcols = this.loopCol(column.subcols, col) |
| | | } |
| | | return item |
| | | }) |
| | | } |
| | | return column |
| | | }) |
| | | } else { |
| | | _columns = _columns.map(column => { |
| | | if (column.uuid === col.uuid) { |
| | | return col |
| | | } |
| | | return column |
| | | }) |
| | | } |
| | | |
| | | updateCol = (col, action) => { |
| | | let _columns = fromJS(this.state.columns).toJS() |
| | | _columns = this.loopCol(_columns, col) |
| | | |
| | | this.setState({ |
| | | columns: _columns, |
| | |
| | | this.setState({card: null}) |
| | | } |
| | | |
| | | loopDelCol = (columns, col) => { |
| | | return columns.filter(column => { |
| | | if (column.type === 'colspan') { |
| | | column.subcols = this.loopDelCol(column.subcols, col) |
| | | } |
| | | return column.uuid !== col.uuid |
| | | }) |
| | | } |
| | | |
| | | deleteCol = (col) => { |
| | | let _columns = fromJS(this.state.columns).toJS() |
| | | |
| | | if (col.isSub) { |
| | | _columns = _columns.map(column => { |
| | | if (column.type !== 'colspan') return column |
| | | if (column.subcols && column.subcols.length > 0) { |
| | | column.subcols = column.subcols.filter(item => item.uuid !== col.uuid) |
| | | } |
| | | return column |
| | | }) |
| | | } else { |
| | | _columns = _columns.filter(column => column.uuid !== col.uuid) |
| | | } |
| | | _columns = this.loopDelCol(_columns, col) |
| | | |
| | | this.setState({ |
| | | columns: _columns |
| | |
| | | document.body.removeChild(oInput) |
| | | } |
| | | |
| | | handlecolumns = (columns, fields, config, isSub) => { |
| | | return columns.map((col, index) => { |
| | | return { |
| | | title: col.label, |
| | | dataIndex: col.uuid, |
| | | align: col.Align, |
| | | sorter: !isSub && col.IsSort === 'true', |
| | | onCell: () => ({ |
| | | column: col, |
| | | width: col.Width, |
| | | config: config, |
| | | upComponent: this.updateCol |
| | | }), |
| | | onHeaderCell: () => ({ |
| | | index: isSub ? undefined : index, |
| | | column: col, |
| | | fields: fields, |
| | | align: col.Align, |
| | | moveCol: this.moveCol, |
| | | updateCol: this.updateCol, |
| | | addElement: this.addElement, |
| | | editColumn: this.editColumn, |
| | | deleteCol: this.deleteCol, |
| | | }), |
| | | children: col.subcols && col.subcols.length ? this.handlecolumns(col.subcols, fields, config, true) : null, |
| | | } |
| | | }) |
| | | } |
| | | |
| | | render() { |
| | | const { config } = this.props |
| | | const { fields, card, lineMarks, dict } = this.state |
| | |
| | | } |
| | | } |
| | | |
| | | const columns = this.state.columns.map((col, index) => { |
| | | return { |
| | | title: col.label, |
| | | dataIndex: col.field, |
| | | align: col.Align, |
| | | sorter: col.IsSort === 'true', |
| | | onCell: () => ({ |
| | | column: col, |
| | | width: col.Width, |
| | | config: config, |
| | | upComponent: this.updateCol |
| | | }), |
| | | children: col.subcols && col.subcols.length > 0 ? col.subcols.map(cell => ({ |
| | | align: col.Align, |
| | | title: cell.label, |
| | | key: cell.uuid, |
| | | onCell: () => ({ |
| | | column: cell, |
| | | width: cell.Width, |
| | | config: config, |
| | | upComponent: this.updateCol |
| | | }), |
| | | onHeaderCell: () => ({ |
| | | column: cell, |
| | | fields: fields, |
| | | align: cell.Align, |
| | | updateCol: this.updateCol, |
| | | addElement: this.addElement, |
| | | editColumn: this.editColumn, |
| | | deleteCol: this.deleteCol, |
| | | }) |
| | | })) : null, |
| | | onHeaderCell: () => ({ |
| | | index, |
| | | column: col, |
| | | fields: fields, |
| | | align: col.Align, |
| | | moveCol: this.moveCol, |
| | | updateCol: this.updateCol, |
| | | addElement: this.addElement, |
| | | editColumn: this.editColumn, |
| | | deleteCol: this.deleteCol, |
| | | }) |
| | | } |
| | | }) |
| | | const columns = this.handlecolumns(this.state.columns, fields, config) |
| | | |
| | | return ( |
| | | <div className={`normal-table-columns ${config.setting.laypage} ${config.wrap.tableType}`}> |
| | |
| | | <DndProvider> |
| | | <Table |
| | | rowKey="uuid" |
| | | rowClassName="editable-row" |
| | | bordered={config.wrap.bordered !== 'false'} |
| | | components={components} |
| | | dataSource={this.state.data} |
| | | rowSelection={config.wrap.tableType ? { type: 'radio' } : null} |
| | | columns={columns} |
| | | rowClassName="editable-row" |
| | | pagination={{ |
| | | current: 1, |
| | | pageSize: 10, |