king
2020-12-03 569ccb3c1ff82f30ffefa7d3700571448d742662
src/menu/components/table/normal-table/columns/editColumn/index.jsx
@@ -1,6 +1,6 @@
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { fromJS } from 'immutable'
import { is, fromJS } from 'immutable'
import { Form, Row, Col, Input, Select, InputNumber, Radio, Tooltip, Icon, Cascader, Modal } from 'antd'
import { getColumnForm } from './formconfig'
@@ -8,20 +8,24 @@
import './index.scss'
const columnTypeOptions = {
  text: ['label', 'field', 'type', 'Align', 'Hide', 'IsSort', 'Width', 'prefix', 'postfix', 'textFormat', 'fieldlength', 'blacklist', 'perspective', 'rowspan'],
  text: ['label', 'field', 'type', 'Align', 'Hide', 'IsSort', 'Width', 'prefix', 'postfix', 'textFormat', 'blacklist', 'perspective', 'rowspan'],
  number: ['label', 'field', 'type', 'Align', 'Hide', 'IsSort', 'Width', 'decimal', 'format', 'prefix', 'postfix', 'blacklist', 'perspective', 'sum'],
  link: ['label', 'field', 'type', 'Align', 'Hide', 'IsSort', 'joint', 'Width', 'fieldlength', 'blacklist'],
  textarea: ['label', 'field', 'type', 'Align', 'Hide', 'IsSort', 'Width', 'prefix', 'postfix', 'fieldlength', 'blacklist'],
  picture: ['label', 'field', 'type', 'Align', 'Hide', 'IsSort', 'Width', 'fieldlength', 'blacklist', 'scale', 'maxHeight']
  link: ['label', 'field', 'type', 'Align', 'Hide', 'IsSort', 'joint', 'Width', 'blacklist'],
  textarea: ['label', 'field', 'type', 'Align', 'Hide', 'IsSort', 'Width', 'prefix', 'postfix', 'blacklist'],
  picture: ['label', 'field', 'type', 'Align', 'Hide', 'IsSort', 'Width', 'blacklist', 'scale', 'lenWidRadio'],
  colspan: ['label', 'type', 'Align', 'Hide', 'blacklist'],
  custom: ['label', 'type', 'Align', 'Hide', 'Width', 'blacklist'],
  action: ['label', 'type', 'Align', 'Width']
}
class MainSearch extends Component {
  static propTpyes = {
    dict: PropTypes.object,     // 字典项
    visible: PropTypes.bool,
    column: PropTypes.object,
    fields: PropTypes.array,
    updateCol: PropTypes.func,  // 提交事件
    deleteCol: PropTypes.func   // 取消时删除事件
    submitCol: PropTypes.func,  // 提交事件
    cancelCol: PropTypes.func   // 取消时删除事件
  }
  state = {
@@ -29,16 +33,13 @@
    formlist: null
  }
  /**
   * @description 初次添加的显示列元素,聚焦提示文字
   */
  componentDidMount () {
    if (this.props.column.focus) {
      this.editColumn()
  UNSAFE_componentWillReceiveProps (nextProps) {
    if (nextProps.column && !is(fromJS(this.props.column), fromJS(nextProps.column))) {
      this.editColumn(nextProps.column)
    }
  }
  editColumn = () => {
  editColumn = (column) => {
    let menulist = sessionStorage.getItem('fstMenuList')
    if (menulist) {
      try {
@@ -50,14 +51,29 @@
      menulist = []
    }
    let formlist = getColumnForm(column, menulist, this.props.fields)
    let _options = fromJS(columnTypeOptions[column.type]).toJS()
    if (column.type === 'text' || column.type === 'number') {
      if (column.perspective !== 'linkurl') {
        _options.push('linkmenu')
      } else {
        _options.push('linkurl')
      }
    }
    this.setState({
      visible: true,
      formlist: getColumnForm(this.props.column, menulist, this.props.fields)
      type: column.type,
      formlist: formlist.map(item => {
        item.hidden = !_options.includes(item.key)
        return item
      })
    }, () => {
      if (this.props.column.focus) {
      if (column.focus) {
        try {
          let _form = document.getElementById('label')
          _form.select()
          _form && _form.select()
        } catch {
          console.warn('表单focus失败!')
        }
@@ -73,12 +89,6 @@
        _options.push('linkmenu')
      }
      let fieldlength = 50
      if (value !== 'text') {
        fieldlength = 512
      }
      this.setState({
        type: value,
        formlist: this.state.formlist.map(item => {
@@ -87,10 +97,12 @@
          return item
        })
      }, () => {
        if (this.props.form.getFieldValue('fieldlength') !== undefined) {
          this.props.form.setFieldsValue({fieldlength: fieldlength})
        } else if (this.props.form.getFieldValue('perspective') !== undefined) {
        if (value === 'link' || value === 'textarea' || value === 'picture') {
          this.props.form.setFieldsValue({IsSort: 'false'})
        } else if (value === 'text' || value === 'number') {
          this.props.form.setFieldsValue({perspective: 'linkmenu'})
        } else if (value === 'action' || value === 'colspan') {
          this.props.form.setFieldsValue({Align: 'center'})
        }
      })
    } else if (key === 'field') {
@@ -176,8 +188,8 @@
                    message: this.props.dict['form.required.input'] + item.label + '!'
                  }
                ]
              })(item.unlimit ? <InputNumber /> :
                  <InputNumber min={item.min} max={item.max} precision={item.decimal} />)}
              })(item.unlimit ? <InputNumber onPressEnter={this.handleSubmit}/> :
                  <InputNumber min={item.min} max={item.max} precision={item.decimal} onPressEnter={this.handleSubmit}/>)}
            </Form.Item>
          </Col>
        )
@@ -201,7 +213,7 @@
                  getPopupContainer={() => document.getElementById('columnwinter')}
                >
                  {item.options.map((option, index) =>
                    <Select.Option key={index} value={option.value || option.field}>
                    <Select.Option key={`${index}`} value={option.value || option.field}>
                      {option.text || option.label}
                    </Select.Option>
                  )}
@@ -287,7 +299,7 @@
    this.props.form.validateFieldsAndScroll((err, values) => {
      if (!err) {
        this.setState({visible: false, formlist: null})
        this.props.updateCol(values)
        this.props.submitCol(values)
      }
    })
  }
@@ -295,9 +307,7 @@
  editModalCancel = () => {
    this.setState({visible: false, formlist: null})
    if (this.props.column.focus) {
      this.props.deleteCol()
    }
    this.props.cancelCol()
  }
  render() {
@@ -312,9 +322,9 @@
        sm: { span: 18 }
      }
    }
    return (
      <div style={{display: 'inline-block'}}>
        <Icon className="edit" title="编辑" type="edit" onClick={this.editColumn} />
        <Modal
          title="显示列编辑"
          visible={visible}