king
2020-10-23 407c0f1765c7d085218a91ad8842784977383d05
src/templates/formtabconfig/actionform/index.jsx
@@ -2,76 +2,77 @@
import PropTypes from 'prop-types'
import { Form, Row, Col, Input, Select, Icon, Radio, notification, Tooltip, InputNumber } from 'antd'
import { btnIcons, btnClasses, formRule } from '@/utils/option.js'
import Utils from '@/utils/utils.js'
// import Utils from '@/utils/utils.js'
import './index.scss'
const { TextArea } = Input
class MainSearch extends Component {
  static propTpyes = {
    dict: PropTypes.object,  // 字典项
    formlist: PropTypes.any, // 表单信息
    card: PropTypes.any,     // 按钮信息
    tabs: PropTypes.array    // 所有标签页
    dict: PropTypes.object,      // 字典项
    formlist: PropTypes.any,     // 表单信息
    card: PropTypes.any,         // 按钮信息
    tabs: PropTypes.array,       // 所有标签页
    inputSubmit: PropTypes.any   // 回车提交事件
  }
  state = {
    formlist: null,  // 表单信息
    openType: null,  // 打开方式
    interType: null, // 接口类型:内部、外部
    position: null,  // 按钮位置
    reqOptionSgl: [{
      value: 'requiredSgl',
      text: this.props.dict['header.form.requiredSgl']
    }],
    reqOptions: [{
      value: 'notRequired',
      text: this.props.dict['header.form.notRequired']
    }, {
      value: 'requiredSgl',
      text: this.props.dict['header.form.requiredSgl']
    }],
    reqOptionsMutil: [{
      value: 'notRequired',
      text: this.props.dict['header.form.notRequired']
    }, {
      value: 'requiredSgl',
      text: this.props.dict['header.form.requiredSgl']
    }, {
      value: 'required',
      text: this.props.dict['header.form.required']
    }, {
      value: 'requiredOnce',
      text: this.props.dict['header.form.requiredOnce']
    }],
    insertUpdateOptions: [{
      value: '',
      text: this.props.dict['header.form.empty']
      text: this.props.dict['model.empty']
    }, {
      value: 'insert',
      text: this.props.dict['header.form.action.insert']
    }, {
      value: 'update',
      text: this.props.dict['header.form.action.update']
    }, {
      value: 'insertOrUpdate',
      text: this.props.dict['header.form.action.insertOrUpdate']
    }],
    returnoptions: [{ // 返回后-不刷新、刷新页面、刷新表格
      value: 'never',
      text: this.props.dict['header.form.refresh.never']
    }, {
      value: 'grid',
      text: this.props.dict['header.form.refresh.grid']
    }, {
      value: 'view',
      text: this.props.dict['header.form.refresh.view']
    }],
    currentoptions: [{ // 不返回时-不刷新、刷新
      value: 'never',
      text: this.props.dict['header.form.refresh.never']
    }, {
      value: 'refresh',
      text: this.props.dict['header.form.refresh']
    }]
  }
  
  UNSAFE_componentWillMount () {
    const { card } = this.props
    let _intertype = ''
    let _options = null
    let _success = 'close'
    let _error = 'notclose'
    this.props.formlist.forEach(form => {
      if (form.key === 'intertype') {
        _intertype = form.initVal
        if (card.btnType !== 'confirm') {
          form.options = form.options.filter(op => op.value !== 'system')
        }
      } else if (form.key === 'afterExecSuccess') {
        _success = form.initVal
      } else if (form.key === 'afterExecError') {
        _error = form.initVal
      }
    })
    if (_intertype === 'outer') {
      _options = ['label', 'OpenType', 'intertype', 'innerFunc', 'interface', 'outerFunc', 'callbackFunc', 'sysInterface', 'icon', 'class', 'execSuccess', 'execError', 'method']
    } else {
      _options = ['label', 'OpenType', 'intertype', 'innerFunc', 'icon', 'class', 'execSuccess', 'execError', 'sql', 'sqlType']
    }
    let _options = this.getOptions(card.btnType, _intertype)
    this.setState({
      formlist: this.props.formlist.map(item => {
@@ -81,7 +82,37 @@
          item.options = btnIcons
        } else if (item.key === 'sqlType') {
          item.options = this.state.insertUpdateOptions
        } else if (item.key === 'OpenType') {
          item.options = [
            {
              value: 'prompt',
              text: this.props.dict['model.form.prompt']
            }, {
              value: 'exec',
              text: this.props.dict['model.form.exec']
            }
          ]
          if (card.btnType === 'cancel') {
            item.readonly = true
          }
        } else if (item.key === 'execSuccess' && card.btnType === 'cancel') {
          item.label = '关闭后'
        } else if (item.key === 'execSuccess' && card.btnType !== 'cancel') {
          if (_success === 'close') {
            item.options = this.state.returnoptions
          } else {
            item.options = this.state.currentoptions
          }
        } else if (item.key === 'execError') {
          if (_error === 'close') {
            item.options = this.state.returnoptions
          } else {
            item.options = this.state.currentoptions
          }
        } else if (item.key === 'innerFunc' && card.btnType !== 'confirm' && _intertype === 'inner') {
          item.required = true
        }
        item.hidden = !_options.includes(item.key)
        return item
      })
@@ -101,22 +132,119 @@
    }
  }
  onChange = (e, key) => {
    let value = e.target.value
    if (key === 'intertype') {
      let _options = null
      if (value === 'inner') {
        _options = ['label', 'OpenType', 'intertype', 'innerFunc', 'icon', 'class', 'execSuccess', 'execError', 'sql', 'sqlType']
  getOptions = (btnType, intertype) => {
    let _options = []
    if (btnType === 'cancel') {
      _options = ['label', 'OpenType', 'icon', 'class', 'execSuccess']
    } else if (btnType === 'confirm') {
      if (intertype === 'outer') {
        _options = ['label', 'OpenType', 'intertype', 'innerFunc', 'interface', 'outerFunc', 'callbackFunc', 'sysInterface', 'icon', 'class', 'execSuccess', 'execError', 'afterExecSuccess', 'afterExecError']
      } else if (intertype === 'system') {
        _options = ['label', 'OpenType', 'intertype', 'icon', 'class', 'execSuccess', 'execError', 'sql', 'sqlType', 'afterExecSuccess', 'afterExecError']
      } else {
        _options = ['label', 'OpenType', 'intertype', 'innerFunc', 'icon', 'class', 'execSuccess', 'execError', 'sysInterface', 'interface', 'outerFunc', 'callbackFunc', 'method']
        _options = ['label', 'OpenType', 'intertype', 'innerFunc', 'icon', 'class', 'execSuccess', 'execError', 'afterExecSuccess', 'afterExecError']
      }
    } else {
      if (intertype === 'outer') {
        _options = ['label', 'OpenType', 'intertype', 'innerFunc', 'interface', 'outerFunc', 'callbackFunc', 'sysInterface', 'icon', 'class', 'execSuccess', 'execError', 'afterExecSuccess', 'afterExecError']
      } else {
        _options = ['label', 'OpenType', 'intertype', 'innerFunc', 'icon', 'class', 'execSuccess', 'execError', 'afterExecSuccess', 'afterExecError']
      }
    }
    return _options
  }
  selectChange = (key, value) => {
    if (key === 'afterExecSuccess') {
      this.setState({
        formlist: this.state.formlist.map(item => {
          if (item.key === 'execSuccess') {
            if (value === 'close') {
              item.options = this.state.returnoptions
            } else {
              item.options = this.state.currentoptions
            }
          }
          return item
        })
      })
      this.props.form.setFieldsValue({
        execSuccess: 'never'
      })
    } else if (key === 'afterExecError') {
      this.setState({
        formlist: this.state.formlist.map(item => {
          if (item.key === 'execError') {
            if (value === 'close') {
              item.options = this.state.returnoptions
            } else {
              item.options = this.state.currentoptions
            }
          }
          return item
        })
      })
      this.props.form.setFieldsValue({
        execError: 'never'
      })
    }
  }
  onChange = (e, key) => {
    const { card } = this.props
    let value = e.target.value
    if (key === 'intertype') {
      let _options = this.getOptions(card.btnType, value)
      this.setState({
        interType: value,
        formlist: this.state.formlist.map(item => {
          item.hidden = !_options.includes(item.key)
          if (item.key === 'interface') {
            item.readonly = false
          } else if (item.key === 'sysInterface') {
            item.initVal = 'false'
          } else if (item.key === 'innerFunc' && value === 'inner') {
            item.required = true
          } else if (item.key === 'innerFunc' && value === 'outer') {
            item.required = false
          }
          return item
        })
      })
    } else if (key === 'sysInterface') {
      if (value === 'true') {
        this.props.form.setFieldsValue({
          interface: window.GLOB.mainSystemApi || ''
        })
      }
      this.setState({
        formlist: this.state.formlist.map(item => {
          if (item.key === 'interface' && value === 'true') {
            item.readonly = true
          } else if (item.key === 'interface') {
            item.readonly = false
          }
          return item
        })
      })
    }
  }
  handleSubmit = (e) => {
    e.preventDefault()
    if (this.props.inputSubmit) {
      this.props.inputSubmit()
    }
  }
@@ -170,7 +298,7 @@
                  },
                  ..._rules
                ]
              })(<Input placeholder="" autoComplete="off" disabled={item.readonly} />)}
              })(<Input placeholder="" autoComplete="off" disabled={item.readonly} onPressEnter={this.handleSubmit} />)}
            </Form.Item>
          </Col>
        )
@@ -211,6 +339,8 @@
                  showSearch
                  filterOption={(input, option) => option.props.children[2].toLowerCase().indexOf(input.toLowerCase()) >= 0}
                  getPopupContainer={() => document.getElementById('winter')}
                  onChange={(val) => this.selectChange(item.key, val)}
                  disabled={!!item.readonly}
                >
                  {item.options.map((option, index) =>
                    <Select.Option id={`${index}`} title={option.text} key={`${index}`} value={option.value}>
@@ -268,34 +398,25 @@
    return new Promise((resolve, reject) => {
      this.props.form.validateFieldsAndScroll((err, values) => {
        if (!err) {
          values.id = this.props.card.id
          values.uuid = this.props.card.uuid
          values.verify = this.props.card.verify || null
          values.btnType = this.props.card.btnType || 'tabFormBtn'
          if (values.OpenType === 'excelIn' || values.OpenType === 'excelOut') {
            values.position = 'toolbar'
            values.Ot = 'notRequired'
          } else if (values.OpenType === 'popview' && !values.linkTab) { // 没有关联标签(新建时),创建新标签Id
            values.linkTab = Utils.getuuid()
          }
          if (values.innerFunc === '' && values.sql === '') {
            notification.warning({
              top: 92,
              message: this.props.dict['header.form.actionhelp.datasource'],
              duration: 10
              message: '使用系统函数时,请填写表名,使用自定义函数时,可忽略。',
              duration: 5
            })
          } else if (values.innerFunc === '' && values.sql !== '' && values.sqlType === '') {
            notification.warning({
              top: 92,
              message: this.props.dict['header.form.actionhelp.sqlType'],
              duration: 10
              message: '使用系统函数时,请选择操作类型,使用自定义函数时,可忽略。',
              duration: 5
            })
          } else {
            resolve({
              type: 'action',
              values
            })
            resolve(values)
          }
        } else {
          reject(err)