From cc1a76df575c18f0d0ee96e8658461efdce3a918 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期二, 17 一月 2023 18:01:01 +0800
Subject: [PATCH] 2023-01-17

---
 src/menu/sysinterface/index.jsx |   43 ++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 42 insertions(+), 1 deletions(-)

diff --git a/src/menu/sysinterface/index.jsx b/src/menu/sysinterface/index.jsx
index 797dc2c..240fea2 100644
--- a/src/menu/sysinterface/index.jsx
+++ b/src/menu/sysinterface/index.jsx
@@ -6,6 +6,7 @@
 
 import Utils from '@/utils/utils.js'
 import asyncComponent from '@/utils/asyncComponent'
+import MKEmitter from '@/utils/events.js'
 import './index.scss'
 
 const DataSource = asyncComponent(() => import('@/menu/datasource'))
@@ -159,8 +160,44 @@
   changeScripts = (interfaces) => {
     const { config } = this.props
 
+    interfaces = interfaces.map(item => {
+      item.$tables = this.getTables(item)
+      return item
+    })
+
     this.setState({ interfaces })
     this.props.updateConfig({...config, interfaces})
+  }
+
+  getTables = (record) => {
+    let tables = []
+    let cuts = []
+    let cutreg = /(from|update|insert\s+into)\s+(@db@)?[a-z_]+/ig
+    let trimreg = /(from|update|insert\s+into)\s+(@db@)?/ig
+
+    if (record.setting.interType === 'system') {
+      if (record.setting.execute !== 'false') {
+        let tbs = record.setting.dataresource.match(cutreg)
+        tbs && cuts.push(...tbs)
+      }
+      record.scripts && record.scripts.forEach(script => {
+        if (script.status === 'false') return
+        let tbs = script.sql.match(cutreg)
+        tbs && cuts.push(...tbs)
+      })
+    } else {
+      let tb = record.setting.tableName.replace(/@db@|\s+/ig, '')
+      if (/[a-z_]+/ig.test(tb)) {
+        tables.push(tb)
+      }
+    }
+
+    cuts = cuts.map(item => item.replace(trimreg, ''))
+    tables.push(...cuts)
+    tables = tables.filter(Boolean)
+    tables = Array.from(new Set(tables))
+
+    return tables
   }
 
   update = (record) => {
@@ -172,6 +209,7 @@
       record.status = 'false'
     }
     record.name = record.setting.name
+    record.$tables = this.getTables(record)
 
     let interfaces = this.state.interfaces.map(item => {
       if (item.uuid !== record.uuid) {
@@ -182,6 +220,10 @@
 
     this.setState({ interfaces })
     this.props.updateConfig({...config, interfaces})
+
+    setTimeout(() => {
+      MKEmitter.emit('mkUpdateInter', record, {delay: 0})
+    }, 10)
   }
 
   addInterface = () => {
@@ -227,7 +269,6 @@
           destroyOnClose
         > 
           <PlusOutlined key="add-interface" onClick={this.addInterface}/>
-          {/* <div style={{fontSize: '12px', position: 'relative', top: '20px'}}>娉細鎺ュ彛鎵ц瀹屾垚鍚庯紝浼氳Е鍙戦粯璁や笉鍔犺浇鐨勭粍浠跺埛鏂版暟鎹��</div> */}
           <EditTable key="manage-interface" actions={['copy']} type="interface" data={interfaces} columns={columns} onChange={this.changeScripts}/>
         </Modal>
       </div>

--
Gitblit v1.8.0