From ecbe0dc46ce2b8f607b9afd063104adeb7f10fe8 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期二, 30 三月 2021 15:19:31 +0800
Subject: [PATCH] 2021-03-30

---
 src/templates/sharecomponent/treesettingcomponent/settingform/utils.jsx |   60 +++++++++++++++++++++++++++++++++++++++++++-----------------
 1 files changed, 43 insertions(+), 17 deletions(-)

diff --git a/src/templates/sharecomponent/treesettingcomponent/settingform/utils.jsx b/src/templates/sharecomponent/treesettingcomponent/settingform/utils.jsx
index ae1a6b6..3ff821a 100644
--- a/src/templates/sharecomponent/treesettingcomponent/settingform/utils.jsx
+++ b/src/templates/sharecomponent/treesettingcomponent/settingform/utils.jsx
@@ -2,27 +2,51 @@
 export default class SettingUtils {
   /**
    * @description 鐢熸垚椤甸潰鏌ヨ璇彞
+   * @return {String}  scripts       鑷畾涔夎剼鏈�
    * @return {Object}  setting       椤甸潰璁剧疆
    */
-  static getDebugSql (setting) {
+  static getDebugSql (setting, scripts) {
+    let arr_field = `${setting.valueField},${setting.labelField},${setting.parentField}`
     let sql = ''
-    let _dataresource = setting.dataresource
-    let _customScript = setting.customScript
+    let _dataresource = setting.dataresource || ''
+    let _customScript = ''
 
-    if (setting.interType === 'inner' && !setting.innerFunc && setting.default === 'false') {
+    scripts && scripts.forEach(script => {
+      _customScript += `
+      ${script.sql}
+      `
+    })
+
+    if (_customScript) {
+      _customScript = `declare @ErrorCode nvarchar(50),@retmsg nvarchar(4000),@UserName nvarchar(50),@FullName nvarchar(50) select @ErrorCode='',@retmsg =''
+        ${_customScript}
+      `
+    }
+
+    if (setting.default === 'false') {
       _dataresource = ''
     }
     
-    if (_dataresource) {
-      _dataresource = _dataresource.replace(/@\$|\$@/ig, '')
-    }
-    if (_customScript) {
-      _customScript = _customScript.replace(/@\$|\$@/ig, '')
-    }
+    _dataresource = _dataresource.replace(/@\$|\$@/ig, '')
+    _customScript = _customScript.replace(/@\$|\$@/ig, '')
 
-    if (_customScript) {
-      _customScript = _customScript.replace(/@orderBy@/ig, setting.order)
+    // 澶栬仈鏁版嵁搴撴浛鎹�
+    if (window.GLOB.externalDatabase !== null) {
+      _dataresource = _dataresource.replace(/@db@/ig, window.GLOB.externalDatabase)
+      _customScript = _customScript.replace(/@db@/ig, window.GLOB.externalDatabase)
     }
+    
+    // 姝e垯鏇挎崲
+    let _regoptions = [
+      {
+        reg: new RegExp('@orderBy@', 'ig'),
+        value: setting.order
+      }
+    ]
+
+    _regoptions.forEach(item => {
+      _customScript = _customScript.replace(item.reg, item.value)
+    })
 
     // 鏁版嵁婧愬鐞�
     if (_dataresource) {
@@ -30,21 +54,23 @@
         _dataresource = '(' + _dataresource + ') tb'
       }
 
-      let arr_field = `${setting.valueField}, ${setting.labelField}, ${setting.parentField}`
-
-      _dataresource = `select ${arr_field} from (select ${arr_field} ,ROW_NUMBER() over(order by ${setting.order}) as rows from ${_dataresource}) tmptable order by tmptable.rows`
+      _dataresource = ` select ${arr_field} from (select ${arr_field} ,ROW_NUMBER() over(order by ${setting.order}) as rows from ${_dataresource}) tmptable order by tmptable.rows `
     }
 
     if (_customScript) {
-      sql = `${_customScript}
+      sql = `/* sql 楠岃瘉 */
+        ${_customScript}
         ${_dataresource}
         aaa:
         if @ErrorCode!=''
           insert into tmp_err_retmsg (ID, ErrorCode, retmsg, CreateUserID) select @time_id@,@ErrorCode, @retmsg,@UserID@
       `
     } else {
-      sql = _dataresource
+      sql = `/* sql 楠岃瘉 */
+        ${_dataresource}`
     }
+    sql = sql.replace(/\n\s{8}/ig, '\n')
+    console.info(sql)
     
     return sql
   }

--
Gitblit v1.8.0