From 5466452f77890b1c04d138b52a5fce54cb6d298a Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期四, 12 九月 2024 11:20:25 +0800
Subject: [PATCH] Merge branch 'master' into positec

---
 src/menu/datasource/verifycard/index.jsx |  141 +++++++++++++++++++++++++++++++++++------------
 1 files changed, 105 insertions(+), 36 deletions(-)

diff --git a/src/menu/datasource/verifycard/index.jsx b/src/menu/datasource/verifycard/index.jsx
index d083aa3..a2f6111 100644
--- a/src/menu/datasource/verifycard/index.jsx
+++ b/src/menu/datasource/verifycard/index.jsx
@@ -4,7 +4,6 @@
 import { Form, Tabs, Popconfirm, notification, Modal, Typography, Spin, message, Button, Input } from 'antd'
 import { StopOutlined, CheckCircleOutlined, TableOutlined, EditOutlined, SwapOutlined, DeleteOutlined, CopyOutlined, BorderOutlined, SnippetsOutlined } from '@ant-design/icons'
 import moment from 'moment'
-import md5 from 'md5'
 
 import Api from '@/api'
 import Utils from '@/utils/utils.js'
@@ -24,6 +23,7 @@
 const { Search } = Input
 const { confirm } = Modal
 
+const ExcelOut = asyncComponent(() => import('./excelout'))
 const CodeMirror = asyncComponent(() => import('@/templates/zshare/codemirror'))
 const FieldsComponent = asyncComponent(() => import('@/templates/sharecomponent/fieldscomponent'))
 const EditTable = asyncComponent(() => import('@/templates/zshare/editTable'))
@@ -42,9 +42,8 @@
     loading: false,
     colLoading: false,
     searchKey: '',
-    initsql: '',          // sql楠岃瘉鏃跺彉閲忓0鏄庡強璧嬪��
     usefulfields: '',
-    defaultsql: '',       // 榛樿Sql
+    defaultsql: '',
     systemScripts: [],
     median: {},
     visible: false,
@@ -52,6 +51,7 @@
     pvisible: false,
     reload: false,
     script: null,
+    oriConfig: null,
     scriptValue: '',
     cols: null,
     colColumns: [
@@ -201,24 +201,26 @@
     let _setting = fromJS(config.setting).toJS()
     let scripts = config.scripts ? fromJS(config.scripts).toJS() : []
 
-    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')
-        if (_setting.dataresource) {
-          _setting.dataresource = _setting.dataresource.replace(reg, `$ex@${m.func_code}@ex$`)
-        }
-        scripts && scripts.forEach(item => {
-          item.sql = item.sql.replace(reg, `$ex@${m.func_code}@ex$`)
-        })
-      })
-    }
+    // 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')
+    //     if (_setting.dataresource) {
+    //       _setting.dataresource = _setting.dataresource.replace(reg, `$ex@${m.func_code}@ex$`)
+    //     }
+    //     scripts && scripts.forEach(item => {
+    //       item.sql = item.sql.replace(reg, `$ex@${m.func_code}@ex$`)
+    //     })
+    //   })
+    // }
 
     let columns = config.columns ? fromJS(config.columns).toJS() : []
     let subColumns = config.subColumns ? fromJS(config.subColumns).toJS() : []
 
-    columns.reverse()
+    if (!config.fixedCol) {
+      columns.reverse()
+    }
     subColumns.reverse()
-
+    
     columns.forEach(col => {
       if (!col.datatype) return
       if (/^nvarchar/.test(col.datatype)) {
@@ -248,7 +250,13 @@
       median: _setting,
       searches: formatSearch(search),
       searchKey: '',
-      debugId: _setting.debugId || ''
+      debugId: _setting.debugId || '',
+      oriConfig: fromJS({
+        scripts,
+        columns: columns,
+        subColumns: subColumns,
+        setting: _setting
+      }).toJS()
     })
 
     this.getsysScript()
@@ -546,7 +554,7 @@
 
   submitDataSource = () => {
     const { config, mainSearch } = this.props
-    const { activeKey, setting, columns, subColumns, scripts, cols, median } = this.state
+    const { activeKey, setting, columns, subColumns, scripts, cols, median, searches } = this.state
 
     if (config.subtype === 'dualdatacard') {
       let arr = columns.map(col => col.field.toLowerCase())
@@ -611,12 +619,13 @@
           if (res.useMSearch === 'true') { // 浣跨敤涓绘悳绱㈡潯浠�
             search = [...search, ...mainSearch]
           }
+          let _searches = formatSearch(search)
 
           this.setState({
-            searches: formatSearch(search),
+            searches: _searches,
             setting: res
           }, () => {
-            this.sqlverify(() => { resolve({setting: res, columns, subColumns, scripts, cols }) }, reject, 'submit')
+            this.sqlverify(() => { resolve({setting: res, columns, subColumns, scripts, cols, searches: _searches }) }, reject, 'submit')
           })
         }, () => {
           reject()
@@ -631,7 +640,7 @@
           reject()
           return
         }
-        this.sqlverify(() => { resolve({setting, columns, subColumns, scripts, cols }) }, reject, 'submit')
+        this.sqlverify(() => { resolve({setting, columns, subColumns, scripts, cols, searches }) }, reject, 'submit')
       } else if (activeKey === 'subcolumns') {
         if (this.subdatasource && this.subdatasource.state.editingKey) {
           notification.warning({
@@ -642,11 +651,37 @@
           reject()
           return
         }
-        this.sqlverify(() => { resolve({setting, columns, subColumns, scripts, cols }) }, reject, 'submit')
+        this.sqlverify(() => { resolve({setting, columns, subColumns, scripts, cols, searches }) }, reject, 'submit')
       } else if (activeKey === 'scripts') {
-        this.sqlverify(() => { resolve({setting, columns, subColumns, scripts, cols }) }, reject, 'submit')
+        this.sqlverify(() => { resolve({setting, columns, subColumns, scripts, cols, searches }) }, reject, 'submit')
       }
     })
+  }
+
+  closeDataSource = (callback) => {
+    const { setting, columns, subColumns, scripts, oriConfig } = this.state
+
+    let line = scripts.map(item => item.sql).join('')
+    line += columns.map(item => item.field + item.datatype).join('')
+    line += subColumns.map(item => item.field + item.datatype).join('')
+    line += setting.interType + (setting.dataresource || '') + (setting.order || '') + (setting.primaryKey || '')
+
+    let _line = oriConfig.scripts.map(item => item.sql).join('')
+    _line += oriConfig.columns.map(item => item.field + item.datatype).join('')
+    _line += oriConfig.subColumns.map(item => item.field + item.datatype).join('')
+    _line += oriConfig.setting.interType + (oriConfig.setting.dataresource || '') + (oriConfig.setting.order || '') + (oriConfig.setting.primaryKey || '')
+
+    if (line !== _line) {
+      confirm({
+        content: '鏁版嵁婧愬凡淇敼锛岀‘瀹氬彇娑堝悧锛�',
+        onOk() {
+          callback()
+        },
+        onCancel() {}
+      })
+    } else {
+      callback()
+    }
   }
 
   sqlverify = (resolve, reject, type, testScripts) => {
@@ -679,10 +714,8 @@
         _columns = [...columns, ...subColumns]
       }
 
-      let r = SettingUtils.getDebugSql(setting, _scripts, _columns, searches, config.subtype)
+      let r = SettingUtils.getDebugSql(setting, _scripts, _columns, searches, config.subtype, config.hasExtend)
 
-      let _debugId = md5(r.sql)
-      
       if (r.custompage && setting.laypage === 'true' && _columns.findIndex(col => col.field === 'mk_total') === -1) {
         if (config.subtype !== 'basetable') {
           Modal.warning({
@@ -702,7 +735,7 @@
         }
       }
 
-      if (debugId === _debugId) {
+      if (debugId === r.debugId) {
         resolve()
         return
       }
@@ -717,7 +750,7 @@
 
       Api.sDebug(r.sql).then(result => {
         if (result.status || result.ErrCode === '-2') {
-          this.setState({debugId: _debugId}, () => {
+          this.setState({debugId: r.debugId}, () => {
             resolve()
           })
         } else {
@@ -959,13 +992,19 @@
   }
 
   copyColumns = () => {
-    const { columns, setting } = this.state
+    const { config } = this.props
+    const { columns, subColumns, setting } = this.state
 
+    let _columns = columns
     let m = []
     let n = []
     let s = []
 
-    columns.forEach(col => {
+    if (subColumns && subColumns.length) {
+      _columns = [...columns, ...subColumns]
+    }
+
+    _columns.forEach(col => {
       m.unshift(`${col.field} ${col.datatype}`)
       n.unshift(col.field)
       if (/decimal|int/ig.test(col.datatype)) {
@@ -980,7 +1019,34 @@
     })
 
     if (window.debugger) {
-      console.info('select ' + s.join(', '))
+      window.mkInfo('select ' + s.join(', '))
+    }
+
+    let extend = ''
+    if (config.hasExtend) {
+      extend = []
+      let mapCol = (cols) => {
+        cols.forEach(col => {
+          if (col.type === 'extend') {
+            let datatype = 'Nvarchar(50)'
+            _columns.forEach(c => {
+              if (c.field === col.field) {
+                datatype = c.datatype
+              }
+            })
+            for (let i = 1; i < col.quota; i++) {
+              extend.push(`${col.field}${i} ${datatype}`)
+            }
+          } else if (col.type === 'colspan' && col.subcols) {
+            mapCol(col.subcols)
+          }
+        })
+      }
+      mapCol(config.cols)
+      extend = `
+      /* 鎵╁睍鍒楀瓧娈� */
+      /* ${extend.join(',')} */
+      `
     }
 
     let oInput = document.createElement('input')
@@ -989,7 +1055,7 @@
     insert into #${setting.tableName || 'tb'}
     (${n.join(',')})
     select ${n.join(',')}
-    from ${setting.dataresource ? `(${setting.dataresource}) tb` : setting.tableName || 'tb'}
+    from ${setting.dataresource ? `(${setting.dataresource.replace(/\n/g, ' ')}) tb` : setting.tableName || 'tb'}
     order by @orderBy@
     
     declare @mk_total int
@@ -1003,7 +1069,9 @@
         delete #${setting.tableName || 'tb'} where sort_id > @pageIndex@*@pageSize@ 
       
       if @pageIndex_top > 0
-        delete #${setting.tableName || 'tb'} where sort_id <= @pageIndex_top`
+        delete #${setting.tableName || 'tb'} where sort_id <= @pageIndex_top
+
+    drop table #${setting.tableName || 'tb'}${extend}`
 
     document.body.appendChild(oInput)
     oInput.select()
@@ -1037,8 +1105,6 @@
   addProcess = () => {
     const { config } = this.props
     const { columns } = this.state
-
-    if (config.subtype === 'dualdatacard') return
 
     let fields = []
     let cols = []
@@ -1167,6 +1233,7 @@
               type="fields"
               updatefield={this.updatefields}
             />
+            <ExcelOut data={columns} setting={setting}/>
             <EditTable actions={['edit', 'move', 'copy', 'del', 'clear']} searchKey={searchKey} type="datasourcefield" wrappedComponentRef={(inst) => this.datasource = inst} data={columns} columns={colColumns} onChange={(columns) => this.setState({columns})}/>
           </TabPane> : <TabPane tab={
             <span>
@@ -1175,6 +1242,7 @@
             </span>
           } key="columns">
             <div className="base-table-columns"></div>
+            <ExcelOut data={columns} setting={setting}/>
             <EditTable actions={[]} searchKey={searchKey} type="datasourcefield" data={columns} columns={colColumns}/>
           </TabPane>}
           {config.subtype === 'dualdatacard' ? <TabPane tab={
@@ -1189,6 +1257,7 @@
               type="fields"
               updatefield={this.updateSubfields}
             />
+            <ExcelOut data={subColumns} setting={setting}/>
             <EditTable actions={['edit', 'move', 'copy', 'del', 'clear']} searchKey={searchKey} type="datasourcefield" wrappedComponentRef={(inst) => this.subdatasource = inst} data={subColumns} columns={colColumns} onChange={(subColumns) => this.setState({subColumns})}/>
           </TabPane> : null}
           <TabPane tab={
@@ -1215,10 +1284,10 @@
             }}/> : null}
             <CustomScriptsForm
               type={config.type}
+              hasExtend={config.hasExtend}
               setting={setting}
               searches={searches}
               defaultsql={defaultsql}
-              initsql={this.state.initsql}
               customScripts={scripts}
               systemScripts={this.state.systemScripts}
               scriptsChange={this.scriptsChange}

--
Gitblit v1.8.0