king
2020-02-15 c76e56d9cc6f8f5e93aaf355b269ec8cac8c6b95
src/templates/formtabconfig/settingform/index.jsx
@@ -19,11 +19,12 @@
    columns: null,
    currentTabs: null,
    selectTabs: [],
    interReadonly: false
    interReadonly: false,
    primaryKey: ''
  }
  UNSAFE_componentWillMount() {
    const { config, menu } = this.props
    const { config } = this.props
    let _tabs = []
    let _select = []
@@ -32,9 +33,6 @@
    let _setting = config.setting
    
    try {
      if (menu && menu.LongParam) {
        _columns = menu.LongParam.columns.filter(item => item.field && item.type !== 'colspan')
      }
      config.groups.forEach(group => {
        let list = group.sublist.filter(item => item.field)
        _columns = [..._columns, ...list]
@@ -72,12 +70,30 @@
      }
    })
    let primaryKey = _setting.primaryKey
    if (primaryKey) {
      let field = _columns.filter(column => column.field === primaryKey)
      if (field.length !== 1) {
        primaryKey = ''
      }
    }
    if (!primaryKey) {
      _columns.forEach(col => {
        if (col.field.toLowerCase() === 'id') {
          primaryKey = col.field
        }
      })
    }
    this.setState({
      currentTabs: _tabs,
      selectTabs: _select,
      columns: _columns,
      setting: _setting,
      interReadonly: _setting.sysInterface === 'true'
      interType: _setting.interType || 'inner',
      interReadonly: _setting.sysInterface === 'true',
      datatype: _setting.datatype || 'maintable',
      primaryKey: primaryKey
    })
  }
@@ -131,10 +147,34 @@
    })
  }
  sourceChange = (e) => {
    const { interType } = this.state
    this.setState({
      datatype: e.target.value
    }, () => {
      if (interType === 'inner') return
      let _type = this.props.form.getFieldValue('sysInterface')
      if (_type === 'true') {
        this.props.form.setFieldsValue({
          interface: window.GLOB.mainSystemApi || window.GLOB.subSystemApi
        })
        this.setState({
          interReadonly: true
        })
      } else {
        this.setState({
          interReadonly: false
        })
      }
    })
  }
  render() {
    const { dict, usefulFields, menu } = this.props
    const { getFieldDecorator } = this.props.form
    const { interType, columns, selectTabs, setting } = this.state
    const { interType, columns, selectTabs, setting, datatype, primaryKey } = this.state
    const formItemLayout = {
      labelCol: {
@@ -145,17 +185,6 @@
        xs: { span: 24 },
        sm: { span: 16 }
      }
    }
    let primaryKey = setting.primaryKey
    if (primaryKey) {
      let field = columns.filter(column => column.field === primaryKey)
      if (field.length !== 1) {
        primaryKey = ''
      }
    }
    if (!primaryKey && columns.length === 0) {
      primaryKey = 'ID'
    }
    let str = '^(' + usefulFields.join('|') + ')'
@@ -195,9 +224,37 @@
            </Form.Item>
          </Col>
          <Col span={12}>
            <Form.Item label={dict['header.menu.datasource']}>
              {getFieldDecorator('datatype', {
                initialValue: setting.datatype || 'maintable'
              })(
                <Radio.Group onChange={this.sourceChange}>
                  <Radio value="maintable">{dict['header.menu.maintable']}</Radio>
                  <Radio value="query">{dict['header.menu.query']}</Radio>
                </Radio.Group>
              )}
            </Form.Item>
          </Col>
          {datatype === 'query' ? <Col span={12}>
            <Form.Item label="主键">
              {getFieldDecorator('primaryKey', {
                initialValue: primaryKey || ''
              })(
                <Select
                  getPopupContainer={() => document.getElementById('commontable-setting-form')}
                >
                  <Select.Option key='unset' value="">未设置</Select.Option>
                  {columns.map((option, index) =>
                    <Select.Option id={option.uuid} title={option.label} key={index} value={option.field}>{option.label}</Select.Option>
                  )}
                </Select>
              )}
            </Form.Item>
          </Col> : null}
          {datatype === 'query' ? <Col span={12}>
            <Form.Item label={dict['header.form.intertype']}>
              {getFieldDecorator('interType', {
                initialValue: setting.interType || 'inner'
                initialValue: interType
              })(
                <Radio.Group onChange={this.onChange}>
                  <Radio value="inner">{dict['header.form.interface.inner']}</Radio>
@@ -205,8 +262,8 @@
                </Radio.Group>
              )}
            </Form.Item>
          </Col>
          {interType === 'outer' ? <Col span={12}>
          </Col> : null}
          {datatype === 'query' && interType === 'outer' ? <Col span={12}>
            <Form.Item label={dict['header.form.sysInterface']}>
              {getFieldDecorator('sysInterface', {
                initialValue: setting.sysInterface || 'false'
@@ -218,7 +275,7 @@
              )}
            </Form.Item>
          </Col> : null}
          {interType === 'outer' ? <Col span={12}>
          {datatype === 'query' && interType === 'outer' ? <Col span={12}>
            <Form.Item label={dict['header.form.interface']}>
              {getFieldDecorator('interface', {
                initialValue: setting.sysInterface === 'true' ? (window.GLOB.mainSystemApi || window.GLOB.subSystemApi) : (setting.interface || ''),
@@ -235,7 +292,7 @@
              })(<Input placeholder="" autoComplete="off" disabled={this.state.interReadonly} />)}
            </Form.Item>
          </Col> : null}
          {interType !== 'outer' ? <Col span={12}>
          {datatype === 'query' && interType !== 'outer' ? <Col span={12}>
            <Form.Item label={
              <Tooltip placement="topLeft" overlayClassName="middle" title={`可自定义数据处理函数,函数名称需以${usefulFields.join(', ')}等字符开始;未设置时会调用系统函数,使用系统函数需完善数据源。`}>
                <Icon type="question-circle" />
@@ -256,7 +313,7 @@
              })(<Input placeholder="" autoComplete="off" />)}
            </Form.Item>
          </Col> : null}
          {interType !== 'outer' ? <Col span={24}>
          {datatype === 'query' && interType !== 'outer' ? <Col span={24}>
            <Form.Item help={'数据ID:' + menu.MenuID} label={
              <Tooltip placement="topLeft" title="使用系统函数时,需填写数据源,自定义函数时,可忽略。">
                <Icon type="question-circle" />
@@ -268,7 +325,7 @@
              })(<TextArea rows={4} />)}
            </Form.Item>
          </Col> : null}
          {interType === 'outer' ? <Col span={12}>
          {datatype === 'query' && interType === 'outer' ? <Col span={12}>
            <Form.Item label={dict['header.form.outerFunc']}>
              {getFieldDecorator('outerFunc', {
                initialValue: setting.outerFunc || '',
@@ -284,26 +341,6 @@
              })(<Input placeholder="" autoComplete="off" />)}
            </Form.Item>
          </Col> : null}
          <Col span={12}>
            <Form.Item label="主键">
              {getFieldDecorator('primaryKey', {
                initialValue: primaryKey
              })(
                <Select
                  getPopupContainer={() => document.getElementById('commontable-setting-form')}
                >
                  <Select.Option key='unset' value="">不设置</Select.Option>
                  {columns.length === 0 ?
                    <Select.Option key='id' value="ID">ID</Select.Option> : null
                  }
                  {columns.map((option, index) =>
                    <Select.Option id={option.uuid} title={option.label} key={index} value={option.field}>{option.label}</Select.Option>
                  )}
                </Select>
              )}
            </Form.Item>
          </Col>
          <Col span={12}>
            <Form.Item label={
              <Tooltip placement="topLeft" title="主表可选取关联标签,标签关联后,主表数据切换时,下级标签会跟随主表主键值变化。">