king
2020-02-15 c76e56d9cc6f8f5e93aaf355b269ec8cac8c6b95
src/templates/subtableconfig/settingform/index.jsx
@@ -18,7 +18,31 @@
  state = {
    interType: this.props.data.interType || 'inner',
    columns: this.props.columns.filter(item => item.field && item.type !== 'colspan'),
    interReadonly: this.props.data.sysInterface === 'true'
    interReadonly: this.props.data.sysInterface === 'true',
    primaryKey: ''
  }
  UNSAFE_componentWillMount() {
    const { data, columns } = this.props
    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({
      primaryKey: primaryKey
    })
  }
  handleConfirm = () => {
@@ -94,7 +118,7 @@
  render() {
    const { data, dict, tabId, usefulFields } = this.props
    const { getFieldDecorator } = this.props.form
    const { interType, columns } = this.state
    const { interType, columns, primaryKey } = this.state
    const formItemLayout = {
      labelCol: {
@@ -105,17 +129,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('|') + ')'
@@ -266,16 +279,13 @@
          <Col span={12}>
            <Form.Item label="主键">
              {getFieldDecorator('primaryKey', {
                initialValue: primaryKey
                initialValue: primaryKey || ''
              })(
                <Select
                  getPopupContainer={() => document.getElementById('subtable-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>
                  )}