From 78eed586f6a0d15162c89878c53a301e7b142a8a Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期一, 10 十月 2022 00:07:06 +0800
Subject: [PATCH] Merge branch 'master' into positec

---
 src/tabviews/custom/index.jsx |  368 +++++++++++++++++++---------------------------------
 1 files changed, 135 insertions(+), 233 deletions(-)

diff --git a/src/tabviews/custom/index.jsx b/src/tabviews/custom/index.jsx
index 6f41f64..2f6eafe 100644
--- a/src/tabviews/custom/index.jsx
+++ b/src/tabviews/custom/index.jsx
@@ -1,15 +1,13 @@
 import React, {Component} from 'react'
 import PropTypes from 'prop-types'
-import { connect } from 'react-redux'
 import { is, fromJS } from 'immutable'
 import { notification, Spin, Row, Col } from 'antd'
 
 import Api from '@/api'
-import options from '@/store/options.js'
 import zhCN from '@/locales/zh-CN/main.js'
 import enUS from '@/locales/en-US/main.js'
 import Utils from '@/utils/utils.js'
-import UtilsDM, { getStructuredParams, getStructDefaultParam } from '@/utils/utils-datamanage.js'
+import { getStructuredParams, getStructDefaultParam } from '@/utils/utils-datamanage.js'
 import asyncComponent from '@/utils/asyncComponent'
 import MKEmitter from '@/utils/events.js'
 import NotFount from '@/components/404'
@@ -42,6 +40,8 @@
 const CustomChart = asyncComponent(() => import('./components/chart/custom-chart'))
 const TimeLine = asyncComponent(() => import('./components/timeline/normal-timeline'))
 const Voucher = asyncComponent(() => import('./components/module/voucher'))
+const DebugTable = asyncComponent(() => import('@/tabviews/debugtable'))
+const MkInterfaces = asyncComponent(() => import('@/tabviews/custom/components/interfaces'))
 
 class CustomPage extends Component {
   static propTpyes = {
@@ -65,7 +65,6 @@
     data: null,           // 鍒楄〃鏁版嵁闆�
     loading: false,       // 鍒楄〃鏁版嵁鍔犺浇涓�
     visible: false,       // 鏍囩椤垫帶鍒�
-    treevisible: false,   // 鑿滃崟缁撴瀯鏍戝脊妗嗘樉绀洪殣钘忔帶鍒�
     shortcuts: null       // 蹇嵎閿�
   }
 
@@ -73,7 +72,7 @@
    * @description 鑾峰彇椤甸潰閰嶇疆淇℃伅
    */
   async loadconfig () {
-    const { permAction, MenuID } = this.props
+    const { MenuID } = this.props
 
     let _param = {
       func: 'sPC_Get_LongParam',
@@ -144,35 +143,6 @@
 
       window.GLOB.CacheData.set(MenuID, param)
 
-      config.components = this.filterComponent(config.components, roleId, permAction, balMap, skip, param, MenuID)
-      
-      // 鑾峰彇涓绘悳绱㈡潯浠�
-      let mainSearch = []
-      config.components.forEach(component => {
-        if (component.type !== 'search') return
-
-        component.search = component.search.map(item => {
-          item.oriInitval = item.initval
-          if (['text', 'select', 'link'].includes(item.type) && param.$searchkey === item.field) {
-            item.initval = param.$searchval
-          }
-
-          return item
-        })
-
-        mainSearch = Utils.initMainSearch(component.search)
-      })
-
-      let params = []
-      let BID = param.$BID || ''
-      let inherit = {}
-
-      if (config.cacheUseful === 'true') { // 缂撳瓨缁ф壙
-        inherit.cacheUseful = config.cacheUseful
-        inherit.timeUnit = config.timeUnit
-        inherit.cacheTime = config.cacheTime
-      }
-
       let userName = sessionStorage.getItem('User_Name') || ''
       let fullName = sessionStorage.getItem('Full_Name') || ''
 
@@ -202,6 +172,37 @@
         })
       }
 
+      config.interfaces = this.formatInterSetting(config.interfaces, regs)
+
+      config.components = this.filterComponent(config.components, roleId, window.GLOB.mkActions, balMap, skip, param, MenuID, config.interfaces)
+      
+      // 鑾峰彇涓绘悳绱㈡潯浠�
+      let mainSearch = []
+      config.components.forEach(component => {
+        if (component.type !== 'search') return
+
+        component.search = component.search.map(item => {
+          item.oriInitval = item.initval
+          if (['text', 'select', 'link'].includes(item.type) && param.$searchkey === item.field) {
+            item.initval = param.$searchval
+          }
+
+          return item
+        })
+
+        mainSearch = Utils.initMainSearch(component.search)
+      })
+
+      let params = []
+      let BID = param.$BID || ''
+      let inherit = {}
+
+      if (config.cacheUseful === 'true') { // 缂撳瓨缁ф壙
+        inherit.cacheUseful = config.cacheUseful
+        inherit.timeUnit = config.timeUnit
+        inherit.cacheTime = config.cacheTime
+      }
+
       config.components = this.formatSetting(config.components, params, mainSearch, inherit, regs, balMap)
 
       if ([...balMap.keys()].length > 0) {
@@ -210,11 +211,11 @@
 
       this.setState({
         BID: BID,
-        shortcuts,
+        shortcuts: shortcuts.length > 0 ? shortcuts : null,
         config,
         mainSearch
       }, () => {
-        if (!params || params.length === 0) {
+        if (params.length === 0) {
           setTimeout(() => { // 寤舵椂鍔犺浇鐘舵��
             this.setState({
               loadingview: false
@@ -227,8 +228,6 @@
         if (!this.props.Tab) {
           this.setShortcut()
         }
-
-        this.loadData()
       })
     } else {
       this.setState({
@@ -246,11 +245,6 @@
   setShortcut = () => {
     const { shortcuts } = this.state
 
-    if (!shortcuts || shortcuts.length === 0) {
-      document.onkeydown = () => {}
-      return
-    }
-
     document.onkeydown = (event) => {
       let e = event || window.event
       let keyCode = e.keyCode || e.which || e.charCode
@@ -265,8 +259,18 @@
       }
 
       if (!preKey || !keyCode) return
-
+      
       let _shortcut = `${preKey}+${keyCode}`
+
+      if (window.GLOB.breakpoint && _shortcut === 'ctrl+67') {
+        window.debugger = false
+        window.GLOB.breakpoint = false
+        sessionStorage.removeItem('breakpoint')
+        
+        MKEmitter.emit('debugChange')
+      }
+
+      if (!shortcuts) return
 
       shortcuts.some(item => {
         if (item.$shortcut === _shortcut) {
@@ -278,176 +282,7 @@
     }
   }
 
-  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
-      }
-
-      item.MenuName = config.MenuName || ''
-
-      inters.push(item)
-    })
-    
-    if (inters.length > 0) {
-      this.loadOutResource(inters)
-    }
-  }
-
-  loadOutResource = (inters) => {
-    let setting = inters.shift()
-    let param = UtilsDM.getPrevQueryParams(setting, [], this.state.BID)
-
-    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') {
-        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 {
-        if (Array.isArray(res)) {
-          res = { data: res }
-        }
-        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, this.state.BID)
-    } 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.debugger === true || (window.debugger === true && options.sysType !== 'cloud')) {
-        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, balMap, skip, urlparam, pageId) => {
+  filterComponent = (components, roleId, permAction, balMap, skip, urlparam, pageId, interfaces) => {
     return components.filter(item => {
       item.$pageId = pageId
       
@@ -533,7 +368,7 @@
         item.subtabs = item.subtabs.map(tab => {
           tab.$pageId = pageId
 
-          tab.components = this.filterComponent(tab.components, roleId, permAction, balMap, skip, urlparam, pageId)
+          tab.components = this.filterComponent(tab.components, roleId, permAction, balMap, skip, urlparam, pageId, interfaces)
           return tab
         })
 
@@ -546,7 +381,7 @@
           return false
         }
 
-        item.components = this.filterComponent(item.components, roleId, permAction, balMap, skip, urlparam, pageId)
+        item.components = this.filterComponent(item.components, roleId, permAction, balMap, skip, urlparam, pageId, interfaces)
 
         return true
       } else if (['pie', 'bar', 'line', 'dashboard', 'scatter', 'chart'].includes(item.type)) {
@@ -562,6 +397,15 @@
           item.wrap.blacklist.filter(v => roleId.indexOf(v) > -1).length > 0
         ) {
           return false
+        }
+
+        if (item.wrap.datatype === 'public') {
+          let inter = interfaces.filter(int => item.wrap.publicId === int.uuid)[0]
+          if (!inter) {
+            item.wrap.datatype = 'static'
+          } else {
+            item.setting = inter.setting
+          }
         }
       }
 
@@ -617,7 +461,7 @@
       
             if (col.linkmenu && col.linkmenu.length > 0) {
               let menu_id = col.linkmenu.pop()
-              col.linkThdMenu = this.props.permMenus.filter(m => m.MenuID === menu_id)[0] || ''
+              col.linkThdMenu = window.GLOB.mkThdMenus.filter(m => m.MenuID === menu_id)[0] || ''
             } else {
               col.linkThdMenu = ''
             }
@@ -996,6 +840,8 @@
         component.components = this.formatSetting(component.components, null, null, inherit, regs, balMap)
         component = {...component, ...inherit}
         return component
+      } else if (component.wrap && component.wrap.datatype === 'public') {
+        return component
       }
 
       if (component.setting) {
@@ -1092,6 +938,61 @@
     })
   }
 
+  // 鏍煎紡鍖栭粯璁よ缃�
+  formatInterSetting = (inters, regs) => {
+    if (!inters) return []
+
+    let interfaces = inters.filter(m => m.status === 'true')
+
+    let delay = 15
+    return interfaces.map(inter => {
+      inter.setting.delay = delay
+      delay += 15
+
+      if (inter.setting.interType !== 'system') return inter
+
+      let _customScript = ''
+      inter.scripts.forEach(script => {
+        if (script.status !== 'false') {
+          _customScript += `
+          ${script.sql}
+          `
+        }
+      })
+      delete inter.scripts
+
+      inter.setting.$name = '鍏叡鏁版嵁婧�-' + inter.setting.name
+      inter.setting.execute = inter.setting.execute !== 'false'
+      inter.setting.laypage = true
+
+      if (!inter.setting.execute) {
+        inter.setting.dataresource = ''
+      }
+      if (/\s/.test(inter.setting.dataresource)) {
+        inter.setting.dataresource = '(' + inter.setting.dataresource + ') tb'
+      }
+  
+      if (sessionStorage.getItem('dataM') === 'true') { // 鏁版嵁鏉冮檺
+        inter.setting.dataresource = inter.setting.dataresource.replace(/\$@/ig, '/*').replace(/@datam@/ig, '\'Y\'')
+        inter.setting.dataresource = inter.setting.dataresource.replace(/@\$/ig, '*/')
+        _customScript = _customScript.replace(/\$@/ig, '/*').replace(/@datam@/ig, '\'Y\'')
+        _customScript = _customScript.replace(/@\$/ig, '*/')
+      } else {
+        inter.setting.dataresource = inter.setting.dataresource.replace(/@\$|\$@/ig, '').replace(/@datam@/ig, '\'\'')
+        _customScript = _customScript.replace(/@\$|\$@/ig, '').replace(/@datam@/ig, '\'\'')
+      }
+
+      regs.forEach(cell => {
+        inter.setting.dataresource = inter.setting.dataresource.replace(cell.reg, cell.value)
+        _customScript = _customScript.replace(cell.reg, cell.value)
+      })
+
+      inter.setting.customScript = _customScript // 鏁寸悊鍚庤嚜瀹氫箟鑴氭湰
+
+      return inter
+    })
+  }
+
   /**
    * @description 涓昏〃鏁版嵁鍔犺浇
    */ 
@@ -1151,6 +1052,7 @@
   }
 
   componentDidMount () {
+    MKEmitter.addListener('debugChange', this.debugChange)
     MKEmitter.addListener('reloadMenuView', this.reloadMenuView)
     MKEmitter.addListener('resetActiveMenu', this.resetActiveMenu)
   }
@@ -1162,11 +1064,21 @@
     this.setState = () => {
       return
     }
+    MKEmitter.removeListener('debugChange', this.debugChange)
     MKEmitter.removeListener('reloadMenuView', this.reloadMenuView)
     MKEmitter.removeListener('resetActiveMenu', this.resetActiveMenu)
 
     window.GLOB.CacheData.delete(this.props.MenuID)
-    this.deleteCache(this.state.config.components)
+    if (this.state.config) {
+      this.deleteCache(this.state.config.components)
+      this.state.config.interfaces.forEach(m => {
+        window.GLOB.CacheData.delete(m.uuid)
+      })
+    }
+  }
+
+  debugChange = () => {
+    this.setState({visible: !this.state.visible})
   }
 
   deleteCache = (components) => {
@@ -1360,30 +1272,20 @@
   }
 
   render() {
-    const { loadingview, viewlost, config, loading, shortcuts } = this.state
+    const { loadingview, viewlost, config, loading, shortcuts, BID } = this.state
 
     return (
       <div className={'custom-page-wrap ' + (loadingview || loading ? 'loading' : '')} id={this.state.ContainerId} style={config ? config.style : null}>
         {(loadingview || loading) ? <Spin className="view-spin" size="large" /> : null}
         <Row className="component-wrap">{this.getComponents()}</Row>
+        {config && config.interfaces.length > 0 ? <MkInterfaces BID={BID} interfaces={config.interfaces}/> : null}
+        {config && window.GLOB.breakpoint ? <DebugTable /> : null}
         {!window.GLOB.mkHS && window.GLOB.systemType !== 'production' ? <PagemsgComponent menu={{MenuName: this.props.MenuName, MenuNo: this.props.MenuNo}} config={config} dict={this.state.dict} /> : null}
-        {!window.GLOB.mkHS && shortcuts ? <SettingComponent config={config} dict={this.state.dict} shortcuts={shortcuts} permAction={this.props.permAction}/> : null}
+        {!window.GLOB.mkHS && config ? <SettingComponent config={config} dict={this.state.dict} shortcuts={shortcuts || []}/> : null}
         {viewlost ? <NotFount msg={this.state.lostmsg} /> : null}
       </div>
     )
   }
 }
 
-const mapStateToProps = (state) => {
-  return {
-    refreshTab: state.refreshTab,
-    permAction: state.permAction,
-    permMenus: state.permMenus
-  }
-}
-
-const mapDispatchToProps = () => {
-  return {}
-}
-
-export default connect(mapStateToProps, mapDispatchToProps)(CustomPage)
\ No newline at end of file
+export default CustomPage
\ No newline at end of file

--
Gitblit v1.8.0