king
2020-02-15 c76e56d9cc6f8f5e93aaf355b269ec8cac8c6b95
src/templates/comtableconfig/settingform/index.jsx
@@ -21,11 +21,12 @@
    columns: this.props.columns.filter(item => item.field && item.type !== 'colspan'),
    currentTabs: null,
    selectTabs: [],
    interReadonly: false
    interReadonly: false,
    primaryKey: ''
  }
  UNSAFE_componentWillMount() {
    const { config, data } = this.props
    const { config, data, columns } = this.props
    let _tabs = []
    let _select = []
    let _tabMap = new Map()
@@ -45,10 +46,26 @@
      }
    })
    let primaryKey = data.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,
      interReadonly: data.sysInterface === 'true'
      interReadonly: data.sysInterface === 'true',
      primaryKey: primaryKey
    })
  }
@@ -122,7 +139,7 @@
  render() {
    const { data, dict, menu, usefulFields } = this.props
    const { getFieldDecorator } = this.props.form
    const { interType, columns, selectTabs } = this.state
    const { interType, columns, selectTabs, primaryKey } = this.state
    const formItemLayout = {
      labelCol: {
@@ -133,17 +150,6 @@
        xs: { span: 24 },
        sm: { span: 16 }
      }
    }
    let primaryKey = data.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('|') + ')'
@@ -319,16 +325,13 @@
          <Col span={12}>
            <Form.Item label="主键">
              {getFieldDecorator('primaryKey', {
                initialValue: primaryKey
                initialValue: primaryKey || ''
              })(
                <Select
                  getPopupContainer={() => document.getElementById('commontable-setting-form')}
                  onChange={this.selectChange}
                >
                  <Select.Option key='unset' value="">不设置</Select.Option>
                  {columns.length === 0 ?
                    <Select.Option key='id' value="ID">ID</Select.Option> : null
                  }
                  <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>
                  )}