| | |
| | | import React, {Component} from 'react' |
| | | import { is, fromJS } from 'immutable' |
| | | import { Table, Input, Button, Popconfirm, Form, Icon } from 'antd' |
| | | import Utils from '@/utils/utils.js' |
| | | import './index.scss' |
| | |
| | | class EditTable extends Component { |
| | | constructor(props) { |
| | | super(props) |
| | | |
| | | let _width = '40%' |
| | | let fields = [] |
| | | |
| | | if (props.type === 'link') { |
| | | _width = '27%' |
| | | } else { |
| | | _width = Math.floor(80 / (props.linkSubFields.length + 2)) + '%' |
| | | fields = props.linkSubFields.map(field => { |
| | | return { |
| | | title: field.label, |
| | | dataIndex: field.field, |
| | | width: _width, |
| | | editable: true |
| | | } |
| | | }) |
| | | } |
| | | |
| | | let columns = [ |
| | | { |
| | | title: 'Value', |
| | | dataIndex: 'Value', |
| | | width: props.type === 'link' ? '27%' : '40%', |
| | | width: _width, |
| | | editable: true |
| | | }, |
| | | { |
| | | title: 'Text', |
| | | dataIndex: 'Text', |
| | | width: props.type === 'link' ? '27%' : '40%', |
| | | width: _width, |
| | | editable: true |
| | | }, |
| | | ...fields, |
| | | { |
| | | title: '操作', |
| | | align: 'center', |
| | |
| | | this.setState({ dataSource: newData }) |
| | | } |
| | | |
| | | resetColumn = (type) => { |
| | | resetColumn = (type, linkSubFields) => { |
| | | let _width = '40%' |
| | | let fields = [] |
| | | |
| | | if (type === 'link') { |
| | | _width = '27%' |
| | | } else { |
| | | _width = Math.floor(80 / (linkSubFields.length + 2)) + '%' |
| | | fields = linkSubFields.map(field => { |
| | | return { |
| | | title: field.label, |
| | | dataIndex: field.field, |
| | | width: _width, |
| | | editable: true |
| | | } |
| | | }) |
| | | } |
| | | |
| | | let columns = [ |
| | | { |
| | | title: 'Value', |
| | | dataIndex: 'Value', |
| | | width: type === 'link' ? '27%' : '40%', |
| | | width: _width, |
| | | editable: true |
| | | }, |
| | | { |
| | | title: 'Text', |
| | | dataIndex: 'Text', |
| | | width: type === 'link' ? '27%' : '40%', |
| | | width: _width, |
| | | editable: true |
| | | }, |
| | | ...fields, |
| | | { |
| | | title: '操作', |
| | | align: 'center', |
| | |
| | | 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) |
| | | } |
| | | } |
| | | |