From 6afdec0062dacbded57e166230eb22cc55ced0c1 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期六, 08 五月 2021 14:30:21 +0800
Subject: [PATCH] 2021-05-08

---
 src/tabviews/custom/index.jsx |  401 +++++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 347 insertions(+), 54 deletions(-)

diff --git a/src/tabviews/custom/index.jsx b/src/tabviews/custom/index.jsx
index 3670784..40f0818 100644
--- a/src/tabviews/custom/index.jsx
+++ b/src/tabviews/custom/index.jsx
@@ -11,6 +11,7 @@
 import zhCN from '@/locales/zh-CN/main.js'
 import enUS from '@/locales/en-US/main.js'
 import Utils from '@/utils/utils.js'
+import UtilsDM from '@/utils/utils-datamanage.js'
 import asyncComponent from '@/utils/asyncComponent'
 import MKEmitter from '@/utils/events.js'
 import NotFount from '@/components/404'
@@ -20,13 +21,19 @@
 const AntvBarAndLine = asyncComponent(() => import('./components/chart/antv-bar-line'))
 const AntvPie = asyncComponent(() => import('./components/chart/antv-pie'))
 const AntvTabs = asyncComponent(() => import('./components/tabs/antv-tabs'))
+const AntvDashboard = asyncComponent(() => import('./components/chart/antv-dashboard'))
+const AntvScatter = asyncComponent(() => import('./components/chart/antv-scatter'))
 const DataCard = asyncComponent(() => import('./components/card/data-card'))
 const PropCard = asyncComponent(() => import('./components/card/prop-card'))
+const NormalForm = asyncComponent(() => import('./components/form/normal-form'))
+const CarouselDataCard = asyncComponent(() => import('./components/carousel/data-card'))
+const CarouselPropCard = asyncComponent(() => import('./components/carousel/prop-card'))
 const TableCard = asyncComponent(() => import('./components/card/table-card'))
 const MainSearch = asyncComponent(() => import('@/tabviews/zshare/topSearch'))
 const NormalTable = asyncComponent(() => import('./components/table/normal-table'))
 const NormalGroup = asyncComponent(() => import('./components/group/normal-group'))
 const BraftEditor = asyncComponent(() => import('./components/editor/braft-editor'))
+const SandBox = asyncComponent(() => import('./components/code/sand-box'))
 const SettingComponent = asyncComponent(() => import('@/tabviews/zshare/settingcomponent'))
 const PagemsgComponent = asyncComponent(() => import('@/tabviews/zshare/pageMessage'))
 
@@ -132,14 +139,8 @@
 
         component.search = component.search.map(item => {
           item.oriInitval = item.initval
-          if (['text', 'select', 'link'].includes(item.type) && param) {
-            if (param.searchkey === item.field) {
-              item.initval = param.searchval
-            } else if (param.BID && item.field.toLowerCase() === 'bid') {
-              item.initval = param.BID
-            } else if (param.data && param.data[item.field]) {
-              item.initval = param.data[item.field]
-            }
+          if (['text', 'select', 'link'].includes(item.type) && param && param.$searchkey === item.field) {
+            item.initval = param.$searchval
           }
 
           return item
@@ -149,7 +150,7 @@
       })
 
       let params = []
-      let BID = param && param.BID ? param.BID : ''
+      let BID = param && param.$BID ? param.$BID : ''
       let inherit = {}
 
       if (config.cacheUseful === 'true') { // 缂撳瓨缁ф壙
@@ -158,7 +159,38 @@
         inherit.cacheTime = config.cacheTime
       }
 
-      config.components = this.formatSetting(config.components, params, mainSearch, inherit)
+      let userName = sessionStorage.getItem('User_Name') || ''
+      let fullName = sessionStorage.getItem('Full_Name') || ''
+      let city = sessionStorage.getItem('city') || ''
+
+      if (sessionStorage.getItem('isEditState') === 'true') {
+        userName = sessionStorage.getItem('CloudUserName') || ''
+        fullName = sessionStorage.getItem('CloudFullName') || ''
+      }
+
+      let regs = [
+        { reg: /@userName@/ig, value: userName },
+        { reg: /@fullName@/ig, value: fullName },
+        { reg: /@login_city@/ig, value: city }
+      ]
+      
+      if (window.GLOB.externalDatabase !== null) {
+        regs.push({
+          reg: /@db@/ig,
+          value: window.GLOB.externalDatabase
+        })
+      }
+      if (config.urlFields) {
+        config.urlFields.forEach(field => {
+          let val = `'${param ? (param[field] || '') : ''}'`
+          regs.push({
+            reg: new RegExp('@' + field + '@', 'ig'),
+            value: val
+          })
+        })
+      }
+
+      config.components = this.formatSetting(config.components, params, mainSearch, inherit, regs)
 
       this.setState({
         BID: BID,
@@ -179,6 +211,8 @@
         if (!this.props.Tab) {
           this.setShortcut()
         }
+
+        this.loadData()
       })
     } else {
       this.setState({
@@ -228,6 +262,178 @@
     }
   }
 
+  loadData = () => {
+    const { config } = this.state
+
+    if (!config.interfaces || config.interfaces.length === 0) return
+
+    let inters = []
+
+    config.interfaces.forEach(item => {
+      if (item.status !== 'true') return
+
+      if (window.GLOB.systemType === 'production' && !item.proInterface) {
+        notification.warning({
+          top: 92,
+          message: `銆�${item.name}銆嬫湭璁剧疆姝e紡绯荤粺鍦板潃!`,
+          duration: 3
+        })
+        return
+      }
+
+      inters.push(item)
+    })
+    
+    if (inters.length > 0) {
+      this.loadOutResource(inters)
+    }
+  }
+
+  loadOutResource = (inters) => {
+    let setting = inters.shift()
+    let param = UtilsDM.getPrevQueryParams(setting, [], this.state.BID, this.props.menuType)
+
+    Api.genericInterface(param).then(res => {
+      if (res.status) {
+        if (res.mk_ex_invoke === 'false' || res.mk_ex_invoke === false) {
+          if (inters.length > 0) {
+            this.loadOutResource(inters)
+          }
+        } else {
+          this.customOuterRequest(res, setting, inters)
+        }
+      } else {
+        notification.error({
+          top: 92,
+          message: res.message,
+          duration: 10
+        })
+      }
+    })
+  }
+
+  customOuterRequest = (result, setting, inters) => {
+    let url = ''
+
+    if (window.GLOB.systemType === 'production') {
+      url = setting.proInterface
+    } else {
+      url = setting.interface
+    }
+
+    let mkey = result.mk_api_key || ''
+
+    delete result.mk_ex_invoke
+    delete result.status
+    delete result.message
+    delete result.ErrCode
+    delete result.ErrMesg
+    delete result.mk_api_key
+
+    let param = {}
+
+    Object.keys(result).forEach(key => {
+      key = key.replace(/^mk_/ig, '')
+      param[key] = result[key]
+    })
+
+    Api.directRequest(url, setting.method, param, setting.cross).then(res => {
+      if (typeof(res) !== 'object' || Array.isArray(res)) {
+        let error = '鏈煡鐨勮繑鍥炵粨鏋滐紒'
+
+        if (typeof(res) === 'string') {
+          error = res.replace(/'/ig, '"')
+        }
+
+        let _result = {
+          mk_api_key: mkey,
+          $ErrCode: 'E',
+          $ErrMesg: error
+        }
+
+        this.customCallbackRequest(_result, setting, inters)
+      } else {
+        res.mk_api_key = mkey
+        this.customCallbackRequest(res, setting, inters)
+      }
+    }, (e) => {
+      let _result = {
+        mk_api_key: mkey,
+        $ErrCode: 'E',
+        $ErrMesg: e && e.statusText ? e.statusText : ''
+      }
+
+      this.customCallbackRequest(_result, setting, inters)
+    })
+  }
+
+  customCallbackRequest = (result, setting, inters) => {
+    let errSql = ''
+    if (result.$ErrCode === 'E') {
+      errSql = `
+        set @ErrorCode='E'
+        set @retmsg='${result.$ErrMesg}'
+      `
+      delete result.$ErrCode
+      delete result.$ErrMesg
+    }
+
+    let lines = UtilsDM.getCallBackSql(setting, result)
+    let param = {}
+
+    if (setting.callbackType === 'script') { // 浣跨敤鑷畾涔夎剼鏈�
+      let sql = lines.map(item => (`
+        ${item.insert}
+        ${item.selects.join(` union all
+        `)}
+      `))
+      sql = sql.join('')
+      
+      param = UtilsDM.getCallBackQueryParams(setting, sql, errSql)
+
+      if (this.state.BID) {
+        param.BID = this.state.BID
+      }
+
+      if (this.props.menuType === 'HS') { // 鍑芥暟 sPC_TableData_InUpDe 浜戠楠岃瘉
+        param.open_key = Utils.encryptOpenKey(param.secretkey, param.timestamp)
+      }
+    } else {
+      param.func = 's_ex_result_back'
+      param.s_ex_result = lines.map((item, index) => ({
+        MenuID: this.props.MenuID || '',
+        MenuName: this.props.MenuName || '',
+        TableName: item.table,
+        LongText: window.btoa(window.encodeURIComponent(`${item.insert}  ${item.selects.join(` union all `)}`)),
+        Sort: index + 1
+      }))
+
+      if ((window.GLOB.systemType !== 'production' && options.sysType !== 'cloud') || window.debugger === true) {
+        let sql = lines.map(item => (`
+          ${item.insert}
+          ${item.selects.join(` union all
+          `)}
+        `))
+        sql = sql.join('')
+        console.info(sql.replace(/\n\s{10}/ig, '\n'))
+      }
+    }
+
+    Api.genericInterface(param).then(res => {
+      if (res.status) {
+        if (inters.length > 0) {
+          this.loadOutResource(inters)
+        }
+      } else {
+        notification.error({
+          top: 92,
+          message: res.message,
+          duration: 10
+        })
+      }
+    })
+  }
+
   filterComponent = (components, roleId, permAction, permMenus) => {
     return components.filter(item => {
       if (item.type === 'tabs') {
@@ -237,6 +443,16 @@
         ) {
           return false
         }
+
+        item.subtabs = item.subtabs.filter(tab => {
+          if (
+            tab.blacklist && tab.blacklist.length > 0 &&
+            tab.blacklist.filter(v => roleId.indexOf(v) > -1).length > 0
+          ) {
+            return false
+          }
+          return true
+        })
 
         item.subtabs = item.subtabs.map(tab => {
           tab.components = this.filterComponent(tab.components, roleId, permAction, permMenus)
@@ -248,7 +464,7 @@
           tab.components.forEach(comp => {
             if (comp.type === 'tabs' && comp.parentIds) {
               supIds.push(...comp.parentIds)
-            } else if (comp.setting.supModule) {
+            } else if (comp.setting && comp.setting.supModule) {
               supIds.push(comp.setting.supModule)
             }
           })
@@ -263,14 +479,14 @@
         }
 
         item.components = this.filterComponent(item.components, roleId, permAction, permMenus)
-      } else if (item.type === 'pie' || item.type === 'bar' || item.type === 'line') {
+      } else if (['pie', 'bar', 'line', 'dashboard', 'scatter'].includes(item.type)) {
         if (
           item.plot.blacklist && item.plot.blacklist.length > 0 &&
           item.plot.blacklist.filter(v => roleId.indexOf(v) > -1).length > 0
         ) {
           return false
         }
-      } else {
+      } else if (item.wrap) {
         if (
           item.wrap.blacklist && item.wrap.blacklist.length > 0 &&
           item.wrap.blacklist.filter(v => roleId.indexOf(v) > -1).length > 0
@@ -292,7 +508,43 @@
         })
       }
       if (item.type === 'table' && item.subtype === 'normaltable') {
-        item.cols = this.getCols(item.cols, roleId, permMenus)
+        let statFields = []
+        let getCols = (cols) => {
+          return cols.filter(col => {
+            if (col.blacklist && col.blacklist.filter(v => roleId.indexOf(v) > -1).length > 0) {
+              return false
+            } else if (col.Hide === 'true') {
+              return false
+            }
+            if (col.type === 'number' && col.sum === 'true' && !statFields.includes(col.field)) {
+              statFields.push(col)
+            } else if (col.type === 'colspan') {
+              col.subcols = getCols(col.subcols || [])
+              if (col.subcols.length === 0) {
+                return false
+              }
+            } else if (col.type === 'custom') {
+              col.elements = col.elements.map(cell => {
+                if (['text', 'number', 'link'].includes(cell.eleType) && !cell.height) {
+                  cell.innerHeight = 'auto'
+                }
+                return cell
+              })
+            }
+      
+            if (col.linkmenu && col.linkmenu.length > 0) {
+              let menu_id = col.linkmenu.pop()
+              col.linkThdMenu = permMenus.filter(m => m.MenuID === menu_id)[0] || ''
+            } else {
+              col.linkThdMenu = ''
+            }
+
+            return true
+          })
+        }
+        
+        item.cols = getCols(item.cols)
+        item.statFields = statFields
       }
 
       // 鏉冮檺杩囨护
@@ -305,15 +557,21 @@
           cell.syncComponentId = cell.syncComponent ? cell.syncComponent.pop() : ''
           cell.$menuId = item.uuid
           cell.$tabId = tabId
-          cell.$type = 'CustomPage'
+          cell.$view = 'CustomPage'
 
           if (cell.OpenType === 'funcbutton' && cell.funcType === 'print' && cell.verify) { // 鎵撳嵃鏈鸿缃�
             cell = this.getPrinter(cell, item.uuid)
           }
 
+          if (cell.btnstyle) { // 鍏煎
+            cell.style = cell.style || {}
+            cell.style = {...cell.style, ...cell.btnstyle}
+          }
+
           return isHS || permAction[cell.uuid]
         })
       }
+
       if (item.type === 'card') {
         item.subcards.forEach(card => {
           let _hasheight = card.style.height && card.style.height !== 'auto'
@@ -331,10 +589,14 @@
               cell.syncComponentId = cell.syncComponent ? cell.syncComponent.pop() : ''
               cell.$menuId = item.uuid
               cell.$tabId = tabId
-              cell.$type = 'CustomPage'
+              cell.$view = 'CustomPage'
 
               if (cell.OpenType === 'funcbutton' && cell.funcType === 'print' && cell.verify) { // 鎵撳嵃鏈鸿缃�
                 cell = this.getPrinter(cell, item.uuid)
+              }
+              if (card.btnstyle) { // 鍏煎
+                card.style = card.style || {}
+                card.style = {...card.style, ...card.btnstyle}
               }
             } else if (['text', 'number', 'link'].includes(cell.eleType) && !cell.height && _hasheight) {
               cell.innerHeight = 'auto'
@@ -350,10 +612,14 @@
               cell.syncComponentId = cell.syncComponent ? cell.syncComponent.pop() : ''
               cell.$menuId = item.uuid
               cell.$tabId = tabId
-              cell.$type = 'CustomPage'
+              cell.$view = 'CustomPage'
 
               if (cell.OpenType === 'funcbutton' && cell.funcType === 'print' && cell.verify) { // 鎵撳嵃鏈鸿缃�
                 cell = this.getPrinter(cell, item.uuid)
+              }
+              if (card.btnstyle) { // 鍏煎
+                card.style = card.style || {}
+                card.style = {...card.style, ...card.btnstyle}
               }
             } else if (['text', 'number', 'link'].includes(cell.eleType) && !cell.height && _hasheight) {
               cell.innerHeight = 'auto'
@@ -361,7 +627,7 @@
             return cell.eleType !== 'button' || isHS || permAction[cell.uuid]
           })
         })
-      } else if (item.type === 'table' && item.subtype === 'tablecard') {
+      } else if ((item.type === 'table' && item.subtype === 'tablecard') || item.type === 'carousel') {
         item.subcards.forEach(card => {
           let _hasheight = card.style.height && card.style.height !== 'auto'
           card.elements = card.elements.filter(cell => {
@@ -372,10 +638,15 @@
               cell.syncComponentId = cell.syncComponent ? cell.syncComponent.pop() : ''
               cell.$menuId = item.uuid
               cell.$tabId = tabId
-              cell.$type = 'CustomPage'
+              cell.$view = 'CustomPage'
 
               if (cell.OpenType === 'funcbutton' && cell.funcType === 'print' && cell.verify) { // 鎵撳嵃鏈鸿缃�
                 cell = this.getPrinter(cell, item.uuid)
+              }
+
+              if (card.btnstyle) { // 鍏煎
+                card.style = card.style || {}
+                card.style = {...card.style, ...card.btnstyle}
               }
             } else if (['text', 'number', 'link'].includes(cell.eleType) && !cell.height && _hasheight) {
               cell.innerHeight = 'auto'
@@ -393,10 +664,15 @@
             cell.syncComponentId = cell.syncComponent ? cell.syncComponent.pop() : ''
             cell.$menuId = item.uuid
             cell.$tabId = tabId
-            cell.$type = 'CustomPage'
+            cell.$view = 'CustomPage'
 
             if (cell.OpenType === 'funcbutton' && cell.funcType === 'print' && cell.verify) { // 鎵撳嵃鏈鸿缃�
               cell = this.getPrinter(cell, item.uuid)
+            }
+
+            if (cell.btnstyle) { // 鍏煎
+              cell.style = cell.style || {}
+              cell.style = {...cell.style, ...cell.btnstyle}
             }
 
             return isHS || permAction[cell.uuid]
@@ -442,48 +718,23 @@
     return item
   }
 
-  getCols = (cols, roleId, permMenus) => {
-    return cols.filter(col => {
-      if (col.blacklist && col.blacklist.filter(v => roleId.indexOf(v) > -1).length > 0) {
-        return false
-      } else if (col.Hide === 'true') {
-        return false
-      }
-      if (col.type === 'colspan') {
-        col.subcols = this.getCols(col.subcols || [], roleId, permMenus)
-        if (col.subcols.length === 0) {
-          return false
-        }
-      }
-
-      if (col.linkmenu && col.linkmenu.length > 0) {
-        let menu_id = col.linkmenu.pop()
-        col.linkThdMenu = permMenus.filter(m => m.MenuID === menu_id)[0] || ''
-      } else {
-        col.linkThdMenu = ''
-      }
-
-      return true
-    })
-  }
-
   // 鏍煎紡鍖栭粯璁よ缃�
-  formatSetting = (components, params, mainSearch, inherit) => {
+  formatSetting = (components, params, mainSearch, inherit, regs) => {
     return components.map(component => {
       if (component.type === 'tabs') {
         component.subtabs = component.subtabs.map(tab => {
-          tab.components = this.formatSetting(tab.components, [], [], inherit)
+          tab.components = this.formatSetting(tab.components, [], [], inherit, regs)
           tab = {...tab, ...inherit}
           return tab
         })
         return component
       } else if (component.type === 'group') {
-        component.components = this.formatSetting(component.components, [], [], inherit)
+        component.components = this.formatSetting(component.components, [], [], inherit, regs)
         component = {...component, ...inherit}
         return component
       }
 
-      if ((component.subtype === 'propcard' || component.subtype === 'brafteditor') && component.wrap.datatype === 'static') {
+      if (['propcard', 'brafteditor', 'sandbox', 'stepform'].includes(component.subtype) && component.wrap.datatype === 'static') {
         component.format = ''
       }
 
@@ -504,7 +755,7 @@
         }
       })
       delete component.scripts
-
+      component.setting.$name = component.name || ''
       component.setting.execute = component.setting.execute !== 'false'  // 榛樿sql鏄惁鎵ц锛岃浆涓篵oolean 缁熶竴鏍煎紡
       component.setting.laypage = component.setting.laypage === 'true'   // 鏄惁鍒嗛〉锛岃浆涓篵oolean 缁熶竴鏍煎紡
 
@@ -524,6 +775,11 @@
         component.setting.dataresource = component.setting.dataresource.replace(/@\$|\$@/ig, '')
         _customScript = _customScript.replace(/@\$|\$@/ig, '')
       }
+
+      regs.forEach(cell => {
+        component.setting.dataresource = component.setting.dataresource.replace(cell.reg, cell.value)
+        _customScript = _customScript.replace(cell.reg, cell.value)
+      })
 
       component.setting.customScript = _customScript // 鏁寸悊鍚庤嚜瀹氫箟鑴氭湰
 
@@ -597,8 +853,8 @@
 
     // 娴嬭瘯绯荤粺鎵撳嵃鏌ヨ璇彞
     if ((options.sysType === 'local' && !window.GLOB.systemType) || window.debugger === true) {
-      _customScript &&  console.info(`${_dataresource ? '' : '/*涓嶆墽琛岄粯璁ql*/\n'}${_customScript}`)
-      _dataresource &&  console.info(_dataresource)
+      _customScript &&  console.info(`${setting.$name ? `/*缁勪欢-${setting.$name} 鑷畾涔夎剼鏈�*/\n` : ''}${_dataresource ? '' : '/*涓嶆墽琛岄粯璁ql*/\n'}${_customScript}`)
+      _dataresource &&  console.info(`${setting.$name ? `/*缁勪欢-${setting.$name} 鏁版嵁婧�*/\n` : ''}` + _dataresource)
     }
 
     return {
@@ -622,6 +878,7 @@
     let diffUser = false
     let userName = sessionStorage.getItem('User_Name') || ''
     let fullName = sessionStorage.getItem('Full_Name') || ''
+    let city = sessionStorage.getItem('city') || ''
 
     if (sessionStorage.getItem('isEditState') === 'true') {
       userName = sessionStorage.getItem('CloudUserName') || ''
@@ -632,8 +889,8 @@
       let _script = item.script
 
       if (index === 0) {
-        _script = `declare @ErrorCode nvarchar(50),@retmsg nvarchar(4000),@UserName nvarchar(50),@FullName nvarchar(50)
-          select @ErrorCode='',@retmsg ='',@UserName='${userName}', @FullName='${fullName}'
+        _script = `declare @ErrorCode nvarchar(50),@retmsg nvarchar(4000),@UserName nvarchar(50),@FullName nvarchar(50),@login_city nvarchar(50)
+          select @ErrorCode='',@retmsg ='',@UserName='${userName}', @FullName='${fullName}', @login_city='${city}'
           ${_script}
         `
       }
@@ -785,6 +1042,24 @@
             <AntvPie config={item} data={data} BID={_bid} mainSearch={mainSearch} menuType={menuType} />
           </Col>
         )
+      } else if (item.type === 'scatter') {
+        return (
+          <Col span={item.width} key={item.uuid}>
+            <AntvScatter config={item} data={data} BID={_bid} mainSearch={mainSearch} menuType={menuType} />
+          </Col>
+        )
+      } else if (item.type === 'dashboard') {
+        return (
+          <Col span={item.width} key={item.uuid}>
+            <AntvDashboard config={item} data={data} BID={_bid} mainSearch={mainSearch} menuType={menuType} />
+          </Col>
+        )
+      } else if (item.type === 'form') {
+        return (
+          <Col span={item.width} key={item.uuid}>
+            <NormalForm config={item} data={data} BID={_bid} mainSearch={mainSearch} menuType={menuType} />
+          </Col>
+        )
       } else if (item.type === 'search') {
         return (
           <Col span={item.width} key={item.uuid}>
@@ -809,6 +1084,18 @@
             <PropCard config={item} data={data} BID={_bid} mainSearch={mainSearch} menuType={menuType} />
           </Col>
         )
+      } else if (item.type === 'carousel' && item.subtype === 'datacard') {
+        return (
+          <Col span={item.width} key={item.uuid}>
+            <CarouselDataCard config={item} data={data} BID={_bid} mainSearch={mainSearch} menuType={menuType} />
+          </Col>
+        )
+      } else if (item.type === 'carousel' && item.subtype === 'propcard') {
+        return (
+          <Col span={item.width} key={item.uuid}>
+            <CarouselPropCard config={item} data={data} BID={_bid} mainSearch={mainSearch} menuType={menuType} />
+          </Col>
+        )
       } else if (item.type === 'table' && item.subtype === 'tablecard') {
         return (
           <Col span={item.width} key={item.uuid}>
@@ -833,6 +1120,12 @@
             <BraftEditor config={item} data={data} BID={_bid} mainSearch={mainSearch} menuType={menuType} />
           </Col>
         )
+      } else if (item.type === 'code') {
+        return (
+          <Col span={item.width} key={item.uuid}>
+            <SandBox config={item} data={data} BID={_bid} mainSearch={mainSearch} menuType={menuType} />
+          </Col>
+        )
       } else {
         return null
       }

--
Gitblit v1.8.0