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/comtableconfig/settingform/index.jsx | 43 +++++++++++++++++++++++-------------------- 1 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/templates/comtableconfig/settingform/index.jsx b/src/templates/comtableconfig/settingform/index.jsx index 4d3b356..b55e8b4 100644 --- a/src/templates/comtableconfig/settingform/index.jsx +++ b/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> )} -- Gitblit v1.8.0