| | |
| | | class EdiDataTable extends Component { |
| | | static propTpyes = { |
| | | dict: PropTypes.object, // 字典项 |
| | | type: PropTypes.object, // 数据类型,文本、图片 |
| | | transfield: PropTypes.object, // 字段名称 |
| | | type: PropTypes.string, // 是否为关联表单 |
| | | display: PropTypes.string, // 数据类型,文本、图片 |
| | | fields: PropTypes.array, // 字段集 |
| | | linkSubFields: PropTypes.array, // 填充字段 |
| | | onChange: PropTypes.func // 数据变化 |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | UNSAFE_componentWillReceiveProps (nextProps) { |
| | | if (!is(fromJS(this.props.fields), fromJS(nextProps.fields)) || !is(fromJS(this.props.type), fromJS(nextProps.type))) { |
| | | if ( |
| | | !is(fromJS(this.props.fields), fromJS(nextProps.fields)) || |
| | | !is(fromJS(this.props.linkSubFields), fromJS(nextProps.linkSubFields)) || |
| | | this.props.display !== nextProps.display || |
| | | this.props.type !== nextProps.type |
| | | ) { |
| | | this.setState({editingKey: ''}, () => { |
| | | this.setState({ |
| | | columns: this.getCloumns() |
| | |
| | | } |
| | | |
| | | getCloumns = () => { |
| | | const { type, fields } = this.props |
| | | const { display, fields, linkSubFields, transfield, type } = this.props |
| | | let columns = [] |
| | | let keys = ['ParentID'] |
| | | |
| | | if (type === 'picture') { |
| | | if (display === 'picture') { |
| | | columns.push({ |
| | | title: 'url', |
| | | dataIndex: '$url', |
| | | inputType: 'file', |
| | | width: '40%', |
| | | // width: '40%', |
| | | editable: true, |
| | | render: (text) => { |
| | | if (!text) return '' |
| | |
| | | } |
| | | }) |
| | | } else { |
| | | columns = fields.map(item => ({ |
| | | title: item.field, |
| | | dataIndex: item.field, |
| | | editable: true, |
| | | })) |
| | | columns = fields.map(item => { |
| | | keys.push(item.field) |
| | | return { |
| | | title: item.field, |
| | | dataIndex: item.field, |
| | | editable: true, |
| | | } |
| | | }) |
| | | } |
| | | |
| | | if (linkSubFields.length > 0) { |
| | | linkSubFields.forEach(m => { |
| | | if (keys.includes(m)) return |
| | | |
| | | columns.push({ |
| | | title: transfield[m] || m, |
| | | dataIndex: m, |
| | | editable: true, |
| | | }) |
| | | }) |
| | | } |
| | | |
| | | columns.unshift({ |
| | |
| | | dataIndex: '$value', |
| | | editable: true, |
| | | }) |
| | | |
| | | if (type === 'link') { |
| | | columns.unshift({ |
| | | title: 'ParentID', |
| | | dataIndex: 'ParentID', |
| | | editable: true, |
| | | }) |
| | | } |
| | | |
| | | columns.push({ |
| | | title: '操作', |
| | |
| | | } |
| | | |
| | | handleAdd = () => { |
| | | const { fields, type } = this.props |
| | | const { fields, display } = this.props |
| | | if (this.state.data.length >= 100) { |
| | | notification.warning({ |
| | | top: 92, |
| | |
| | | return |
| | | } |
| | | |
| | | let item = { key: Utils.getuuid(), $value: `${this.state.data.length + 1}` } |
| | | let item = { key: Utils.getuuid(), $value: `${this.state.data.length + 1}`, ParentID: '' } |
| | | |
| | | if (type === 'picture') { |
| | | if (display === 'picture') { |
| | | item.$url = '' |
| | | } else { |
| | | fields.forEach(f => { |
| | |
| | | }) |
| | | |
| | | let addable = false |
| | | if (this.props.type === 'picture') { |
| | | if (this.props.display === 'picture') { |
| | | addable = true |
| | | } else if (this.props.fields && this.props.fields.length > 0) { |
| | | addable = true |