From 2f54651464414059b224181d713af2980e76d095 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期日, 09 十月 2022 19:35:39 +0800
Subject: [PATCH] 2020-10-09

---
 src/tabviews/custom/index.jsx |  319 ++++++++++++++++++----------------------------------
 1 files changed, 111 insertions(+), 208 deletions(-)

diff --git a/src/tabviews/custom/index.jsx b/src/tabviews/custom/index.jsx
index 4e1324e..2f6eafe 100644
--- a/src/tabviews/custom/index.jsx
+++ b/src/tabviews/custom/index.jsx
@@ -4,11 +4,10 @@
 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 +41,7 @@
 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 = {
@@ -143,35 +143,6 @@
 
       window.GLOB.CacheData.set(MenuID, param)
 
-      config.components = this.filterComponent(config.components, roleId, window.GLOB.mkActions, 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') || ''
 
@@ -201,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) {
@@ -213,7 +215,7 @@
         config,
         mainSearch
       }, () => {
-        if (!params || params.length === 0) {
+        if (params.length === 0) {
           setTimeout(() => { // 寤舵椂鍔犺浇鐘舵��
             this.setState({
               loadingview: false
@@ -226,8 +228,6 @@
         if (!this.props.Tab) {
           this.setShortcut()
         }
-
-        this.loadData()
       })
     } else {
       this.setState({
@@ -282,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
       
@@ -537,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
         })
 
@@ -550,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)) {
@@ -566,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
+          }
         }
       }
 
@@ -1000,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) {
@@ -1096,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 涓昏〃鏁版嵁鍔犺浇
    */ 
@@ -1172,7 +1069,12 @@
     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 = () => {
@@ -1370,12 +1272,13 @@
   }
 
   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 && config ? <SettingComponent config={config} dict={this.state.dict} shortcuts={shortcuts || []}/> : null}

--
Gitblit v1.8.0