From 0c84df247914f893ef5e41d57a422e10a2dc814c Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期五, 12 十一月 2021 17:02:06 +0800
Subject: [PATCH] 2021-11-12

---
 src/templates/formtabconfig/settingform/index.jsx |  127 ++++++++++++++++++++++++++----------------
 1 files changed, 78 insertions(+), 49 deletions(-)

diff --git a/src/templates/formtabconfig/settingform/index.jsx b/src/templates/formtabconfig/settingform/index.jsx
index b469fbf..3d916d5 100644
--- a/src/templates/formtabconfig/settingform/index.jsx
+++ b/src/templates/formtabconfig/settingform/index.jsx
@@ -1,7 +1,10 @@
 import React, {Component} from 'react'
 import PropTypes from 'prop-types'
-import { Form, Row, Col, Input, Radio, Select, Tooltip, Icon, notification } from 'antd'
+import { Form, Row, Col, Input, Radio, Select, Tooltip, notification, InputNumber } from 'antd'
+import { QuestionCircleOutlined } from '@ant-design/icons'
+
 import { formRule } from '@/utils/option.js'
+import Utils from '@/utils/utils.js'
 import './index.scss'
 
 const { TextArea } = Input
@@ -11,14 +14,14 @@
     dict: PropTypes.object, // 瀛楀吀椤�
     menu: PropTypes.object,
     config: PropTypes.object,
-    usefulFields: PropTypes.array
+    inputSubmit: PropTypes.any     // 鍥炶溅鎻愪氦浜嬩欢
   }
 
   state = {
     interType: (this.props.config.setting && this.props.config.setting.interType) || 'inner',
     columns: null,
+    usefulFields: [],
     interReadonly: false,
-    primaryKey: ''
   }
 
   UNSAFE_componentWillMount() {
@@ -42,27 +45,23 @@
           return true
         }
       })
-    } catch {
+    } catch (e) {
       notification.warning({
         top: 92,
         message: '鑿滃崟淇℃伅閿欒锛�',
-        duration: 10
+        duration: 5
       })
     }
 
-    let primaryKey = _setting.primaryKey
-    if (primaryKey) {
-      let field = _columns.filter(column => column.field === primaryKey)
-      if (field.length !== 1) {
-        primaryKey = ''
+    let usefulFields = sessionStorage.getItem('permFuncField')
+    if (usefulFields) {
+      try {
+        usefulFields = JSON.parse(usefulFields)
+      } catch (e) {
+        usefulFields = []
       }
-    }
-    if (!primaryKey) {
-      _columns.forEach(col => {
-        if (col.field.toLowerCase() === 'id') {
-          primaryKey = col.field
-        }
-      })
+    } else {
+      usefulFields = []
     }
 
     this.setState({
@@ -71,7 +70,7 @@
       interType: _setting.interType || 'inner',
       interReadonly: _setting.sysInterface === 'true',
       datatype: _setting.datatype || 'maintable',
-      primaryKey: primaryKey
+      usefulFields
     })
   }
 
@@ -80,6 +79,17 @@
     return new Promise((resolve, reject) => {
       this.props.form.validateFieldsAndScroll((err, values) => {
         if (!err) {
+          let error = Utils.verifySql(values.dataresource)
+
+          if (error) {
+            notification.warning({
+              top: 92,
+              message: '鏁版嵁婧愪腑涓嶅彲浣跨敤' + error,
+              duration: 5
+            })
+            return
+          }
+
           resolve(values)
         } else {
           reject(err)
@@ -91,7 +101,7 @@
   onSysChange = (e) => {
     if (e.target.value === 'true') {
       this.props.form.setFieldsValue({
-        interface: window.GLOB.mainSystemApi || window.GLOB.subSystemApi
+        interface: window.GLOB.mainSystemApi || ''
       })
       this.setState({
         interReadonly: true
@@ -112,7 +122,7 @@
       let _type = this.props.form.getFieldValue('sysInterface')
       if (_type === 'true') {
         this.props.form.setFieldsValue({
-          interface: window.GLOB.mainSystemApi || window.GLOB.subSystemApi
+          interface: window.GLOB.mainSystemApi || ''
         })
         this.setState({
           interReadonly: true
@@ -136,7 +146,7 @@
       let _type = this.props.form.getFieldValue('sysInterface')
       if (_type === 'true') {
         this.props.form.setFieldsValue({
-          interface: window.GLOB.mainSystemApi || window.GLOB.subSystemApi
+          interface: window.GLOB.mainSystemApi || ''
         })
         this.setState({
           interReadonly: true
@@ -149,10 +159,18 @@
     })
   }
 
+  handleSubmit = (e) => {
+    e.preventDefault()
+
+    if (this.props.inputSubmit) {
+      this.props.inputSubmit()
+    }
+  }
+
   render() {
-    const { dict, usefulFields, menu } = this.props
+    const { dict, menu } = this.props
     const { getFieldDecorator } = this.props.form
-    const { interType, columns, setting, datatype, primaryKey } = this.state
+    const { interType, setting, datatype, usefulFields } = this.state
 
     const formItemLayout = {
       labelCol: {
@@ -181,11 +199,11 @@
                     message: dict['form.required.input'] + '琛ㄥ悕!'
                   },
                   {
-                    max: formRule.input.max,
-                    message: formRule.input.message
+                    max: 50,
+                    message: '琛ㄥ悕鏈�闀夸负50涓瓧绗�!'
                   }
                 ]
-              })(<Input placeholder="" autoComplete="off" />)}
+              })(<Input placeholder="" autoComplete="off" onPressEnter={this.handleSubmit} />)}
             </Form.Item>
           </Col>
           <Col span={12}>
@@ -197,6 +215,7 @@
                   <Select.Option value="1">1鍒�</Select.Option>
                   <Select.Option value="2">2鍒�</Select.Option>
                   <Select.Option value="3">3鍒�</Select.Option>
+                  <Select.Option value="4">4鍒�</Select.Option>
                 </Select>
               )}
             </Form.Item>
@@ -213,30 +232,21 @@
               )}
             </Form.Item>
           </Col>
-          {datatype === 'query' ? <Col span={12}>
+          <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>
-              )}
+                initialValue: setting.primaryKey
+              })(<Input placeholder="" autoComplete="off" disabled/>)}
             </Form.Item>
-          </Col> : null}
+          </Col>
           {datatype === 'query' ? <Col span={12}>
             <Form.Item label={dict['header.form.intertype']}>
               {getFieldDecorator('interType', {
                 initialValue: interType
               })(
                 <Radio.Group onChange={this.onChange}>
-                  <Radio value="inner">{dict['header.form.interface.inner']}</Radio>
-                  <Radio value="outer">{dict['header.form.interface.outer']}</Radio>
+                  <Radio value="inner">{dict['model.interface.inner']}</Radio>
+                  <Radio value="outer">{dict['model.interface.outer']}</Radio>
                 </Radio.Group>
               )}
             </Form.Item>
@@ -247,8 +257,8 @@
                 initialValue: setting.sysInterface || 'false'
               })(
                 <Radio.Group onChange={this.onSysChange}>
-                  <Radio value="true">{dict['header.form.true']}</Radio>
-                  <Radio value="false">{dict['header.form.false']}</Radio>
+                  <Radio value="true">{dict['model.true']}</Radio>
+                  <Radio value="false">{dict['model.false']}</Radio>
                 </Radio.Group>
               )}
             </Form.Item>
@@ -256,7 +266,7 @@
           {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 || ''),
+                initialValue: setting.sysInterface === 'true' ? (window.GLOB.mainSystemApi || '') : (setting.interface || ''),
                 rules: [
                   {
                     required: true,
@@ -267,13 +277,13 @@
                     message: formRule.input.message
                   }
                 ]
-              })(<Input placeholder="" autoComplete="off" disabled={this.state.interReadonly} />)}
+              })(<Input placeholder="" autoComplete="off" disabled={this.state.interReadonly} onPressEnter={this.handleSubmit} />)}
             </Form.Item>
           </Col> : null}
           {datatype === 'query' && interType !== 'outer' ? <Col span={12}>
             <Form.Item label={
               <Tooltip placement="topLeft" overlayClassName="middle" title={`鍙嚜瀹氫箟鏁版嵁澶勭悊鍑芥暟锛屽嚱鏁板悕绉伴渶浠�${usefulFields.join(', ')}绛夊瓧绗﹀紑濮嬶紱鏈缃椂浼氳皟鐢ㄧ郴缁熷嚱鏁帮紝浣跨敤绯荤粺鍑芥暟闇�瀹屽杽鏁版嵁婧愩�俙}>
-                <Icon type="question-circle" />
+                <QuestionCircleOutlined className="mk-form-tip" />
                 {dict['header.form.innerFunc']}
               </Tooltip>
             }>
@@ -288,13 +298,13 @@
                     message: formRule.func.maxMessage
                   }
                 ]
-              })(<Input placeholder="" autoComplete="off" />)}
+              })(<Input placeholder="" autoComplete="off" onPressEnter={this.handleSubmit} />)}
             </Form.Item>
           </Col> : null}
           {datatype === 'query' && interType !== 'outer' ? <Col span={24}>
             <Form.Item help={'鏁版嵁ID锛�' + menu.MenuID} label={
               <Tooltip placement="topLeft" title="浣跨敤绯荤粺鍑芥暟鏃讹紝闇�濉啓鏁版嵁婧愶紝鑷畾涔夊嚱鏁版椂锛屽彲蹇界暐銆�">
-                <Icon type="question-circle" />
+                <QuestionCircleOutlined className="mk-form-tip" />
                 {'鏁版嵁婧�'}
               </Tooltip>
             } className="textarea">
@@ -316,9 +326,28 @@
                     message: formRule.func.maxMessage
                   }
                 ]
-              })(<Input placeholder="" autoComplete="off" />)}
+              })(<Input placeholder="" autoComplete="off" onPressEnter={this.handleSubmit} />)}
             </Form.Item>
           </Col> : null}
+          <Col span={12}>
+            <Form.Item label="瀹藉害">
+              {getFieldDecorator('width', {
+                initialValue: setting.width || 100
+              })(<InputNumber min={10} max={100} precision={0} />)}
+            </Form.Item>
+          </Col>
+          <Col span={12}>
+            <Form.Item label="鍒濆鍖�">
+              {getFieldDecorator('onload', {
+                initialValue: setting.onload || 'true'
+              })(
+                <Select>
+                  <Select.Option value="true">鍔犺浇鏁版嵁</Select.Option>
+                  <Select.Option value="false">涓嶅姞杞芥暟鎹�</Select.Option>
+                </Select>
+              )}
+            </Form.Item>
+          </Col>
         </Row>
       </Form>
     )

--
Gitblit v1.8.0