| | |
| | | toggleEdit = () => { |
| | | const editing = !this.state.editing |
| | | this.setState({ editing }, () => { |
| | | if (editing) { |
| | | if (editing && this.input && this.input.select) { |
| | | this.input.select() |
| | | } else if (editing && this.input && this.input.focus) { |
| | | this.input.focus() |
| | | } |
| | | }) |
| | |
| | | |
| | | if (props.type === 'link') { |
| | | _width = '27%' |
| | | } else { |
| | | } else if (props.type === 'select') { |
| | | _width = Math.floor(80 / (props.linkSubFields.length + 2)) + '%' |
| | | fields = props.linkSubFields.map(field => { |
| | | return { |
| | |
| | | dataIndex: 'operation', |
| | | render: (text, record) => |
| | | this.state.dataSource.length >= 1 ? ( |
| | | <Popconfirm title="Sure to delete?" onConfirm={() => this.handleDelete(record.key)}> |
| | | <span style={{color: '#1890ff', cursor: 'pointer'}}><Icon type="delete" /></span> |
| | | </Popconfirm> |
| | | <div> |
| | | <span className="operation-btn" title={props.dict['header.form.up']} onClick={() => this.handleUpDown(record, 'up')} style={{color: '#1890ff'}}><Icon type="arrow-up" /></span> |
| | | <span className="operation-btn" title={props.dict['header.form.down']} onClick={() => this.handleUpDown(record, 'down')} style={{color: '#ff4d4f'}}><Icon type="arrow-down" /></span> |
| | | <Popconfirm |
| | | title={props.dict['header.form.query.delete']} |
| | | okText={props.dict['header.confirm']} |
| | | cancelText={props.dict['header.cancel']} |
| | | onConfirm={() => this.handleDelete(record.key) |
| | | }> |
| | | <span style={{color: '#1890ff', cursor: 'pointer'}}><Icon type="delete" /></span> |
| | | </Popconfirm> |
| | | </div> |
| | | ) : null, |
| | | } |
| | | ] |
| | |
| | | type: props.type, |
| | | linkSubFields: props.linkSubFields |
| | | } |
| | | } |
| | | |
| | | handleUpDown = (record, direction) => { |
| | | const { dataSource } = this.state |
| | | let index = 0 |
| | | |
| | | let _data = dataSource.filter((item, i) => { |
| | | if (item.key === record.key) { |
| | | index = i |
| | | } |
| | | |
| | | return item.key !== record.key |
| | | }) |
| | | if ((index === 0 && direction === 'up') || (index === dataSource.length - 1 && direction === 'down')) { |
| | | return |
| | | } |
| | | |
| | | if (direction === 'up') { |
| | | _data.splice(index - 1, 0, record) |
| | | } else { |
| | | _data.splice(index + 1, 0, record) |
| | | } |
| | | |
| | | this.setState({ |
| | | dataSource: _data |
| | | }) |
| | | } |
| | | |
| | | handleDelete = key => { |
| | |
| | | let dataSource = JSON.parse(JSON.stringify(this.state.dataSource)) |
| | | let _width = '40%' |
| | | let fields = [] |
| | | |
| | | console.log(linkSubFields) |
| | | if (type === 'select' && linkSubFields.length > this.state.linkSubFields) { |
| | | let addcol = linkSubFields[linkSubFields.length - 1] |
| | | dataSource = dataSource.map(data => { |
| | | data[addcol.field] = data.Text |
| | | return data |
| | | }) |
| | | console.log(addcol) |
| | | } |
| | | // console.log(linkSubFields) |
| | | // console.log(type) |
| | | // console.log(dataSource) |
| | | |
| | | if (type === 'link') { |
| | | _width = '27%' |
| | | } else { |
| | | } else if (type === 'select') { |
| | | _width = Math.floor(80 / (linkSubFields.length + 2)) + '%' |
| | | fields = linkSubFields.map(field => { |
| | | return { |
| | |
| | | } |
| | | }) |
| | | } |
| | | |
| | | console.log(fields) |
| | | |
| | | let columns = [ |
| | | { |
| | |
| | | dataIndex: 'operation', |
| | | render: (text, record) => |
| | | this.state.dataSource.length >= 1 ? ( |
| | | <Popconfirm title="Sure to delete?" onConfirm={() => this.handleDelete(record.key)}> |
| | | <span style={{color: '#1890ff', cursor: 'pointer'}}><Icon type="delete" /></span> |
| | | </Popconfirm> |
| | | <div> |
| | | <span className="operation-btn" title={this.props.dict['header.form.up']} onClick={() => this.handleUpDown(record, 'up')} style={{color: '#1890ff'}}><Icon type="arrow-up" /></span> |
| | | <span className="operation-btn" title={this.props.dict['header.form.down']} onClick={() => this.handleUpDown(record, 'down')} style={{color: '#ff4d4f'}}><Icon type="arrow-down" /></span> |
| | | <Popconfirm |
| | | title={this.props.dict['header.form.query.delete']} |
| | | okText={this.props.dict['header.confirm']} |
| | | cancelText={this.props.dict['header.cancel']} |
| | | onConfirm={() => this.handleDelete(record.key) |
| | | }> |
| | | <span style={{color: '#1890ff', cursor: 'pointer'}}><Icon type="delete" /></span> |
| | | </Popconfirm> |
| | | </div> |
| | | ) : null, |
| | | } |
| | | ] |
| | |
| | | } |
| | | |
| | | UNSAFE_componentWillReceiveProps (nextProps) { |
| | | if (this.props.type !== nextProps.type) { |
| | | this.resetColumn(nextProps.type) |
| | | } else if (!is(fromJS(this.props.linkSubFields), fromJS(nextProps.linkSubFields))) { |
| | | this.resetColumn(this.props.type, nextProps.linkSubFields) |
| | | if (!is(fromJS(this.props.linkSubFields), fromJS(nextProps.linkSubFields)) || this.props.type !== nextProps.type) { |
| | | this.resetColumn(nextProps.type, nextProps.linkSubFields) |
| | | } |
| | | } |
| | | |