king
2020-02-10 b70376bd370f83e0087e629b664243f3a4bf191c
src/templates/ushare/editable/index.jsx
@@ -1,4 +1,5 @@
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'
@@ -91,19 +92,38 @@
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',
@@ -166,20 +186,38 @@
    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',
@@ -211,6 +249,8 @@
  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)
    }
  }