king
2021-10-27 bbcb3f45ad0ef4c808bf5a68ec10c0464c094e2f
src/menu/components/table/edit-table/columns/editColumn/index.jsx
@@ -1,7 +1,7 @@
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { is, fromJS } from 'immutable'
import { Form, Row, Col, Input, Select, InputNumber, Radio, Tooltip, Icon, Cascader, Modal } from 'antd'
import { Form, Row, Col, Input, Select, InputNumber, Radio, Tooltip, Icon, Modal, notification } from 'antd'
import { getColumnForm } from './formconfig'
import { formRule } from '@/utils/option.js'
@@ -9,22 +9,21 @@
const { TextArea } = Input
const columnTypeOptions = {
  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', 'rowspan'],
  link: ['label', 'field', 'type', 'Align', 'Hide', 'IsSort', 'joint', 'Width', 'blacklist', 'nameField'],
  textarea: ['label', 'field', 'type', 'Align', 'Hide', 'IsSort', 'Width', 'prefix', 'postfix', 'blacklist'],
  picture: ['label', 'field', 'type', 'Align', 'Hide', 'IsSort', 'Width', 'blacklist', 'scale', 'lenWidRadio', 'picSort'],
  colspan: ['label', 'type', 'Align', 'Hide', 'blacklist'],
  text: ['label', 'field', 'type', 'Align', 'Hide', 'IsSort', 'Width', 'prefix', 'postfix', 'textFormat', 'editable', 'initval', 'blacklist'],
  number: ['label', 'field', 'type', 'Align', 'Hide', 'IsSort', 'Width', 'decimal', 'format', 'prefix', 'postfix', 'editable', 'initval', 'sum', 'blacklist'],
  textarea: ['label', 'field', 'type', 'Align', 'Hide', 'Width', 'prefix', 'initval', 'postfix', 'blacklist'],
  custom: ['label', 'type', 'Align', 'Hide', 'Width', 'blacklist'],
  action: ['label', 'type', 'Align', 'Width'],
  formula: ['label', 'type', 'Align', 'Hide', 'Width', 'prefix', 'postfix', 'eval', 'formula', 'blacklist'],
  index: ['label', 'type', 'Align', 'Width']
}
class MainSearch extends Component {
class EdiTableColumn extends Component {
  static propTpyes = {
    dict: PropTypes.object,     // 字典项
    visible: PropTypes.bool,
    column: PropTypes.object,
    columns: PropTypes.array,
    fields: PropTypes.array,
    submitCol: PropTypes.func,  // 提交事件
    cancelCol: PropTypes.func   // 取消时删除事件
@@ -42,18 +41,20 @@
  }
  editColumn = (column) => {
    let formlist = getColumnForm(column, this.props.fields)
    let formlist = getColumnForm(column, this.props.fields, this.props.columns)
    let _options = fromJS(columnTypeOptions[column.type]).toJS()
    if (column.type === 'text' || column.type === 'number') {
      if (column.perspective === 'linkmenu') {
        _options.push('linkmenu', 'linkfields', 'open')
      } else if (column.perspective === 'linkurl') {
        _options.push('linkurl', 'linkfields', 'open')
    if (column.editable === 'true') {
      if (column.type === 'text') {
        _options.push('required', 'enter', 'footEnter')
      } else if (column.type === 'number') {
        _options.push('max', 'min', 'enter', 'footEnter')
      }
    }
    this.setState({
      visible: true,
      editable: column.editable || 'false',
      type: column.type,
      formlist: formlist.map(item => {
        item.hidden = !_options.includes(item.key)
@@ -73,22 +74,30 @@
  }
  typeChange = (key, value, option) => {
    const { editable, type } = this.state
    if (key === 'type') {
      let _options = fromJS(columnTypeOptions[value]).toJS()
      if (editable === 'true') {
        if (value === 'text') {
          _options.push('required', 'enter', 'footEnter')
        } else if (value === 'number') {
          _options.push('max', 'min', 'enter', 'footEnter')
        }
      }
      this.setState({
        type: value,
        formlist: this.state.formlist.map(item => {
          if (item.key === 'editable') {
            item.initVal = editable
          }
          item.hidden = !_options.includes(item.key)
          return item
        })
      }, () => {
        if (value === 'link' || value === 'textarea' || value === 'picture') {
          this.props.form.setFieldsValue({IsSort: 'false'})
        } else if (value === 'text' || value === 'number') {
          this.props.form.setFieldsValue({perspective: ''})
        } else if (value === 'action' || value === 'colspan') {
        if (value === 'action') {
          this.props.form.setFieldsValue({Align: 'center'})
        }
      })
@@ -106,12 +115,22 @@
      }
      if (values.type !== this.state.type) {
        values.perspective = ''
        let _options = fromJS(columnTypeOptions[values.type]).toJS()
        if (editable === 'true') {
          if (values.type === 'text') {
            _options.push('required', 'enter', 'footEnter')
          } else if (values.type === 'number') {
            _options.push('max', 'min', 'enter', 'footEnter')
          }
        }
        this.setState({
          type: values.type,
          formlist: this.state.formlist.map(item => {
            if (item.key === 'editable') {
              item.initVal = editable
            }
            item.hidden = !_options.includes(item.key)
            return item
@@ -124,20 +143,19 @@
      }
    } else if (key === 'format' && value === 'percent') {
      this.props.form.setFieldsValue({postfix: '%'})
    }
  }
    } else if (key === 'editable') {
      let _options = fromJS(columnTypeOptions[type]).toJS()
  changeRadio = (key, value) => {
    if (key === 'perspective') {
      let _options = fromJS(columnTypeOptions[this.state.type]).toJS()
      if (value === 'linkmenu') {
        _options.push('linkmenu', 'linkfields', 'open')
      } else if (value === 'linkurl') {
        _options.push('linkurl', 'linkfields', 'open')
      if (value === 'true') {
        if (type === 'text') {
          _options.push('required', 'enter', 'footEnter')
        } else if (type === 'number') {
          _options.push('max', 'min', 'enter', 'footEnter')
        }
      }
      this.setState({
        editable: value,
        formlist: this.state.formlist.map(item => {
          item.hidden = !_options.includes(item.key)
@@ -255,7 +273,7 @@
                  }
                ]
              })(
                <Radio.Group onChange={(e) => {this.changeRadio(item.key, e.target.value)}}>
                <Radio.Group onChange={(e) => {this.typeChange(item.key, e.target.value)}}>
                  {
                    item.options.map(option => {
                      return (
@@ -288,28 +306,6 @@
            </Form.Item>
          </Col>
        )
      } else if (item.type === 'cascader') { // 多选
        fields.push(
          <Col span={12} key={index}>
            <Form.Item label={item.label}>
              {getFieldDecorator(item.key, {
                initialValue: item.initVal || [],
                rules: [
                  {
                    required: !!item.required,
                    message: this.props.dict['form.required.select'] + item.label + '!'
                  }
                ]
              })(
                <Cascader
                  options={item.options}
                  placeholder=""
                  getPopupContainer={() => document.getElementById('columnwinter')}
                />
              )}
            </Form.Item>
          </Col>
        )
      } else if (item.type === 'textarea') { // 文本搜索
        fields.push(
          <Col span={24} key={index} className="textarea">
@@ -327,7 +323,7 @@
                    message: this.props.dict['form.required.input'] + item.label + '!'
                  }
                ]
              })(<TextArea rows={2} disabled={item.readonly} onPressEnter={this.handleSubmit} />)}
              })(<TextArea rows={2} disabled={item.readonly} placeholder={item.placeholder || ''} />)}
            </Form.Item>
          </Col>
        )
@@ -337,9 +333,21 @@
  }
  handleSubmit = () => {
    const { columns, column } = this.props
    // 表单提交时检查输入值是否正确
    this.props.form.validateFieldsAndScroll((err, values) => {
      if (!err) {
        values.uuid = column.uuid
        values.marks = column.marks || []
        if (values.field && columns.filter(col => col.field && col.uuid !== values.uuid && col.field === values.field).length > 0) {
          notification.warning({
            top: 92,
            message: '字段已添加!',
            duration: 5
          })
          return
        }
        this.setState({visible: false, formlist: null})
        this.props.submitCol(values)
      }
@@ -385,4 +393,4 @@
  }
}
export default Form.create()(MainSearch)
export default Form.create()(EdiTableColumn)