From 2a347c8d91d6962f4302f0553c55a3b9f743baa5 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期三, 09 九月 2020 21:15:58 +0800
Subject: [PATCH] 2020-09-09

---
 src/templates/sharecomponent/treesettingcomponent/settingform/index.jsx |  800 +++++++++++---------------------------------------------
 1 files changed, 161 insertions(+), 639 deletions(-)

diff --git a/src/templates/sharecomponent/treesettingcomponent/settingform/index.jsx b/src/templates/sharecomponent/treesettingcomponent/settingform/index.jsx
index a0da051..e71602e 100644
--- a/src/templates/sharecomponent/treesettingcomponent/settingform/index.jsx
+++ b/src/templates/sharecomponent/treesettingcomponent/settingform/index.jsx
@@ -1,289 +1,131 @@
 import React, {Component} from 'react'
 import PropTypes from 'prop-types'
 import { fromJS } from 'immutable'
-import { Form, Row, Col, Input, Radio, Select, Tooltip, Icon, notification, InputNumber, Modal, Table, Popconfirm, Typography, Button } from 'antd'
+import { Form, notification, Modal, Spin, Tabs } from 'antd'
 import moment from 'moment'
 
 import Api from '@/api'
 import Utils from '@/utils/utils.js'
 import SettingUtils from './utils.jsx'
-import CustomScript from './customscript'
-import CodeMirror from '@/templates/zshare/codemirror'
+import DataSource from './datasource'
+import CustomScript from '@/templates/zshare/customscript'
 import './index.scss'
 
-const { confirm } = Modal
-const { Paragraph } = Typography
+const { TabPane } = Tabs
 
 class SettingForm extends Component {
   static propTpyes = {
-    type: PropTypes.string,      // 鑿滃崟绫诲瀷
-    dict: PropTypes.object,      // 瀛楀吀椤�
-    menu: PropTypes.object,      // 鑿滃崟淇℃伅
-    config: PropTypes.object,    // 椤甸潰閰嶇疆淇℃伅
-    formlist: PropTypes.array,   // 琛ㄥ崟淇℃伅
-    inputSubmit: PropTypes.any   // 鍥炶溅鎻愪氦浜嬩欢
+    dict: PropTypes.object,         // 瀛楀吀椤�
+    menu: PropTypes.object,         // 鑿滃崟淇℃伅
+    config: PropTypes.object,       // 椤甸潰閰嶇疆淇℃伅
+    permFuncField: PropTypes.array, // 瀛樺偍杩囩▼鍙敤瀛楁
+    inputSubmit: PropTypes.any      // 鍥炶溅鎻愪氦浜嬩欢
   }
 
   state = {
-    formlist: [],
-    btnloading: false,
+    loading: false,
     setting: null,
-    view: 'normal',
-    systemScripts: [{
-      name: '榛樿sql',
-      value: ''
-    }],
-    scriptsColumns: [
-      {
-        title: 'SQL',
-        dataIndex: 'sql',
-        width: '70%',
-        render: (text) => (
-          <Paragraph copyable ellipsis={{ rows: 5, expandable: true }}>{text}</Paragraph>
-        )
-      },
-      {
-        title: '鐘舵��',
-        dataIndex: 'status',
-        width: '10%',
-        render: (text, record) => record.status === 'false' ?
-          (
-            <div>
-              {this.props.dict['model.status.forbidden']}
-              <Icon style={{marginLeft: '5px'}} type="stop" theme="twoTone" twoToneColor="#ff4d4f" />
-            </div>
-          ) :
-          (
-            <div>
-              {this.props.dict['model.status.open']}
-              <Icon style={{marginLeft: '5px'}} type="check-circle" theme="twoTone" twoToneColor="#52c41a" />
-            </div>
-          )
-      },
-      {
-        title: '鎿嶄綔',
-        align: 'center',
-        width: '20%',
-        dataIndex: 'operation',
-        render: (text, record) =>
-          (<div>
-            <span className="operation-btn" title={this.props.dict['model.edit']} onClick={() => this.handleEdit(record)} style={{color: '#1890ff'}}><Icon type="edit" /></span>
-            <span className="operation-btn" title={this.props.dict['header.form.up']} onClick={() => this.handleUpDown(record, 'up')} style={{color: '#1890ff'}}><Icon type="arrow-up" /></span>
-            <span className="operation-btn" title={this.props.dict['header.form.down']} onClick={() => this.handleUpDown(record, 'down')} style={{color: '#ff4d4f'}}><Icon type="arrow-down" /></span>
-            <span className="operation-btn" title={this.props.dict['header.form.status.change']} onClick={() => this.handleStatus(record)} style={{color: '#8E44AD'}}><Icon type="swap" /></span>
-            <Popconfirm
-              overlayClassName="popover-confirm"
-              title={this.props.dict['model.query.delete']}
-              onConfirm={() => this.handleDelete(record)
-            }>
-              <span className="operation-btn" style={{color: '#ff4d4f'}}><Icon type="delete" /></span>
-            </Popconfirm>
-          </div>)
-      }
-    ]
+    defaultsql: '',
+    activeKey: 'setting',
   }
 
   UNSAFE_componentWillMount() {
-    let _formlist = fromJS(this.props.formlist).toJS()
-    let interType = 'inner'
+    const { config } = this.props
 
-    _formlist.forEach(item => {
-      if (item.key === 'interType') {
-        interType = item.initVal
-      }
-    })
-
-    let _setting = fromJS(this.props.config.setting).toJS()
-    _setting.scripts = _setting.scripts || []
-    _setting.default = _setting.default || 'true'
+    let _setting = fromJS(config.setting).toJS()
+    let _scripts = _setting.scripts || []
 
     this.setState({
       setting: _setting,
-      formlist: _formlist.map(item => {
-        if (interType === 'inner' && ['sysInterface', 'interface', 'outerFunc'].includes(item.key)) {
-          item.hidden = true
-        } else if (interType === 'outer' && ['innerFunc', 'dataresource', 'queryType'].includes(item.key)) {
-          item.hidden = true
-        }
-
-        return item
-      })
+      scripts: _scripts
     })
   }
 
-  componentDidMount () {
-    this.getsysScript()
-  }
 
-  getsysScript = () => {
-    let _scriptSql = `Select distinct func+Remark as funcname,longparam, s.Sort from聽 s_custom_script s inner join (select OpenID from sapp where ID=@Appkey@) p on s.openid = case when s.appkey='' then s.openid else p.OpenID end order by s.Sort`
-
-    _scriptSql = Utils.formatOptions(_scriptSql)
-
-    let _sParam = {
-      func: 'sPC_Get_SelectedList',
-      LText: _scriptSql,
-      obj_name: 'data',
-      arr_field: 'funcname,longparam'
-    }
+  handleConfirm = () => {
+    const { activeKey, setting, scripts } = this.state
     
-    _sParam.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000'
-    _sParam.secretkey = Utils.encrypt(_sParam.LText, _sParam.timestamp)
-    _sParam.open_key = Utils.encryptOpenKey(_sParam.secretkey, _sParam.timestamp) // 浜戠鏁版嵁楠岃瘉
-    
-    Api.getSystemConfig(_sParam).then(res => {
-      if (res.status) {
-        let _scripts = res.data.map(item => {
-          let _item = {
-            name: item.funcname,
-            value: Utils.UnformatOptions(item.longparam)
-          }
+    let _scripts = scripts.filter(script => script.status !== 'false')
 
-          return _item
-        })
-
-        this.setState({
-          systemScripts: [...this.state.systemScripts, ..._scripts]
-        })
-      } else {
-        notification.warning({
-          top: 92,
-          message: res.message,
-          duration: 5
-        })
-      }
-    })
-  }
-
-  handleConfirm = (otype) => {
-    const { menu } = this.props
-    const { view, setting } = this.state
-    // 琛ㄥ崟鎻愪氦鏃舵鏌ヨ緭鍏ュ�兼槸鍚︽纭�
-
-    if (view !== 'custom') {
+    if (activeKey === 'setting') {
       return new Promise((resolve, reject) => {
-        this.props.form.validateFieldsAndScroll((err, values) => {
-          if (!err) {
-            values = {...setting, ...values}
-
-            // 鏁版嵁婧愬墠绔獙璇�
-            if (values.interType === 'inner' && !values.innerFunc && values.default !== 'false' && !values.dataresource) {
-              notification.warning({
-                top: 92,
-                message: '璇峰~鍐欏唴閮ㄥ嚱鏁版垨鏁版嵁婧愶紒',
-                duration: 5
-              })
-              reject()
-              return
-            } else if (values.interType === 'inner' && !values.innerFunc && values.default !== 'false' && values.dataresource) {
-              let error = Utils.verifySql(values.dataresource)
-  
-              if (error) {
-                notification.warning({
-                  top: 92,
-                  message: '鏁版嵁婧愪腑涓嶅彲浣跨敤' + error,
-                  duration: 5
-                })
-                reject()
-                return
-              }
-            }
-
-            // 鏁版嵁婧愪繚瀛�
-            if (
-              values.interType === 'inner' && !values.innerFunc &&
-              values.default !== 'false' &&
-              /[^\s]+\s+[^\s]+/ig.test(values.dataresource) &&
-              this.props.config.setting.dataresource !== values.dataresource
-            ) {
-              let param = {
-                func: 's_DataSrc_Save',
-                LText: values.dataresource,
-                MenuID: menu.MenuID
-              }
-      
-              param.LText = Utils.formatOptions(param.LText)
-              param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000'
-              param.secretkey = Utils.encrypt(param.LText, param.timestamp)
-      
-              Api.getLocalConfig(param)
-            }
-
-            if (otype === 'change') {
-              this.setState({
-                setting: values,
-              }, () => {
-                resolve()
-              })
-            } else {
-              values.customScript = this.getCustomScript(values)
-
-              this.sqlverify(values, resolve, reject)
-            }
-          } else {
-            reject(err)
+        this.settingForm.handleConfirm().then(res => {
+          if (res.interType === 'system' && res.default === 'false' && _scripts.length === 0) {
+            notification.warning({
+              top: 92,
+              message: '涓嶆墽琛岄粯璁ql鏃讹紝璇锋坊鍔犺嚜瀹氫箟鑴氭湰锛�',
+              duration: 5
+            })
+            reject()
+            return
           }
+
+          this.setState({
+            setting: res
+          }, () => {
+            this.sqlverify(() => { resolve({...res, scripts}) }, reject, 'submit')
+          })
+        }, () => {
+          reject()
         })
       })
     } else {
-      let _setting = fromJS(this.state.setting).toJS()
-      _setting.customScript = this.getCustomScript(_setting)
-
-      let _this = this
-
       return new Promise((resolve, reject) => {
-        if (this.scriptsForm && this.scriptsForm.props.form.getFieldValue('sql')) {
-          confirm({
-            content: `瀛樺湪鏈繚瀛橀」锛岀‘瀹氭彁浜ゅ悧锛焋,
-            onOk() {
-              _this.sqlverify(_setting, resolve, reject)
-            },
-            onCancel() {
-              reject()
-            }
+        let _loading = false
+        if (this.scriptsForm && this.scriptsForm.state.editItem) {
+          _loading = true
+        } else if (this.scriptsForm && this.scriptsForm.props.form.getFieldValue('sql')) {
+          _loading = true
+        }
+  
+        if (_loading) {
+          notification.warning({
+            top: 92,
+            message: '瀛樺湪鏈繚瀛樿剼鏈紝璇风偣鍑荤‘瀹氫繚瀛橈紝鎴栫偣鍑诲彇娑堟斁寮冧慨鏀癸紒',
+            duration: 5
           })
+          reject()
+        } else if (setting.interType === 'system' && setting.default === 'false' && _scripts.length === 0) {
+          notification.warning({
+            top: 92,
+            message: '涓嶆墽琛岄粯璁ql鏃讹紝璇锋坊鍔犺嚜瀹氫箟鑴氭湰锛�',
+            duration: 5
+          })
+          reject()
         } else {
-          this.sqlverify(_setting, resolve, reject)
+          this.sqlverify(() => {
+            resolve({...setting, scripts})
+          }, () => {
+            reject()
+          }, 'submit')
         }
       })
     }
   }
 
-  getCustomScript = (setting) => {
-    let _customScript = ''
-    if (setting.scripts && setting.scripts.length > 0) {
-      setting.scripts.forEach(item => {
-        if (item.status === 'false') return
-        _customScript += `
-          ${item.sql}
-        `
-      })
-    }
+  sqlverify = (_resolve, _reject, type, uscripts) => {
+    const { setting, scripts } = this.state
 
-    if (_customScript) {
-      _customScript = `declare @ErrorCode nvarchar(50),@retmsg nvarchar(4000) select @ErrorCode='',@retmsg =''
-        ${_customScript}
-      `
-    }
-
-    return _customScript
-  }
-
-  sqlverify = (_setting, _resolve, _reject, isChange = false) => {
-    if (!isChange && _setting.interType === 'inner' && !_setting.innerFunc && _setting.default === 'false' && !_setting.customScript) {
-      notification.warning({
-        top: 92,
-        message: '涓嶆墽琛岄粯璁ql鏃讹紝璇锋坊鍔犺嚜瀹氫箟鑴氭湰锛�',
-        duration: 5
-      })
-      _reject()
+    if (setting.interType !== 'system') { // 涓嶄娇鐢ㄧ郴缁熸帴鍙f椂锛屼笉闇�瑕乻ql楠岃瘉
+      _resolve()
       return
     }
 
-    if (_setting.interType === 'inner' && !_setting.innerFunc && _setting.default !== 'false') {
+    let _scripts = []
+    if (uscripts) { // 杩囨护绂佺敤鐨勮剼鏈�
+      _scripts = uscripts.filter(script => script.status !== 'false')
+    } else {
+      _scripts = scripts.filter(script => script.status !== 'false')
+    }
+
+    if (type === 'setting' && setting.default === 'false') {
+      _resolve()
+    } else if (type === 'scripts' && _scripts.length === 0) {
+      _resolve()
+    } else { // type 涓� submit 銆� verify 锛屼互鍙婂叾浠栭渶瑕侀獙璇佺殑鍦烘櫙
       let param = {
         func: 's_debug_sql',
-        LText: SettingUtils.getDebugSql(_setting)
+        LText: SettingUtils.getDebugSql(setting, _scripts)
       }
       param.LText = Utils.formatOptions(param.LText)
       param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000'
@@ -291,7 +133,7 @@
       
       Api.getLocalConfig(param).then(result => {
         if (result.status) {
-          _resolve(_setting)
+          _resolve()
         } else {
           _reject()
           Modal.error({
@@ -299,444 +141,124 @@
           })
         }
       })
-    } else {
-      _resolve(_setting)
     }
   }
 
-  selectChange = (key, val) => {
-    if (key === 'primaryKey' && val) {
-      this.props.form.setFieldsValue({
-        order: `${val} desc`
-      })
-    }
-  }
+  changeTab = (val) => {
+    const { activeKey } = this.state
 
-  onRadioChange = (e, key) => {
-    let value = e.target.value
-    let _formlist = fromJS(this.state.formlist).toJS()
-
-    if (key === 'interType') {
-      this.setState({
-        formlist: _formlist.map(item => {
-          item.hidden = false
-
-          if (value === 'inner' && ['sysInterface', 'interface', 'outerFunc'].includes(item.key)) {
-            item.initVal = this.props.form.getFieldValue(item.key)
-            item.hidden = true
-          } else if (value === 'outer' && ['innerFunc', 'dataresource', 'queryType'].includes(item.key)) {
-            item.initVal = this.props.form.getFieldValue(item.key)
-            item.hidden = true
-          }
-          
-          return item
-        })
-      })
-    } else if (key === 'sysInterface') {
-      if (value === 'true') {
-        this.props.form.setFieldsValue({
-          interface: window.GLOB.mainSystemApi || ''
-        })
-      }
-      this.setState({
-        formlist: _formlist.map(item => {
-          if (item.key === 'interface') {
-            item.readonly = value === 'true'
-          }
-          
-          return item
-        })
-      })
-    }
-  }
-
-  changeView = () => {
-    const { view } = this.state
-    let _this = this
-
-    if (view === 'normal') {
-      this.handleConfirm('change').then(() => {
-        const { setting } = this.state
-
-        if (setting.interType !== 'inner' || (setting.interType === 'inner' && setting.innerFunc)) {
+    if (activeKey === 'setting') {
+      this.settingForm.handleConfirm().then(res => {
+        if (res.interType !== 'system') {
           notification.warning({
             top: 92,
-            message: '浣跨敤澶栭儴鎺ュ彛鎴栧唴閮ㄦ帴鍙g殑鑷畾涔夊嚱鏁帮紝涓嶅彲娣诲姞鑷畾涔夎缃紒',
+            message: '浣跨敤绯荤粺鎺ュ彛鏃讹紝鎵嶅彲浠ヨ缃嚜瀹氫箟鑴氭湰锛�',
             duration: 5
           })
           return
         }
 
-        let _dataresource = setting.dataresource
+        let _defaultSql = ''
+        if (res.dataresource) {
+          let _dataresource = res.dataresource
+          let arr_field = `${res.valueField},${res.labelField},${res.parentField}`
 
-        if (/\s/.test(_dataresource)) {
-          _dataresource = '(' + _dataresource + ') tb'
+          if (/\s/.test(_dataresource)) {
+            _dataresource = '(' + _dataresource + ') tb'
+          }
+
+          _defaultSql = ` select ${arr_field} from (select ${arr_field} ,ROW_NUMBER() over(order by ${res.order}) as rows from ${_dataresource}) tmptable order by tmptable.rows `
         }
-
-        let arr_field = `${setting.valueField}, ${setting.labelField}, ${setting.parentField}`
-
-        let LText = `select ${arr_field} from (select ${arr_field} ,ROW_NUMBER() over(order by @orderBy@) as rows from ${_dataresource}) tmptable order by tmptable.rows`
-        let _scripts = fromJS(this.state.systemScripts).toJS()
-        _scripts[0].value = LText
-
-
-        if (setting.default === 'false') {
-          this.setState({
-            view: 'custom',
-            btnloading: false,
-            systemScripts: _scripts
-          })
-          this.scrolltop()
-        } else {
-          this.setState({
-            btnloading: true
-          })
-          new Promise((resolve, reject) => {
-            this.sqlverify(setting, resolve, reject, true)
-          }).then(() => {
+        this.setState({
+          setting: res,
+          defaultsql: _defaultSql
+        }, () => {
+          this.setState({loading: true})
+          this.sqlverify(() => { // 楠岃瘉鎴愬姛
             this.setState({
-              view: 'custom',
-              btnloading: false,
-              systemScripts: _scripts
+              activeKey: val,
+              loading: false
             })
-            this.scrolltop()
-          }, () => {
+          }, () => {             // 楠岃瘉澶辫触
             this.setState({
-              btnloading: false
+              loading: false
             })
-          })
-        }
+          }, activeKey)
+        })
       })
     } else {
       let _loading = false
-
-      if (this.scriptsForm && this.scriptsForm.props.form.getFieldValue('sql')) {
+      if (this.scriptsForm && this.scriptsForm.state.editItem) {
+        _loading = true
+      } else if (this.scriptsForm && this.scriptsForm.props.form.getFieldValue('sql')) {
         _loading = true
       }
 
       if (_loading) {
-        confirm({
-          content: `瀛樺湪鏈繚瀛橀」锛岀‘瀹氬垏鎹㈠悧锛焋,
-          onOk() {
-            _this.setState({
-              view: 'normal'
-            })
-    
-            _this.scrolltop()
-          },
-          onCancel() {}
+        notification.warning({
+          top: 92,
+          message: '瀛樺湪鏈繚瀛樿剼鏈紝璇风偣鍑荤‘瀹氫繚瀛橈紝鎴栫偣鍑诲彇娑堟斁寮冧慨鏀癸紒',
+          duration: 5
         })
-      } else {
-        _this.setState({
-          view: 'normal'
+        return
+      }
+      this.setState({loading: true})
+      this.sqlverify(() => { // 楠岃瘉鎴愬姛
+        this.setState({
+          activeKey: val,
+          loading: false
         })
-
-        _this.scrolltop()
-      }
+      }, () => {             // 楠岃瘉澶辫触
+        this.setState({
+          loading: false
+        })
+      }, activeKey)
     }
   }
 
-  handleSubmit = (e) => {
-    e.preventDefault()
-
-    if (this.props.inputSubmit) {
-      this.props.inputSubmit()
-    }
-  }
-
-  getFields(formlist) {
-    const { getFieldDecorator } = this.props.form
-    const fields = []
-
-    formlist.forEach((item, index) => {
-      if (item.hidden || item.forbid) return
-
-      if (item.type === 'text') { // 鏂囨湰鎼滅储
-        let rules = item.rules || []
-        
-        fields.push(
-          <Col span={12} key={index}>
-            <Form.Item label={item.tooltip ?
-              <Tooltip placement={item.placement || 'topLeft'} title={item.tooltip}>
-                <Icon type="question-circle" />
-                {item.label}
-              </Tooltip> : item.label
-            }>
-              {getFieldDecorator(item.key, {
-                initialValue: item.initVal || '',
-                rules: [
-                  {
-                    required: !!item.required,
-                    message: this.props.dict['form.required.input'] + item.label + '!'
-                  },
-                  ...rules
-                ]
-              })(<Input placeholder={item.placeholder || ''} autoComplete="off" disabled={item.readonly} onPressEnter={this.handleSubmit} />)}
-            </Form.Item>
-          </Col>
-        )
-      } else if (item.type === 'number') {
-        fields.push(
-          <Col span={12} key={index}>
-            <Form.Item label={item.tooltip ?
-              <Tooltip placement="topLeft" title={item.tooltip}>
-                <Icon type="question-circle" />
-                {item.label}
-              </Tooltip> : item.label
-            }>
-              {getFieldDecorator(item.key, {
-                initialValue: item.initVal || 6,
-                rules: [
-                  {
-                    required: item.required,
-                    message: this.props.dict['form.required.input'] + item.label + '!'
-                  }
-                ]
-              })(<InputNumber min={item.min} max={item.max} precision={0} />)}
-            </Form.Item>
-          </Col>
-        )
-      } else if (item.type === 'select') { // 涓嬫媺鎼滅储
-        fields.push(
-          <Col span={12} key={index}>
-            <Form.Item label={item.label}>
-              {getFieldDecorator(item.key, {
-                initialValue: item.initVal || '',
-                rules: [
-                  {
-                    required: !!item.required,
-                    message: this.props.dict['form.required.select'] + item.label + '!'
-                  }
-                ]
-              })(
-                <Select
-                  showSearch
-                  filterOption={(input, option) => {
-                    return option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0 ||
-                      option.props.value.toLowerCase().indexOf(input.toLowerCase()) >= 0
-                  }}
-                  onChange={(value) => {this.selectChange(item.key, value)}}
-                  getPopupContainer={() => document.getElementById('model-table-setting-form')}
-                >
-                  {item.options.map((option, i) =>
-                    <Select.Option id={i} key={i} value={option.value}>
-                      {option.text}
-                    </Select.Option>
-                  )}
-                </Select>
-              )}
-            </Form.Item>
-          </Col>
-        )
-      } else if (item.type === 'radio') {
-        fields.push(
-          <Col span={12} key={index}>
-            <Form.Item label={item.tooltip ?
-              <Tooltip placement="topLeft" title={item.tooltip}>
-                <Icon type="question-circle" />
-                {item.label}
-              </Tooltip> : item.label
-            }>
-              {getFieldDecorator(item.key, {
-                initialValue: item.initVal,
-                rules: [
-                  {
-                    required: !!item.required,
-                    message: this.props.dict['form.required.select'] + item.label + '!'
-                  }
-                ]
-              })(
-                <Radio.Group onChange={(e) => {this.onRadioChange(e, item.key)}}>
-                  {
-                    item.options.map((option, i) => {
-                      return (
-                        <Radio key={i} value={option.value}>{option.text}</Radio>
-                      )
-                    })
-                  }
-                </Radio.Group>,
-              )}
-            </Form.Item>
-          </Col>
-        )
-      } else if (item.type === 'datasource') {
-        fields.push(
-          <Col span={24} key={index} style={{paddingLeft: '7px'}}>
-            <Form.Item className="text-area" labelCol={{xs: { span: 24 }, sm: { span: 4 }}} wrapperCol={ {xs: { span: 24 }, sm: { span: 20 }} } help={item.help} label={
-              <Tooltip placement="topLeft" title={item.tooltip}>
-                <Icon type="question-circle" />
-                {item.label}
-              </Tooltip>
-            }>
-              {getFieldDecorator(item.key, {
-                initialValue: item.initVal
-              })(<CodeMirror />)}
-            </Form.Item>
-          </Col>
-        )
-      } else if (item.type === 'multiselect') { // 澶氶��
-        fields.push(
-          <Col span={12} key={index}>
-            <Form.Item label={item.label}>
-              {getFieldDecorator(item.key, {
-                initialValue: item.initVal || []
-              })(
-                <Select
-                  showSearch
-                  mode="multiple"
-                  filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0}
-                >
-                  {item.options.map((option, i) =>
-                    <Select.Option id={i} key={i} value={option.value}>{option.text}</Select.Option>
-                  )}
-                </Select>
-              )}
-            </Form.Item>
-          </Col>
-        )
-      }
-    })
-
-    return fields
-  }
-
-  handleEdit = (record) => {
-    this.scriptsForm.edit(record)
-
-    this.scrolltop()
-  }
-
-  scrolltop = () => {
-    let node = document.getElementById('model-tree-setting-form-box').parentNode
-
-    if (node && node.scrollTop) {
-      let inter = Math.ceil(node.scrollTop / 10)
-
-      let timer = setInterval(() => {
-        if (node.scrollTop - inter > 0) {
-          node.scrollTop = node.scrollTop - inter
-        } else {
-          node.scrollTop = 0
-          clearInterval(timer)
-        }
-      }, 10)
-    }
-  }
-
-  handleUpDown = (record, direction) => {
-    let scripts = fromJS(this.state.setting.scripts).toJS()
-    let index = 0
-
-    scripts = scripts.filter((item, i) => {
-      if (item.uuid === record.uuid) {
-        index = i
-      }
-
-      return item.uuid !== record.uuid
-    })
-    if ((index === 0 && direction === 'up') || (index === scripts.length && direction === 'down')) {
-      return
-    }
-
-    if (direction === 'up') {
-      scripts.splice(index - 1, 0, record)
-    } else {
-      scripts.splice(index + 1, 0, record)
-    }
-
-    this.setState({
-      setting: {...this.state.setting, scripts: scripts}
+  // 鑷畾涔夎剼鏈慨鏀�
+  scriptsChange = (scripts) => {
+    return new Promise((resolve, reject) => {
+      this.sqlverify(resolve, reject, 'verify', scripts)
     })
   }
 
-  handleStatus = (record) => {
-    let scripts = fromJS(this.state.setting.scripts).toJS()
-    record.status = record.status === 'false' ? 'true' : 'false'
-
-    scripts = scripts.map(item => {
-      if (item.uuid === record.uuid) {
-        return record
-      } else {
-        return item
-      }
-    })
-
-    this.setState({
-      setting: {...this.state.setting, scripts: scripts}
-    })
-  }
-
-  handleDelete = (record) => {
-    let scripts = fromJS(this.state.setting.scripts).toJS()
-    scripts = scripts.filter(item => item.uuid !== record.uuid)
-
-    this.setState({ setting: {...this.state.setting, scripts: scripts} })
-  }
-
-  scriptsChange = (values) => {
-    let scripts = fromJS(this.state.setting.scripts).toJS()
-
-    if (values.uuid) {
-      scripts = scripts.map(item => {
-        if (item.uuid === values.uuid) {
-          return values
-        } else {
-          return item
-        }
-      })
-    } else {
-      values.uuid = Utils.getuuid()
-      scripts.push(values)
-    }
-
-    this.setState({
-      setting: {...this.state.setting, scripts: scripts}
-    })
+  // 鑷畾涔夎剼鏈洿鏂�
+  scriptsUpdate = (scripts) => {
+    this.setState({scripts})
   }
 
   render() {
-    const { config, type } = this.props
-    const { formlist, view, setting, scriptsColumns, systemScripts, btnloading } = this.state
-    const formItemLayout = {
-      labelCol: {
-        xs: { span: 24 },
-        sm: { span: 8 }
-      },
-      wrapperCol: {
-        xs: { span: 24 },
-        sm: { span: 16 }
-      }
-    }
+    const { menu } = this.props
+    const { activeKey, setting, loading, scripts } = this.state
 
     return (
-      <div className="model-tree-setting-form-box" id="model-tree-setting-form-box">
-        {view ==='custom' ? <div>
-          <Icon className="setting-custom-back" onClick={this.changeView} type="arrow-left" />
-          <CustomScript
-            type={type}
-            setting={setting}
-            dict={this.props.dict}
-            searches={config.search}
-            systemScripts={systemScripts}
-            scriptsChange={this.scriptsChange}
-            wrappedComponentRef={(inst) => this.scriptsForm = inst}
-          />
-          <Table
-            bordered
-            rowKey="uuid"
-            className="custom-table"
-            dataSource={setting.scripts}
-            columns={scriptsColumns}
-            pagination={false}
-          />
-        </div> : null }
-        <Form {...formItemLayout} className="model-tree-setting-form" id="model-table-setting-form">
-          {view !=='custom' ? <Row gutter={24}>{this.getFields(formlist)}</Row> : null}
-          <Row gutter={24}>
-            {view !=='custom' ? <Button onClick={this.changeView} className="to-custom-script" loading={btnloading}>鑷畾涔夎缃�<Icon style={{marginLeft: 5}} type="right" /></Button> : null}
-            {view ==='custom' ? <span onClick={this.changeView} style={{float: 'left', color: '#1890ff', marginLeft: 12, marginTop: 15, cursor: 'pointer'}}><Icon style={{marginRight: 5}} type="left" />鍩虹璁剧疆</span> : null}
-          </Row>
-        </Form>
+      <div className="model-tree-setting-form-box" id="model-setting-form-body">
+        {loading && <Spin size="large" />}
+        <Tabs activeKey={activeKey} className="verify-card-box" onChange={this.changeTab}>
+          <TabPane tab="鏁版嵁婧�" key="setting">
+            <DataSource
+              menu={menu}
+              dict={this.props.dict}
+              setting={setting}
+              permFuncField={this.props.permFuncField}
+              inputSubmit={this.props.inputSubmit}
+              wrappedComponentRef={(inst) => this.settingForm = inst}
+            />
+          </TabPane>
+          <TabPane tab="鑷畾涔夎剼鏈�" key="scripts">
+            <CustomScript
+              dict={this.props.dict}
+              setting={setting}
+              scripts={scripts}
+              defaultSql={this.state.defaultsql}
+              searches={[]}
+              scriptsChange={this.scriptsChange}
+              scriptsUpdate={this.scriptsUpdate}
+              wrappedComponentRef={(inst) => this.scriptsForm = inst}
+            />
+          </TabPane>
+        </Tabs>
       </div>
     )
   }

--
Gitblit v1.8.0