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/index.jsx |   62 ++++++++++++++++++++++++------
 1 files changed, 49 insertions(+), 13 deletions(-)

diff --git a/src/templates/sharecomponent/settingcomponent/index.jsx b/src/templates/sharecomponent/settingcomponent/index.jsx
index ca71c7b..eaf65ba 100644
--- a/src/templates/sharecomponent/settingcomponent/index.jsx
+++ b/src/templates/sharecomponent/settingcomponent/index.jsx
@@ -1,10 +1,10 @@
 import React, {Component} from 'react'
 import PropTypes from 'prop-types'
 import { is, fromJS } from 'immutable'
-import { Icon, Modal, Button } from 'antd'
+import { Modal, Button } from 'antd'
+import { SettingOutlined } from '@ant-design/icons'
 
-import Utils from '@/utils/utils.js'
-import DevUtils from '@/utils/devutils.js'
+import Utils, { FuncUtils } from '@/utils/utils.js'
 import zhCN from '@/locales/zh-CN/model.js'
 import enUS from '@/locales/en-US/model.js'
 
@@ -19,12 +19,11 @@
     mainsearch: PropTypes.any,       // 涓昏〃鐨勬悳绱㈡潯浠讹紝褰撳瓙琛ㄨ缃帴鏀朵富琛ㄦ潯浠舵椂鏈夋晥
     MenuID: PropTypes.string,        // 鑿滃崟ID
     config: PropTypes.object,        // 鑿滃崟閰嶇疆淇℃伅
-    permFuncField: PropTypes.array,  // 瀛樺偍杩囩▼鍙敤寮�澶村瓧娈�
     updatesetting: PropTypes.func
   }
 
   state = {
-    dict: localStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
+    dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
     menu: null,          // 鑿滃崟淇℃伅
     search: null,        // 鎼滅储鏉′欢锛屽寘鎷富琛ㄦ悳绱�
     formlist: null,      // 琛ㄥ崟淇℃伅
@@ -61,7 +60,8 @@
     this.setState({
       loading: true
     })
-    this.settingRef.handleConfirm().then(res => {
+    this.settingRef.handleConfirm().then(setting => {
+      let res = this.resetSetting(setting)
       this.setState({
         visible: false,
         loading: false
@@ -85,9 +85,10 @@
     const { menu } = this.state
 
     this.settingRef.handleConfirm('func').then(setting => {
-      let _config = {...config, setting: setting}
-      let newLText = Utils.formatOptions(DevUtils.getTableFunc(setting, menu, _config)) // 鍒涘缓瀛樺偍杩囩▼sql
-      let DelText = Utils.formatOptions(DevUtils.dropfunc(setting.innerFunc))          // 鍒犻櫎瀛樺偍杩囩▼sql
+      let res = this.resetSetting(setting)
+      let _config = {...config, setting: res}
+      let newLText = Utils.formatOptions(FuncUtils.getTableFunc(setting, menu, _config)) // 鍒涘缓瀛樺偍杩囩▼sql
+      let DelText = Utils.formatOptions(FuncUtils.dropfunc(setting.innerFunc))          // 鍒犻櫎瀛樺偍杩囩▼sql
 
       this.refs.funcCreatComponent.exec(setting.innerFunc, newLText, DelText).then(result => {
         if (result === 'success') {
@@ -105,7 +106,8 @@
     const { menu } = this.state
 
     this.settingRef.handleConfirm('interface').then(setting => {
-      let _config = {...config, setting: setting}
+      let res = this.resetSetting(setting)
+      let _config = {...config, setting: res}
       let _menu = {
         type: config.Template === 'CommonTable' ? 'main' : 'subtable',
         MenuID: menu.MenuID,
@@ -115,6 +117,41 @@
 
       this.refs.tableCreatInterface.triggerOutInterface(_menu, _config)
     })
+  }
+
+  resetSetting = (s) => {
+    let setting = fromJS(s).toJS()
+    let maxScript = 0
+
+    if (window.GLOB.funcs && window.GLOB.funcs.length > 0) {
+      window.GLOB.funcs.forEach(m => {
+        let reg = new RegExp('\\$ex@' + m.func_code + '@ex\\$', 'ig')
+        setting.scripts.forEach(item => {
+          item.sql = item.sql.replace(reg, `/*$ex@${m.func_code}-begin*/\n${m.key_sql}\n/*@ex$-end*/`)
+
+          if (item.status === 'false') return
+
+          if (/exec\s/ig.test(item.sql)) {
+            maxScript = 1000
+          } else if (item.sql.length > maxScript) {
+            maxScript = item.sql.length
+          }
+        })
+        setting.preScripts.forEach(item => {
+          item.sql = item.sql.replace(reg, `/*$ex@${m.func_code}-begin*/\n${m.key_sql}\n/*@ex$-end*/`)
+        })
+        setting.cbScripts.forEach(item => {
+          item.sql = item.sql.replace(reg, `/*$ex@${m.func_code}-begin*/\n${m.key_sql}\n/*@ex$-end*/`)
+        })
+        if (setting.dataresource) {
+          setting.dataresource = setting.dataresource.replace(reg, `/*$ex@${m.func_code}-begin*/\n${m.key_sql}\n/*@ex$-end*/`)
+        }
+      })
+    }
+
+    setting.maxScript = maxScript
+
+    return setting
   }
 
   shouldComponentUpdate (nextProps, nextState) {
@@ -131,12 +168,12 @@
   }
 
   render() {
-    const { config, permFuncField } = this.props
+    const { config } = this.props
     const { dict, visible, search, menu } = this.state
 
     return (
       <div className="model-menu-setting">
-        <Icon type="setting" onClick={this.changeSetting} />
+        <SettingOutlined onClick={this.changeSetting} />
         {/* 璁剧疆鍏ㄥ眬閰嶇疆鍙婂垪琛ㄦ暟鎹簮 */}
         <Modal
           wrapClassName="model-table-setting-verify-modal"
@@ -158,7 +195,6 @@
             menu={menu}
             config={config}
             search={search}
-            permFuncField={permFuncField}
             wrappedComponentRef={(inst) => this.settingRef = inst}
           />
         </Modal>

--
Gitblit v1.8.0