| | |
| | | import { is, fromJS } from 'immutable' |
| | | import { DndProvider, DragSource, DropTarget } from 'react-dnd' |
| | | import { Table, Input, InputNumber, Popconfirm, Form, Select, Radio, Cascader, notification, message, Modal, Typography } from 'antd' |
| | | import { CopyOutlined, EditOutlined, DeleteOutlined, SwapOutlined } from '@ant-design/icons' |
| | | import { CopyOutlined, EditOutlined, DeleteOutlined, SwapOutlined, PlusOutlined } from '@ant-design/icons' |
| | | |
| | | import Utils from '@/utils/utils.js' |
| | | import ColorSketch from '@/mob/colorsketch' |
| | |
| | | } |
| | | |
| | | UNSAFE_componentWillReceiveProps (nextProps) { |
| | | |
| | | if (!is(fromJS(this.state.data), fromJS(nextProps.data))) { |
| | | this.setState({data: nextProps.data, editingKey: ''}) |
| | | } else if (!is(fromJS(this.props.columns), fromJS(nextProps.columns))) { |
| | |
| | | return |
| | | } |
| | | |
| | | let forbid = false |
| | | |
| | | columns.forEach(col => { |
| | | if (!col.forbids || forbid) return |
| | | |
| | | let key = record[col.dataIndex].toLowerCase() |
| | | if (col.forbids.includes(key)) { |
| | | forbid = col.title + '不可使用' + record[col.dataIndex] |
| | | } |
| | | }) |
| | | |
| | | if (forbid) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: forbid, |
| | | duration: 5 |
| | | }) |
| | | return |
| | | } |
| | | |
| | | let unique = true |
| | | columns.forEach(col => { |
| | | if (col.unique !== true || !unique) return |
| | |
| | | row = {...newData[index], ...row} |
| | | } else { |
| | | row.uuid = uuid |
| | | } |
| | | |
| | | let forbid = false |
| | | |
| | | columns.forEach(col => { |
| | | if (!col.forbids || forbid) return |
| | | |
| | | let key = row[col.dataIndex].toLowerCase() |
| | | if (col.forbids.includes(key)) { |
| | | forbid = col.title + '不可使用' + row[col.dataIndex] |
| | | } |
| | | }) |
| | | |
| | | if (forbid) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: forbid, |
| | | duration: 5 |
| | | }) |
| | | return |
| | | } |
| | | |
| | | let unique = true |
| | |
| | | }) |
| | | } |
| | | |
| | | handleAdd = () => { |
| | | const { columns } = this.props |
| | | const { data } = this.state |
| | | |
| | | let _index = data.length + 1 |
| | | let item = { |
| | | uuid: Utils.getuuid() |
| | | } |
| | | |
| | | columns.forEach(col => { |
| | | if (!col.dataIndex) return |
| | | |
| | | item[col.dataIndex] = col.initval || '' |
| | | |
| | | if (col.unique) { |
| | | while (data.filter(cell => cell[col.dataIndex] === item[col.dataIndex]).length > 0) { |
| | | _index++ |
| | | item[col.dataIndex] = col.initval + _index |
| | | } |
| | | } |
| | | }) |
| | | |
| | | let _data = [...data, item] |
| | | |
| | | this.setState({ |
| | | data: _data |
| | | }, () => { |
| | | this.props.onChange(_data) |
| | | }) |
| | | } |
| | | |
| | | render() { |
| | | const { actions, indexShow, searchKey } = this.props |
| | | const { editLineId } = this.state |
| | |
| | | return ( |
| | | <EditableContext.Provider value={this.props.form}> |
| | | <div className="modal-edit-table"> |
| | | {actions.includes('add') ? <PlusOutlined className="add-row" onClick={this.handleAdd} /> : null} |
| | | <DndProvider> |
| | | <Table |
| | | bordered |