From c76e56d9cc6f8f5e93aaf355b269ec8cac8c6b95 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期六, 15 二月 2020 02:18:10 +0800
Subject: [PATCH] 2020-02-15

---
 src/templates/subtableconfig/settingform/index.jsx |   46 ++++++++++++++++++++++++++++------------------
 1 files changed, 28 insertions(+), 18 deletions(-)

diff --git a/src/templates/subtableconfig/settingform/index.jsx b/src/templates/subtableconfig/settingform/index.jsx
index a67d205..41a9c8a 100644
--- a/src/templates/subtableconfig/settingform/index.jsx
+++ b/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>
                   )}

--
Gitblit v1.8.0