From d59f518f466274b2caeb2e01c10c92deafe7c93b Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期三, 09 二月 2022 11:48:29 +0800
Subject: [PATCH] 2022-02-09

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

diff --git a/src/templates/sharecomponent/settingcomponent/settingform/index.jsx b/src/templates/sharecomponent/settingcomponent/settingform/index.jsx
index 0ee9ff9..2be5f9a 100644
--- a/src/templates/sharecomponent/settingcomponent/settingform/index.jsx
+++ b/src/templates/sharecomponent/settingcomponent/settingform/index.jsx
@@ -85,12 +85,41 @@
     status.requestMode = status.requestMode || 'system'
     status.procMode = status.procMode || 'script'
     status.callbackType = status.callbackType || 'script'
+    let regoptions = Utils.getRegOptions(search)
+
+    if (config.urlFields && config.urlFields.length > 0) {
+      config.urlFields.forEach(field => {
+        regoptions.push({
+          key: field,
+          value: '0',
+          type: 'url'
+        })
+      })
+    }
+
+    if (window.GLOB.funcs && window.GLOB.funcs.length > 0) {
+      window.GLOB.funcs.forEach(m => {
+        let reg = new RegExp(`\\/\\*\\$ex@${m.func_code}-begin\\*\\/[\\s\\S]+\\/\\*@ex\\$-end\\*\\/`, 'ig')
+        _scripts.forEach(item => {
+          item.sql = item.sql.replace(reg, `$ex@${m.func_code}@ex$`)
+        })
+        _preScripts.forEach(item => {
+          item.sql = item.sql.replace(reg, `$ex@${m.func_code}@ex$`)
+        })
+        _cbScripts.forEach(item => {
+          item.sql = item.sql.replace(reg, `$ex@${m.func_code}@ex$`)
+        })
+        if (_setting.dataresource) {
+          _setting.dataresource = _setting.dataresource.replace(reg, `$ex@${m.func_code}@ex$`)
+        }
+      })
+    }
 
     this.setState({
       setting: _setting,
       search: _search,
       arr_field: arr_field.join(','),
-      regoptions: Utils.getRegOptions(search), // 鎼滅储鏉′欢锛屾鍒欐浛鎹�
+      regoptions: regoptions, // 鎼滅储鏉′欢锛屾鍒欐浛鎹�
       columns: columns,
       scripts: _scripts,
       preScripts: _preScripts,
@@ -118,32 +147,26 @@
         value: search.initval,
         required: search.required === 'true'
       }
+      
       if (item.type === 'group') {
-        let copy = fromJS(item).toJS()
-        copy.key = search.datefield
+        item.key = search.datefield
+        item.type = 'daterange'
+        item.match = 'between'
+        item.value = [moment().format('YYYY-MM-DD'), moment().format('YYYY-MM-DD')].join(',')
 
-        item.value = search.initval && search.initval[0] ? search.initval[0] : '@$@'
-        item.match = '='
-        
-        copy.type = 'daterange'
-        copy.match = 'between'
-        copy.value = [moment().format('YYYY-MM-DD'), moment().format('YYYY-MM-DD')]
-
-        if (search.transfer === 'true') {
-          newsearches.push(item)
-        }
-        newsearches.push(copy)
+        newsearches.push(item)
         return
       } else if (item.type === 'date') {
         item.value = moment().format('YYYY-MM-DD')
       } else if (item.type === 'datemonth') {
         item.value = moment().format('YYYY-MM')
       } else if (item.type === 'dateweek') {
-        item.value = [moment().startOf('week').format('YYYY-MM-DD'), moment().endOf('week').format('YYYY-MM-DD')]
+        item.value = moment().format('YYYY-MM-DD')
       } else if (item.type === 'daterange') {
-        item.value = [moment().format('YYYY-MM-DD'), moment().format('YYYY-MM-DD')]
-      } else if (item.type === 'multiselect') {
-        item.value = ['@$@']
+        item.value = [moment().format('YYYY-MM-DD'), moment().format('YYYY-MM-DD')].join(',')
+      } else if (item.type === 'multiselect' || (item.type === 'checkcard' && search.multiple === 'true')) {
+        item.type = 'multi'
+        item.value = '@$@'
       } else {
         item.value = '@$@'
       }
@@ -157,11 +180,11 @@
     const { activeKey, setting, scripts, preScripts, cbScripts } = this.state
 
     let _loading = false
-    if (this.scriptsForm && this.scriptsForm.props.form.getFieldValue('sql')) {
+    if (this.scriptsForm && this.scriptsForm.props.form.getFieldValue('sql') && !/^\s+$/.test(this.scriptsForm.props.form.getFieldValue('sql'))) {
       _loading = true
-    } else if (this.preScriptsForm && this.preScriptsForm.props.form.getFieldValue('sql')) {
+    } else if (this.preScriptsForm && this.preScriptsForm.props.form.getFieldValue('sql') && !/^\s+$/.test(this.preScriptsForm.props.form.getFieldValue('sql'))) {
       _loading = true
-    } else if (this.cbScriptsForm && this.cbScriptsForm.props.form.getFieldValue('sql')) {
+    } else if (this.cbScriptsForm && this.cbScriptsForm.props.form.getFieldValue('sql') && !/^\s+$/.test(this.cbScriptsForm.props.form.getFieldValue('sql'))) {
       _loading = true
     }
 
@@ -171,14 +194,12 @@
         message: '瀛樺湪鏈繚瀛樿剼鏈紝璇风偣鍑荤‘瀹氫繚瀛橈紝鎴栫偣鍑诲彇娑堟斁寮冧慨鏀癸紒',
         duration: 5
       })
-      return
+      return Promise.reject()
     }
 
     if (trigger) {
       this.setState({loading: true})
     }
-
-    let _scripts = scripts.filter(script => script.status !== 'false')
 
     // 琛ㄥ崟鎻愪氦鏃舵鏌ヨ緭鍏ュ�兼槸鍚︽纭�
     if (activeKey === 'setting') {
@@ -200,14 +221,6 @@
               duration: 5
             })
             this.setState({loading: false})
-            reject()
-            return
-          } else if ((res.interType === 'system' || res.requestMode === 'system') && res.default === 'false' && _scripts.length === 0) {
-            notification.warning({
-              top: 92,
-              message: '涓嶆墽琛岄粯璁ql鏃讹紝璇锋坊鍔犺嚜瀹氫箟鑴氭湰锛�',
-              duration: 5
-            })
             reject()
             return
           }
@@ -234,14 +247,6 @@
           notification.warning({
             top: 92,
             message: '浣跨敤鍐呴儴鎺ュ彛锛屾墠鍙互鍒涘缓瀛樺偍杩囩▼锛�',
-            duration: 5
-          })
-          this.setState({loading: false})
-          reject()
-        } else if ((setting.interType === 'system' || setting.requestMode === 'system') && setting.default === 'false' && _scripts.length === 0) {
-          notification.warning({
-            top: 92,
-            message: '涓嶆墽琛岄粯璁ql鏃讹紝璇锋坊鍔犺嚜瀹氫箟鑴氭湰锛�',
             duration: 5
           })
           this.setState({loading: false})
@@ -284,18 +289,44 @@
     } else if (type === 'scripts' && _scripts.length === 0) {
       _resolve()
     } else { // type 涓� submit 銆� verify 锛屼互鍙婂叾浠栭渶瑕侀獙璇佺殑鍦烘櫙
+      let r = SettingUtils.getDebugSql(setting, _scripts, arr_field, regoptions, search)
       let param = {
         func: 's_debug_sql',
         exec_type: 'y',
-        LText: SettingUtils.getDebugSql(setting, _scripts, arr_field, regoptions, search)
+        LText: r.sql
       }
       param.LText = Utils.formatOptions(param.LText)
       param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
       param.secretkey = Utils.encrypt('', param.timestamp)
+
+      let sumParam = null
+      if (r.sumSql) {
+        sumParam = {
+          func: 's_debug_sql',
+          exec_type: 'y',
+          LText: r.sumSql
+        }
+        sumParam.LText = Utils.formatOptions(sumParam.LText)
+        sumParam.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
+        sumParam.secretkey = Utils.encrypt('', sumParam.timestamp)
+      }
       
       Api.getLocalConfig(param).then(result => {
         if (result.status) {
-          _resolve()
+          if (sumParam) {
+            Api.getLocalConfig(sumParam).then(res => {
+              if (res.status) {
+                _resolve()
+              } else {
+                _reject()
+                Modal.error({
+                  title: res.message
+                })
+              }
+            })
+          } else {
+            _resolve()
+          }
         } else {
           _reject()
           Modal.error({
@@ -311,11 +342,11 @@
     const { activeKey, search, arr_field, setting } = this.state
 
     let _loading = false
-    if (this.scriptsForm && this.scriptsForm.props.form.getFieldValue('sql')) {
+    if (this.scriptsForm && this.scriptsForm.props.form.getFieldValue('sql') && !/^\s+$/.test(this.scriptsForm.props.form.getFieldValue('sql'))) {
       _loading = true
-    } else if (this.preScriptsForm && this.preScriptsForm.props.form.getFieldValue('sql')) {
+    } else if (this.preScriptsForm && this.preScriptsForm.props.form.getFieldValue('sql') && !/^\s+$/.test(this.preScriptsForm.props.form.getFieldValue('sql'))) {
       _loading = true
-    } else if (this.cbScriptsForm && this.cbScriptsForm.props.form.getFieldValue('sql')) {
+    } else if (this.cbScriptsForm && this.cbScriptsForm.props.form.getFieldValue('sql') && !/^\s+$/.test(this.cbScriptsForm.props.form.getFieldValue('sql'))) {
       _loading = true
     }
 
@@ -470,6 +501,7 @@
               setting={setting}
               scripts={scripts}
               defaultSql={defaultSql}
+              urlFields={config.urlFields}
               searches={this.props.search}
               scriptsChange={this.scriptsChange}
               scriptsUpdate={this.scriptsUpdate}
@@ -487,6 +519,7 @@
               setting={setting}
               scripts={preScripts}
               regoptions={regoptions}
+              urlFields={config.urlFields}
               searches={this.props.search}
               scriptsUpdate={this.preScriptsUpdate}
               wrappedComponentRef={(inst) => this.preScriptsForm = inst}

--
Gitblit v1.8.0