From d36c27e80e668b3bc1dcd687a18a2f2d125b32db Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期日, 24 一月 2021 02:15:12 +0800
Subject: [PATCH] 2021-01-24

---
 src/templates/sharecomponent/settingcomponent/settingform/index.jsx |  123 +++++++++++++++++++++++++++++-----------
 1 files changed, 88 insertions(+), 35 deletions(-)

diff --git a/src/templates/sharecomponent/settingcomponent/settingform/index.jsx b/src/templates/sharecomponent/settingcomponent/settingform/index.jsx
index f7a193e..b5c4ffe 100644
--- a/src/templates/sharecomponent/settingcomponent/settingform/index.jsx
+++ b/src/templates/sharecomponent/settingcomponent/settingform/index.jsx
@@ -7,11 +7,13 @@
 import Api from '@/api'
 import Utils from '@/utils/utils.js'
 import SettingUtils from './utils.jsx'
-import CustomScript from '@/templates/zshare/customscript'
+import asyncComponent from '@/utils/asyncComponent'
 import DataSource from './datasource'
 import './index.scss'
 
 const { TabPane } = Tabs
+const CustomScript = asyncComponent(() => import('@/templates/zshare/customscript'))
+const SimpleScript = asyncComponent(() => import('./simplescript'))
 
 class SettingForm extends Component {
   static propTpyes = {
@@ -37,6 +39,8 @@
 
     let _setting = fromJS(config.setting).toJS()
     let _scripts = _setting.scripts || []
+    let _preScripts = _setting.preScripts || []
+    let _cbScripts = _setting.cbScripts || []
 
     _setting.default = _setting.default || 'true'            // 榛樿sql
     _setting.sysInterface = _setting.sysInterface || 'false' // 鏄惁涓虹郴缁熸帴鍙�
@@ -82,7 +86,9 @@
       arr_field: arr_field.join(','),
       regoptions: Utils.getRegOptions(search), // 鎼滅储鏉′欢锛屾鍒欐浛鎹�
       columns: columns,
-      scripts: _scripts
+      scripts: _scripts,
+      preScripts: _preScripts,
+      cbScripts: _cbScripts
     })
   }
 
@@ -143,6 +149,24 @@
   handleConfirm = (trigger) => {
     const { activeKey, setting, scripts } = this.state
 
+    let _loading = false
+    if (this.scriptsForm && this.scriptsForm.props.form.getFieldValue('sql')) {
+      _loading = true
+    } else if (this.preScriptsForm && this.preScriptsForm.props.form.getFieldValue('sql')) {
+      _loading = true
+    } else if (this.cbScriptsForm && this.cbScriptsForm.props.form.getFieldValue('sql')) {
+      _loading = true
+    }
+
+    if (_loading) {
+      notification.warning({
+        top: 92,
+        message: '瀛樺湪鏈繚瀛樿剼鏈紝璇风偣鍑荤‘瀹氫繚瀛橈紝鎴栫偣鍑诲彇娑堟斁寮冧慨鏀癸紒',
+        duration: 5
+      })
+      return
+    }
+
     if (trigger) {
       this.setState({loading: true})
     }
@@ -199,25 +223,10 @@
       })
     } else {
       return new Promise((resolve, 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 (trigger === 'func' && setting.interType !== 'inner') {
           notification.warning({
             top: 92,
             message: '浣跨敤鍐呴儴鎺ュ彛锛屾墠鍙互鍒涘缓瀛樺偍杩囩▼锛�',
-            duration: 5
-          })
-          this.setState({loading: false})
-          reject()
-        } else if (_loading) {
-          notification.warning({
-            top: 92,
-            message: '瀛樺湪鏈繚瀛樿剼鏈紝璇风偣鍑荤‘瀹氫繚瀛橈紝鎴栫偣鍑诲彇娑堟斁寮冧慨鏀癸紒',
             duration: 5
           })
           this.setState({loading: false})
@@ -289,6 +298,24 @@
   changeTab = (val) => {
     const { activeKey, search, arr_field } = this.state
 
+    let _loading = false
+    if (this.scriptsForm && this.scriptsForm.props.form.getFieldValue('sql')) {
+      _loading = true
+    } else if (this.preScriptsForm && this.preScriptsForm.props.form.getFieldValue('sql')) {
+      _loading = true
+    } else if (this.cbScriptsForm && this.cbScriptsForm.props.form.getFieldValue('sql')) {
+      _loading = true
+    }
+
+    if (_loading) {
+      notification.warning({
+        top: 92,
+        message: '瀛樺湪鏈繚瀛樿剼鏈紝璇风偣鍑荤‘瀹氫繚瀛橈紝鎴栫偣鍑诲彇娑堟斁寮冧慨鏀癸紒',
+        duration: 5
+      })
+      return
+    }
+
     if (activeKey === 'setting') {
       let _defaultSql = ''
       this.settingForm.handleConfirm().then(res => {
@@ -330,22 +357,6 @@
         })
       })
     } else if (activeKey === 'scripts') {
-      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
-        })
-        return
-      }
-    
       this.setState({loading: true})
       this.sqlverify(() => { // 楠岃瘉鎴愬姛
         this.setState({
@@ -372,10 +383,20 @@
   scriptsUpdate = (scripts) => {
     this.setState({scripts})
   }
+  
+  // 鍓嶇疆鑴氭湰鏇存柊
+  preScriptsUpdate = (preScripts) => {
+    this.setState({preScripts})
+  }
+  
+  // 鍚庣疆鑴氭湰鏇存柊
+  cbScriptsUpdate = (cbScripts) => {
+    this.setState({cbScripts})
+  }
 
   render() {
     const { config, menu, dict } = this.props
-    const { loading, activeKey, setting, defaultSql, columns, scripts } = this.state
+    const { loading, activeKey, setting, defaultSql, columns, scripts, preScripts, cbScripts } = this.state
 
     return (
       <div className="model-table-setting-form-box" id="model-setting-form-body">
@@ -404,11 +425,43 @@
               scripts={scripts}
               defaultSql={defaultSql}
               searches={this.props.search}
-              scriptsChange={this.scriptsChange}
               scriptsUpdate={this.scriptsUpdate}
               wrappedComponentRef={(inst) => this.scriptsForm = inst}
             />
           </TabPane>
+          <TabPane tab={
+            <span>
+              鍓嶇疆鑴氭湰
+              {preScripts.length ? <span className="count-tip">{preScripts.length}</span> : null}
+            </span>
+          } key="prescripts">
+            <SimpleScript
+              dict={dict}
+              setting={setting}
+              scripts={preScripts}
+              defaultSql={defaultSql}
+              searches={this.props.search}
+              scriptsChange={this.scriptsChange}
+              scriptsUpdate={this.preScriptsUpdate}
+              wrappedComponentRef={(inst) => this.preScriptsForm = inst}
+            />
+          </TabPane>
+          <TabPane tab={
+            <span>
+              鍥炶皟鑴氭湰
+              {cbScripts.length ? <span className="count-tip">{cbScripts.length}</span> : null}
+            </span>
+          } key="cbscripts">
+            <SimpleScript
+              dict={dict}
+              setting={setting}
+              scripts={cbScripts}
+              searches={this.props.search}
+              scriptsChange={this.scriptsChange}
+              scriptsUpdate={this.scriptsUpdate}
+              wrappedComponentRef={(inst) => this.cbScriptsForm = inst}
+            />
+          </TabPane>
         </Tabs>
       </div>
     )

--
Gitblit v1.8.0