From a7c6bffc152da5eeb780cca98fe73b7d90becf04 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期三, 30 十月 2024 16:22:19 +0800
Subject: [PATCH] Merge branch 'master' into positec

---
 src/menu/datasource/index.jsx |  303 ++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 241 insertions(+), 62 deletions(-)

diff --git a/src/menu/datasource/index.jsx b/src/menu/datasource/index.jsx
index e0bb557..dd54aa7 100644
--- a/src/menu/datasource/index.jsx
+++ b/src/menu/datasource/index.jsx
@@ -1,10 +1,11 @@
 import React, {Component} from 'react'
 import PropTypes from 'prop-types'
 import { is, fromJS } from 'immutable'
-import { Modal } from 'antd'
+import { Modal, Button, notification } from 'antd'
 import { SettingOutlined } from '@ant-design/icons'
 
 import VerifyCard from './verifycard'
+import CreateFunc from '@/templates/zshare/createfunc'
 import MKEmitter from '@/utils/events.js'
 import './index.scss'
 
@@ -20,13 +21,7 @@
     mainSearch: [],
     visible: false,
     loading: false,
-    setting: null
-  }
-
-  UNSAFE_componentWillMount () {
-    const { config } = this.props
-
-    this.setState({setting: fromJS(config.setting).toJS()})
+    record: {}
   }
 
   shouldComponentUpdate (nextProps, nextState) {
@@ -36,11 +31,6 @@
   editDataSource = () => {
     const { config } = this.props
     const { appType } = this.state
-
-    if (config.type === 'interface') { // 鍏叡鏁版嵁婧愪笉浣跨敤鎼滅储
-      this.setState({visible: true})
-      return
-    }
 
     let search = []
     let menu = fromJS(window.GLOB.customMenu).toJS()
@@ -100,48 +90,49 @@
           })
         })
       }
+    } else if (config.type === 'interface') {
+      menu.components.forEach(item => {
+        if (item.type !== 'search') return
+        search = item.search
+      })
     } else {
-      let _search = null
-      let filterComponent = (box) => {
+      let filterComponent = (box, mainSearch) => {
         box.components.forEach(item => {
-          if (_search) return
-
-          if (item.type === 'search') {
-            box.slist = [...box.slist, item.search]
-          } else if (item.uuid === config.uuid) {
-            _search = box.slist.pop()
+          if (item.type !== 'search') return
+          mainSearch = item.search
+        })
+        let has = false
+        box.components.forEach(item => {
+          if (item.uuid === config.uuid) {
+            has = true
           } else if (item.type === 'group') {
             item.components.forEach(m => {
               if (m.uuid !== config.uuid) return
-              _search = box.slist.pop()
-            })
-          } else if (item.type === 'tabs') {
-            item.subtabs.forEach(tab => {
-              tab.slist = [...box.slist]
-              filterComponent(tab)
+              has = true
             })
           }
         })
-      }
-      menu.slist = []
-      filterComponent(menu)
 
-      if (_search) {
-        search = _search
-      } else {
-        menu.components.forEach(item => {
-          if (item.type !== 'search') return
-          search = item.search
-        })
+        if (has) {
+          search = mainSearch || []
+        } else {
+          box.components.forEach(item => {
+            if (item.type !== 'tabs') return
+
+            item.subtabs.forEach(tab => {
+              filterComponent(tab, mainSearch)
+            })
+          })
+        }
       }
+      filterComponent(menu, null)
     }
 
     this.setState({
       visible: true,
-      mainSearch: search
+      mainSearch: search,
+      record: {...config.setting}
     })
-
-    MKEmitter.emit('modalStatus', '鏁版嵁婧�')
   }
 
   verifySubmit = () => {
@@ -150,59 +141,243 @@
     this.setState({loading: true})
     this.verifyRef.submitDataSource().then(res => {
 
+      let MenuType = sessionStorage.getItem('MenuType')
+
+      if (MenuType === 'billPrint') {
+        res.setting.supModule = ['empty']
+      }
+
+      if (!res.setting.primaryKey && res.columns && res.columns.length > 0) {
+        res.columns.forEach(col => {
+          if (col.field.toLowerCase() === 'id') {
+            res.setting.primaryKey = col.field
+          }
+        })
+      }
+
       if (res.columns) {
         res.columns = res.columns.map(item => {
-    
           if (/int/ig.test(item.datatype)) {
             item.type = 'number'
             item.decimal = 0
           } else if (/Decimal/ig.test(item.datatype)) {
             item.type = 'number'
             item.decimal = +item.datatype.replace(/^Decimal\(18,/ig, '').replace(/\)/ig, '')
+          } else if (/^date/ig.test(item.datatype)) {
+            item.type = 'text'
+            item.fieldlength = 50
           } else {
             item.type = 'text'
             item.fieldlength = +item.datatype.replace(/^Nvarchar\(/ig, '').replace(/\)/ig, '')
           }
           return item
         })
+
+        if (!config.fixedCol) {
+          res.columns.reverse()
+        }
       }
 
       let maxScript = 0
+      let useExec = false
 
-      if (window.GLOB.funcs && window.GLOB.funcs.length > 0) {
-        window.GLOB.funcs.forEach(m => {
-          let reg = new RegExp('\\$ex@' + m.func_code + '@ex\\$', 'ig')
-          if (res.setting.dataresource) {
-            res.setting.dataresource = res.setting.dataresource.replace(reg, `/*$ex@${m.func_code}-begin*/\n${m.key_sql}\n/*@ex$-end*/`)
+      let sFields = []
+      res.searches && res.searches.forEach(item => {
+        if (!item.key) return
+    
+        if (item.type === 'date') {
+          if (sFields.includes(item.key)) {
+            sFields.push(item.key + '1')
+          } else {
+            sFields.push(item.key)
           }
-          res.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
-            }
+        } else if (item.type === 'dateweek' || item.type === 'range' || (item.type === 'datemonth' && item.match !== '=')) {
+          sFields.push(item.key)
+          sFields.push(item.key + '1')
+        } else if (item.type === 'daterange') {
+          if (/,/.test(item.key)) {
+            sFields.push(item.key.split(',')[0])
+            sFields.push(item.key.split(',')[1])
+          } else {
+            sFields.push(item.key)
+            sFields.push(item.key + '1')
+          }
+        } else if (item.type === 'text' || item.type === 'select') {
+          item.key.split(',').forEach(field => {
+            sFields.push(field)
           })
-        })
+        } else {
+          sFields.push(item.key)
+        }
+      })
+      delete res.searches
+      sFields = sFields.join('|')
+
+      // if (window.GLOB.funcs && window.GLOB.funcs.length > 0) {
+      //   window.GLOB.funcs.forEach(m => {
+      //     let reg = new RegExp('\\$ex@' + m.func_code + '@ex\\$', 'ig')
+      //     if (res.setting.dataresource) {
+      //       res.setting.dataresource = res.setting.dataresource.replace(reg, `/*$ex@${m.func_code}-begin*/\n${m.key_sql}\n/*@ex$-end*/`)
+      //     }
+      //     res.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)) {
+      //         useExec = true
+      //         maxScript = 1000
+      //       } else if (item.sql.length > maxScript) {
+      //         maxScript = item.sql.length
+      //       }
+      //     })
+      //   })
+      // } else {
+      //   res.scripts.forEach(item => {
+      //     if (item.status === 'false') return
+
+      //     if (/exec\s/ig.test(item.sql)) {
+      //       useExec = true
+      //       maxScript = 1000
+      //     } else if (item.sql.length > maxScript) {
+      //       maxScript = item.sql.length
+      //     }
+      //   })
+      // }
+
+      if (res.setting.interType === 'system' && res.setting.dataresource && res.setting.execute !== 'false') {
+        res.setting.dataresource = res.setting.dataresource.replace(/\t+|\v+/g, ' ')
+        if (sFields) {
+          if (new RegExp(`@(${sFields})@`, 'ig').test(res.setting.dataresource)) {
+            maxScript = 1000
+          }
+        }
       }
+
+      res.scripts.forEach(item => {
+        if (item.status === 'false') return
+
+        item.sql = item.sql.replace(/\t+|\v+/g, ' ')
+
+        if (/exec\s/ig.test(item.sql)) {
+          useExec = true
+          maxScript = 1000
+        } else if (sFields && new RegExp(`@(${sFields})@`, 'ig').test(item.sql)) {
+          maxScript = 1000
+        } else if (item.sql.length > maxScript) {
+          maxScript = item.sql.length
+        }
+      })
 
       res.setting.maxScript = maxScript
 
+      if (useExec && res.setting.sync === 'true') {
+        notification.warning({
+          top: 92,
+          message: '褰撳墠鏁版嵁婧愪娇鐢ㄤ簡鍚屾鏌ヨ涓旇嚜瀹氫箟鑴氭湰涓瓨鍦ㄥ嚱鏁癳xec锛屽閬囨帴鍙f姤閿欓渶鍏抽棴鍚屾鏌ヨ鍚庨噸鏂版祴璇曘��',
+          duration: 5
+        })
+      }
+
+      if (config.subtype !== 'dualdatacard') {
+        delete res.subColumns
+        if (config.type === 'interface') {
+          res.setting.laypage = 'false'
+        }
+      } else {
+        res.subColumns = res.subColumns.map(item => {
+          if (/int/ig.test(item.datatype)) {
+            item.type = 'number'
+            item.decimal = 0
+          } else if (/Decimal/ig.test(item.datatype)) {
+            item.type = 'number'
+            item.decimal = +item.datatype.replace(/^Decimal\(18,/ig, '').replace(/\)/ig, '')
+          } else if (/^date/ig.test(item.datatype)) {
+            item.type = 'text'
+            item.fieldlength = 50
+          } else {
+            item.type = 'text'
+            item.fieldlength = +item.datatype.replace(/^Nvarchar\(/ig, '').replace(/\)/ig, '')
+          }
+          return item
+        })
+  
+        res.subColumns.reverse()
+      }
+
+      if (this.verifyRef.state.debugId) {
+        res.setting.debugId = this.verifyRef.state.debugId
+      } else {
+        delete res.setting.debugId
+      }
+
+      if (res.setting.interType === 'system' && res.setting.sync === 'true') {
+        res.scripts && res.scripts.forEach(script => {
+          if (script.status === 'false' || script.position !== 'back') return
+
+          res.setting.sync = 'false'
+        })
+      }
+
       this.setState({loading: false, visible: false})
+
+      if (res.cols) {
+        res.cols = [...config.cols, ...res.cols]
+      } else {
+        delete res.cols
+      }
       this.props.updateConfig({...config, ...res})
 
-      MKEmitter.emit('modalStatus', false)
+      if (res.setting && res.setting.tableName && config.setting && !config.setting.tableName) {
+        setTimeout(() => {
+          MKEmitter.emit('publicTableChange', res.setting.tableName, 'init')
+        }, 100)
+      }
+
+      if ((config.type === 'card' && config.subtype === 'datacard') || (config.type === 'table' && config.subtype === 'normaltable')) {
+        setTimeout(() => {
+          MKEmitter.emit('mkUpdateInter', {uuid: config.uuid, columns: res.columns}, {delay: 0})
+        }, 150)
+      }
     }, () => {
       this.setState({loading: false})
     })
   }
 
+  cancel = () => {
+    this.verifyRef.closeDataSource(() => {
+      this.setState({ visible: false, loading: false })
+    })
+  }
+
+  creatFunc = () => {
+    const { config } = this.props
+    const { mainSearch } = this.state
+    const menu = window.GLOB.customMenu
+
+    return new Promise((resolve) => {
+      this.verifyRef.submitDataSource().then(res => {
+        let _config = fromJS(config).toJS()
+        _config.MenuName = menu.MenuName + '-' + _config.name
+        _config.menuNo = menu.MenuNo
+        _config.MenuID = menu.MenuID
+        _config.setting = res.setting
+        _config.columns = res.columns
+        _config.func = res.setting.innerFunc
+        _config.$type = 'table'
+  
+        if (res.setting.useMSearch === 'true') { // 浣跨敤涓绘悳绱㈡潯浠�
+          _config.search = [..._config.search, ...mainSearch]
+        }
+  
+        resolve(_config)
+      })
+    })
+  }
+
   render () {
     const { config } = this.props
-    const { visible, loading, mainSearch } = this.state
+    const { visible, loading, mainSearch, record } = this.state
 
     return (
       <div className="model-datasource">
@@ -214,14 +389,18 @@
           width={'75vw'}
           maskClosable={false}
           okText="鎻愪氦"
-          onOk={this.verifySubmit}
-          confirmLoading={loading}
-          onCancel={() => { MKEmitter.emit('modalStatus', false);this.setState({ visible: false }) }}
+          onCancel={() => {this.setState({ visible: false, loading: false }) }}
+          footer={[
+            config.subtype !== 'dualdatacard' && record.interType === 'inner' ? <CreateFunc key="create" getMsg={this.creatFunc}/> : null,
+            <Button key="cancel" onClick={this.cancel}>鍙栨秷</Button>,
+            <Button key="confirm" type="primary" loading={loading} onClick={this.verifySubmit}>纭畾</Button>
+          ]}
           destroyOnClose
         >
           <VerifyCard
             mainSearch={mainSearch}
             config={config}
+            updRecord={(record) => this.setState({record: record})}
             wrappedComponentRef={(inst) => this.verifyRef = inst}
           />
         </Modal>

--
Gitblit v1.8.0