| | |
| | | } |
| | | |
| | | render() { |
| | | let { lineMarks, data, className, ...resProps } = this.props |
| | | let { lineMarks, onDoubleClick, data, className, ...resProps } = this.props |
| | | let style = {} |
| | | |
| | | if (lineMarks && lineMarks.length > 0) { |
| | |
| | | }) |
| | | } |
| | | |
| | | return <tr {...resProps} className={className} style={style}/> |
| | | return <tr {...resProps} onDoubleClick={onDoubleClick} className={className} style={style}/> |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | render() { |
| | | let { col, config, record, className, style, triggerLink, updateStatus, ...resProps } = this.props |
| | | let { col, config, record, className, style, triggerLink, ...resProps } = this.props |
| | | |
| | | if (!col) return (<td {...resProps} className={className} style={style}/>) |
| | | |
| | |
| | | if (col.linkThdMenu || col.linkurl) { |
| | | content = ( |
| | | <div> |
| | | <div className="link-menu" onDoubleClick={() => this.triggerLink(col, record)}></div> |
| | | <div className="link-menu" onDoubleClick={(e) => this.triggerLink(e, col, record)}></div> |
| | | {content} |
| | | </div> |
| | | ) |
| | |
| | | content = md5(content) |
| | | } |
| | | |
| | | if (col.rowspan === 'true') { |
| | | resProps.rowSpan = record['$$' + col.field] |
| | | } |
| | | |
| | | if (col.linkThdMenu || col.linkurl) { |
| | | content = ( |
| | | <div> |
| | | <div className="link-menu" onDoubleClick={() => this.triggerLink(col, record)}></div> |
| | | <div className="link-menu" onDoubleClick={(e) => this.triggerLink(e, col, record)}></div> |
| | | {content} |
| | | </div> |
| | | ) |
| | |
| | | } else if (col.type === 'custom') { |
| | | style.padding = '0px' |
| | | resProps.children = ( |
| | | <CardCellComponent data={record} cards={config} elements={col.elements} updateStatus={this.props.updateStatus}/> |
| | | <CardCellComponent data={record} cards={config} elements={col.elements}/> |
| | | ) |
| | | } else if (col.type === 'action') { |
| | | style.padding = '0px 5px' |
| | | resProps.children = ( |
| | | <CardCellComponent data={record} cards={config} elements={col.elements} updateStatus={this.props.updateStatus}/> |
| | | <CardCellComponent data={record} cards={config} elements={col.elements}/> |
| | | ) |
| | | } |
| | | |
| | |
| | | loading: PropTypes.bool, // 表格加载中 |
| | | refreshdata: PropTypes.func, // 表格中排序列、页码的变化时刷新 |
| | | chgSelectData: PropTypes.func, // 数据切换 |
| | | refreshbyaction: PropTypes.func, // 按钮执行完成后刷新 |
| | | } |
| | | |
| | | state = { |
| | | dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS, |
| | | tableId: '', // 表格ID |
| | | selectedRowKeys: [], // 表格中选中行 |
| | | pageIndex: 1, // 初始页面索引 |
| | | pageSize: 10, // 每页数据条数 |
| | | columns: null, // 显示列 |
| | | activeIndex: null, // 标记当前选中行 |
| | | rowspans: null, // 行合并字段信息 |
| | | pickup: false |
| | | pickup: false, // 收起未选择项 |
| | | orderfields: {} // 排序id与field转换 |
| | | } |
| | | |
| | | UNSAFE_componentWillMount () { |
| | | const { menuType, memberLevel, setting, fields } = this.props |
| | | let columns = fromJS(this.props.columns).toJS() |
| | | let _columns = [] |
| | | const { menuType, memberLevel, setting, fields, columns } = this.props |
| | | let radio = 5 // 虚化比例 |
| | | let _format = false // 是否虚化处理 |
| | | let rowspans = [] |
| | | let orderfields = {} |
| | | |
| | | if (window.GLOB.dataFormat && menuType !== 'HS' && memberLevel) { |
| | | _format = true |
| | |
| | | } |
| | | } |
| | | |
| | | columns.forEach(item => { |
| | | if (item.hidden === true || item.Hide === 'true') return |
| | | let cell = null |
| | | |
| | | if (item.type === 'colspan') { |
| | | cell = {title: item.label, children: []} |
| | | |
| | | item.subcols.forEach(col => { |
| | | if (col.rowspan === 'true') { |
| | | rowspans.push(col.field) |
| | | let getColumns = (cols) => { |
| | | return cols.map(item => { |
| | | let cell = null |
| | | |
| | | if (item.type === 'colspan') { |
| | | cell = { title: item.label, align: item.Align } |
| | | cell.children = getColumns(item.subcols) |
| | | } else { |
| | | if (item.rowspan === 'true') { |
| | | rowspans.push(item.field) |
| | | } |
| | | if (_format && !Math.floor(Math.random() * radio)) { |
| | | col.blur = true |
| | | item.blur = true |
| | | } |
| | | |
| | | if (item.marks && item.marks.length === 0) { |
| | | item.marks = '' |
| | | } |
| | | |
| | | if (col.marks && col.marks.length === 0) { |
| | | col.marks = '' |
| | | if (item.field) { |
| | | orderfields[item.uuid] = item.field |
| | | } |
| | | |
| | | cell.children.push({ |
| | | align: col.Align, |
| | | title: col.label, |
| | | dataIndex: col.field || col.uuid, |
| | | key: col.uuid, |
| | | width: col.Width || 120, |
| | | cell = { |
| | | align: item.Align, |
| | | dataIndex: item.uuid, |
| | | title: item.label, |
| | | sorter: item.field && item.IsSort === 'true', |
| | | width: item.Width || 120, |
| | | onCell: record => ({ |
| | | record, |
| | | col, |
| | | config: col.type === 'custom' ? {setting, columns: fields} : null, |
| | | triggerLink: this.triggerLink, |
| | | updateStatus: this.updateStatus |
| | | col: item, |
| | | config: item.type === 'custom' || item.type === 'action' ? {setting, columns: fields} : null, |
| | | triggerLink: this.triggerLink |
| | | }) |
| | | }) |
| | | }) |
| | | } else { |
| | | if (item.rowspan === 'true') { |
| | | rowspans.push(item.field) |
| | | } |
| | | } |
| | | if (_format && !Math.floor(Math.random() * radio)) { |
| | | item.blur = true |
| | | } |
| | | |
| | | return cell |
| | | }) |
| | | } |
| | | |
| | | if (item.marks && item.marks.length === 0) { |
| | | item.marks = '' |
| | | } |
| | | |
| | | cell = { |
| | | align: item.Align, |
| | | dataIndex: item.field || item.uuid, |
| | | title: item.label, |
| | | sorter: item.field && item.IsSort === 'true', |
| | | width: item.Width || 120, |
| | | onCell: record => ({ |
| | | record, |
| | | col: item, |
| | | config: item.type === 'custom' || item.type === 'action' ? {setting, columns: fields} : null, |
| | | triggerLink: this.triggerLink, |
| | | updateStatus: this.updateStatus |
| | | }) |
| | | } |
| | | } |
| | | |
| | | _columns.push(cell) |
| | | }) |
| | | let _columns = getColumns(columns) |
| | | |
| | | if (rowspans.length === 0) { |
| | | rowspans = null |
| | | } |
| | | |
| | | let tableId = (() => { |
| | | let uuid = [] |
| | | let _options = 'abcdefghigklmnopqrstuv' |
| | | for (let i = 0; i < 19; i++) { |
| | | uuid.push(_options.substr(Math.floor(Math.random() * 0x20), 1)) |
| | | } |
| | | return uuid.join('') |
| | | }) () |
| | | |
| | | if (setting.borderColor) { // 边框颜色 |
| | | let style = `#${tableId} table, #${tableId} tr, #${tableId} th, #${tableId} td {border-color: ${setting.borderColor}}` |
| | | let ele = document.createElement('style') |
| | | ele.innerHTML = style |
| | | document.getElementsByTagName('head')[0].appendChild(ele) |
| | | } |
| | | |
| | | this.setState({ |
| | | columns: _columns, |
| | | rowspans |
| | | rowspans, |
| | | tableId, |
| | | orderfields |
| | | }) |
| | | } |
| | | |
| | |
| | | MKEmitter.removeListener('resetTable', this.resetTable) |
| | | } |
| | | |
| | | updateStatus = (type, positon, btn) => { |
| | | if (type === 'refresh') { |
| | | this.props.refreshbyaction(positon, btn) |
| | | } |
| | | } |
| | | |
| | | // 字段透视 |
| | | triggerLink = (item, record) => { |
| | | triggerLink = (e, item, record) => { |
| | | const { tabviews, MenuID } = this.props |
| | | e.stopPropagation() |
| | | |
| | | if (item.linkThdMenu) { |
| | | let tabmenu = item.linkThdMenu |
| | |
| | | index = selectedRowKeys.slice(-1)[0] |
| | | } |
| | | |
| | | if (setting.tableType === 'checkbox') { |
| | | if (setting.tableType === 'checkbox' || setting.tableType === 'radio') { |
| | | _activeIndex = index === '' ? null : index |
| | | } |
| | | |
| | |
| | | if (setting.tableType === 'radio') { |
| | | newkeys = [index] |
| | | this.changedata(index) |
| | | this.setState({ selectedRowKeys: newkeys }) |
| | | this.setState({ selectedRowKeys: newkeys, activeIndex: index }) |
| | | } else { |
| | | let _index = '' |
| | | if (newkeys.includes(index)) { |
| | |
| | | } |
| | | |
| | | changeTable = (pagination, filters, sorter) => { |
| | | const { orderfields } = this.state |
| | | |
| | | this.setState({ |
| | | pageIndex: pagination.current, |
| | | pageSize: pagination.pageSize, |
| | |
| | | activeIndex: null, |
| | | pickup: false |
| | | }) |
| | | |
| | | sorter.field = orderfields[sorter.field] || '' |
| | | |
| | | this.props.refreshdata(pagination, filters, sorter) |
| | | } |
| | | |
| | |
| | | let preItem = data[index - 1] |
| | | rowspans.forEach((cell, i) => { |
| | | if (i === 0) { |
| | | if ((item[cell] || item[cell] === 0) && preItem[cell] === item[cell]) { |
| | | if (preItem[cell] === item[cell]) { |
| | | item['$' + cell] = preItem['$' + cell] + 1 |
| | | } else { |
| | | item['$' + cell] = 1 |
| | | } |
| | | } else { |
| | | if ((item[cell] || item[cell] === 0) && preItem[cell] === item[cell]) { |
| | | if (preItem[cell] === item[cell]) { |
| | | item['$' + cell] = preItem['$' + cell] + 1 |
| | | } else { |
| | | item['$' + cell] = 1 |
| | |
| | | }) |
| | | } |
| | | |
| | | doubleClickLine = (record) => { |
| | | const { setting } = this.props |
| | | |
| | | if (!setting.doubleClick) return |
| | | |
| | | MKEmitter.emit('triggerBtnId', setting.doubleClick, [record]) |
| | | } |
| | | |
| | | render() { |
| | | const { setting, statFValue, lineMarks, data } = this.props |
| | | const { selectedRowKeys, activeIndex, pickup } = this.state |
| | | const { selectedRowKeys, activeIndex, pickup, tableId } = this.state |
| | | |
| | | // 设置表格选择属性:单选、多选、不可选 |
| | | let rowSelection = null |
| | |
| | | } |
| | | |
| | | return ( |
| | | <div className="normal-custom-table"> |
| | | <div className={'normal-custom-table ' + setting.tableHeader} id={tableId}> |
| | | {(setting.tableType === 'radio' || setting.tableType === 'checkbox') && data && data.length > 0 ? |
| | | <Switch title="收起" className="main-pickup" checkedChildren="开" unCheckedChildren="关" defaultChecked={pickup} onChange={this.pickupChange} /> : null |
| | | } |
| | | <Table |
| | | size="middle" |
| | | components={components} |
| | | size={setting.size || 'middle'} |
| | | bordered={setting.bordered !== 'false'} |
| | | rowSelection={rowSelection} |
| | | columns={this.state.columns} |
| | |
| | | lineMarks, |
| | | data: record, |
| | | className: index === activeIndex ? ' mk-row-active ' : '', |
| | | onClick: () => {this.changeRow(record, index)} |
| | | onClick: () => {this.changeRow(record, index)}, |
| | | onDoubleClick: () => {this.doubleClickLine(record)} |
| | | } |
| | | }} |
| | | onChange={this.changeTable} |