king
2021-07-28 137fb8ea6af2789b3238b22bac31d80bced41dfe
src/tabviews/custom/index.jsx
@@ -3,15 +3,13 @@
import { connect } from 'react-redux'
import { is, fromJS } from 'immutable'
import { notification, Spin, Row, Col } from 'antd'
import moment from 'moment'
import md5 from 'md5'
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 from '@/utils/utils-datamanage.js'
import UtilsDM, { getStructuredParams, getStructDefaultParam } from '@/utils/utils-datamanage.js'
import asyncComponent from '@/utils/asyncComponent'
import MKEmitter from '@/utils/events.js'
import NotFount from '@/components/404'
@@ -21,6 +19,8 @@
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'))
@@ -32,6 +32,8 @@
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 NormalTree = asyncComponent(() => import('./components/tree/antd-tree'))
const Balcony = asyncComponent(() => import('./components/card/balcony'))
const SettingComponent = asyncComponent(() => import('@/tabviews/zshare/settingcomponent'))
const PagemsgComponent = asyncComponent(() => import('@/tabviews/zshare/pageMessage'))
@@ -167,9 +169,9 @@
      }
      let regs = [
        { reg: /@userName@/ig, value: userName },
        { reg: /@fullName@/ig, value: fullName },
        { reg: /@login_city@/ig, value: city }
        { reg: /@userName@/ig, value: `'${userName}'` },
        { reg: /@fullName@/ig, value: `'${fullName}'` },
        { reg: /@login_city@/ig, value: `'${city}'` }
      ]
      
      if (window.GLOB.externalDatabase !== null) {
@@ -182,7 +184,7 @@
        config.urlFields.forEach(field => {
          let val = `'${param ? (param[field] || '') : ''}'`
          regs.push({
            reg: new RegExp(field, 'ig'),
            reg: new RegExp('@' + field + '@', 'ig'),
            value: val
          })
        })
@@ -336,7 +338,7 @@
    })
    Api.directRequest(url, setting.method, param, setting.cross).then(res => {
      if (typeof(res) !== 'object' || Array.isArray(res)) {
      if (typeof(res) !== 'object') {
        let error = '未知的返回结果!'
        if (typeof(res) === 'string') {
@@ -351,6 +353,9 @@
        this.customCallbackRequest(_result, setting, inters)
      } else {
        if (Array.isArray(res)) {
          res = { data: res }
        }
        res.mk_api_key = mkey
        this.customCallbackRequest(res, setting, inters)
      }
@@ -462,7 +467,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)
            }
          })
@@ -477,14 +482,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
@@ -492,21 +497,50 @@
          return false
        }
      }
      // 搜索黑名单过滤
      if (item.search && item.search.length > 0) {
        item.search = item.search.map(cell => {
          cell.oriInitval = cell.initval
          if (!cell.blacklist || cell.blacklist.length === 0) return cell
          if (cell.blacklist.filter(v => roleId.indexOf(v) > -1).length > 0) {
            cell.Hide = 'true'
      // 搜索条件初始化
      if (item.search && item.search.length > 0) {
        item.search = Utils.initSearchVal(item.search)
          }
          return item
      if (item.type === 'table' && item.subtype === 'normaltable') {
        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 (item.type === 'table' && item.subtype === 'normaltable') {
        item.cols = this.getCols(item.cols, roleId, permMenus)
            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
      }
      // 权限过滤
@@ -516,20 +550,26 @@
        item.action = item.action.filter(cell => {
          cell.logLabel = item.name + '-' + cell.label
          cell.ContainerId = this.state.ContainerId
          cell.syncComponentId = cell.syncComponent ? cell.syncComponent.pop() : ''
          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 => {
        item.subcards && item.subcards.forEach(card => {
          let _hasheight = card.style.height && card.style.height !== 'auto'
          if (card.style.shadow) { // 卡片阴影
@@ -542,13 +582,17 @@
              cell.logLabel = item.name + '-' + cell.label
              cell.Ot = 'requiredSgl'
              cell.ContainerId = this.state.ContainerId
              cell.syncComponentId = cell.syncComponent ? cell.syncComponent.pop() : ''
              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'
@@ -561,13 +605,17 @@
              cell.logLabel = item.name + '-' + cell.label
              cell.Ot = 'requiredSgl'
              cell.ContainerId = this.state.ContainerId
              cell.syncComponentId = cell.syncComponent ? cell.syncComponent.pop() : ''
              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'
@@ -575,21 +623,45 @@
            return cell.eleType !== 'button' || isHS || permAction[cell.uuid]
          })
        })
      } else if (item.type === 'balcony') {
        item.elements = item.elements.filter(cell => {
          if (cell.eleType === 'button') {
            cell.logLabel = item.name + '-' + cell.label
            cell.ContainerId = this.state.ContainerId
            cell.syncComponentId = cell.syncComponent ? (cell.syncComponent.pop() || '') : ''
            cell.$menuId = item.uuid
            cell.$tabId = tabId
            cell.$view = 'CustomPage'
            if (cell.OpenType === 'funcbutton' && cell.funcType === 'print' && cell.verify) { // 打印机设置
              cell = this.getPrinter(cell, item.uuid)
            }
          } else if (['text', 'number', 'link'].includes(cell.eleType) && !cell.height) {
            cell.innerHeight = 'auto'
          }
          return cell.eleType !== 'button' || isHS || permAction[cell.uuid]
        })
      } else if ((item.type === 'table' && item.subtype === 'tablecard') || item.type === 'carousel') {
        item.subcards.forEach(card => {
        item.subcards && item.subcards.forEach(card => {
          let _hasheight = card.style.height && card.style.height !== 'auto'
          card.elements = card.elements.filter(cell => {
            if (cell.eleType === 'button') {
              cell.logLabel = item.name + '-' + cell.label
              cell.Ot = 'requiredSgl'
              cell.ContainerId = this.state.ContainerId
              cell.syncComponentId = cell.syncComponent ? cell.syncComponent.pop() : ''
              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'
@@ -604,13 +676,18 @@
            cell.logLabel = item.name + '-' + cell.label
            cell.Ot = 'requiredSgl'
            cell.ContainerId = this.state.ContainerId
            cell.syncComponentId = cell.syncComponent ? cell.syncComponent.pop() : ''
            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]
@@ -656,31 +733,6 @@
    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, regs) => {
    return components.map(component => {
@@ -697,12 +749,19 @@
        return component
      }
      if (['propcard', 'brafteditor', 'sandbox', 'stepform'].includes(component.subtype) && component.wrap.datatype === 'static') {
        component.format = ''
      if (component.setting) {
        component.setting.useMSearch = component.setting.useMSearch === 'true'
        component.setting.syncRefresh = (component.setting.useMSearch && component.setting.syncRefresh === 'true')
      }
      if (!component.setting) return component // 不使用系统函数时
      if (!component.format) return component  // 没有动态数据  数据格式 array 或 object
      if (component.wrap && component.wrap.datatype === 'static') {
        component.format = ''
        component.setting = component.setting || {}
        component.setting.useMSearch = false
        component.setting.syncRefresh = false
      }
      if (!component.setting || !component.format) return component  // 1、不使用系统函数时;2、 没有动态数据  数据格式 array 或 object
      if (component.setting.interType !== 'system') { // 不使用系统函数时
        component.setting.sync = 'false'
        component.setting.laypage = component.setting.laypage === 'true'
@@ -718,7 +777,7 @@
        }
      })
      delete component.scripts
      component.setting.$name = component.name || ''
      component.setting.execute = component.setting.execute !== 'false'  // 默认sql是否执行,转为boolean 统一格式
      component.setting.laypage = component.setting.laypage === 'true'   // 是否分页,转为boolean 统一格式
@@ -750,8 +809,25 @@
      // dataName 系统生成的数据源名称
      // pageable 是否分页,组件属性,不分页的组件才可以统一查询
      if (component.floor === 1 && component.dataName && (!component.pageable || (component.pageable && !component.setting.laypage)) && component.setting.onload === 'true' && component.setting.sync === 'true') {
        let param = this.getDefaultParam(component, mainSearch)
        params.push(param)
        let searchlist = []
        if (component.search && component.search.length > 0) {
          searchlist = Utils.initMainSearch(component.search)
        }
        if (component.setting.useMSearch) {
          let keys = searchlist.map(item => item.key)
          mainSearch.forEach(item => {
            if (!keys.includes(item.key)) {
              searchlist.push(item)
            }
          })
        }
        if (searchlist.filter(item => item.required && item.value === '').length > 0) {
          component.setting.sync = 'false'
          component.setting.onload = 'false'
        } else {
          params.push(getStructDefaultParam(component, searchlist))
        }
      } else if (component.floor === 1) {
        component.setting.sync = 'false'
      }
@@ -761,138 +837,10 @@
  }
  /**
   * @description 获取系统存储过程 sPC_Get_TableData 的参数
   */
  getDefaultParam = (component, mainSearch) => {
    const { columns, search, setting, dataName, format } = component
    let searchlist = []
    if (search && search.length > 0) {
      searchlist = Utils.initMainSearch(search)
    }
    if (setting.useMSearch === 'true') {
      let keys = searchlist.map(item => item.key)
      mainSearch.forEach(item => {
        if (!keys.includes(item.key)) {
          searchlist.push(item)
        }
      })
    }
    let arr_field = columns.map(col => col.field)
    let _dataresource = setting.dataresource
    let _customScript = setting.customScript
    if (setting.queryType === 'statistics' || _customScript) {
      let allSearch = Utils.getAllSearchOptions(searchlist)
      let regoptions = allSearch.map(item => {
        return {
          reg: new RegExp('@' + item.key + '@', 'ig'),
          value: `'${item.value}'`
        }
      })
      regoptions.forEach(item => {
        if (_dataresource && setting.queryType === 'statistics') {
          _dataresource = _dataresource.replace(item.reg, item.value)
        }
        _customScript = _customScript.replace(item.reg, item.value)
      })
    }
    let _search = ''
    if (setting.queryType !== 'statistics' && _dataresource) {
      _search = Utils.joinMainSearchkey(searchlist)
      _search = _search ? 'where ' + _search : ''
    }
    if (setting.order && _dataresource) {
      _dataresource = `select top 1000 ${arr_field.join(',')} from (select ${arr_field.join(',')} ,ROW_NUMBER() over(order by ${setting.order}) as rows from ${_dataresource} ${_search}) tmptable order by tmptable.rows `
    } else if (_dataresource) {
      _dataresource = `select top 1000 ${arr_field.join(',')} from ${_dataresource} ${_search} `
    }
    // 测试系统打印查询语句
    if ((options.sysType === 'local' && !window.GLOB.systemType) || window.debugger === true) {
      _customScript &&  console.info(`${_dataresource ? '' : '/*不执行默认sql*/\n'}${_customScript}`)
      _dataresource &&  console.info(_dataresource)
    }
    return {
      name: dataName,
      columns: columns,
      par_tablename: '',
      type: format === 'array' ? format : '',
      primaryKey: setting.primaryKey || '',
      foreign_key: '',
      sql: _dataresource,
      script: _customScript
    }
  }
  /**
   * @description 主表数据加载
   */ 
  loadmaindata = (params) => {
    const { config } = this.state
    let LText_field = []
    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') || ''
      fullName = sessionStorage.getItem('CloudFullName') || ''
    }
    let _LText = params.map((item, index) => {
      let _script = item.script
      if (index === 0) {
        _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}
        `
      }
      if (!diffUser && (/@userid@/ig.test(item.sql) || /@userid@/ig.test(_script))) {
        diffUser = true
      }
      item.columns.forEach(cell => {
        LText_field.push(`Select '${item.name}' as tablename,'${cell.field}' as fieldname,'${cell.datatype}' as field_type`)
      })
      return `Select '${item.name}' as tablename,'${window.btoa(window.encodeURIComponent(item.sql))}' as LText,'${window.btoa(window.encodeURIComponent(_script))}' as Lcustomize,'${item.type}' as table_type,'${item.primaryKey}' as primary_key,'${item.par_tablename}' as par_tablename,'${item.foreign_key}' as foreign_key,'${index}' as Sort`
    })
    // 把大接口sPC_Get_structured_data的ltext拆成三份,第一段:@LText1,第二段@LText,第三段@LText2
    let param = {
      func: 'sPC_Get_structured_data',
      LText: _LText.join(' union all '),
      LText_field: LText_field.join(' union all '),
      BID: this.state.BID || ''
    }
    let { LText, LText1, LText2 } = Utils.sPCInUpDeFormatOptions(param.LText)
    param.LText1 = LText1
    param.LText = LText
    param.LText2 = LText2
    param.LText_field = Utils.formatOptions(param.LText_field)
    if (config.cacheUseful === 'true') {
      param.time_type = config.timeUnit
      param.time_limit = config.cacheTime
      if (diffUser) {
        param.userid = sessionStorage.getItem('UserID')
      }
      param.data_md5 = md5(JSON.stringify(param))
    }
    param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
    param.secretkey = Utils.encrypt(param.LText, param.timestamp)
    let param = getStructuredParams(params, this.state.config, this.state.BID)
    this.setState({loading: true, loadingview: false})
@@ -1005,6 +953,18 @@
            <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}>
@@ -1014,7 +974,7 @@
      } else if (item.type === 'search') {
        return (
          <Col span={item.width} key={item.uuid}>
            <MainSearch config={item} data={data} BID={_bid} mainSearch={mainSearch} menuType={menuType} refreshdata={this.resetSearch} />
            <MainSearch config={item} BID={BID} menuType={menuType} refreshdata={this.resetSearch} />
          </Col>
        )
      } else if (item.type === 'tabs') {
@@ -1033,6 +993,12 @@
        return (
          <Col span={item.width} key={item.uuid}>
            <PropCard config={item} data={data} BID={_bid} mainSearch={mainSearch} menuType={menuType} />
          </Col>
        )
      } else if (item.type === 'balcony') {
        return (
          <Col span={item.width} key={item.uuid}>
            <Balcony menu={config} config={item} data={data} BID={_bid} menuType={menuType} />
          </Col>
        )
      } else if (item.type === 'carousel' && item.subtype === 'datacard') {
@@ -1071,6 +1037,12 @@
            <BraftEditor config={item} data={data} BID={_bid} mainSearch={mainSearch} menuType={menuType} />
          </Col>
        )
      } else if (item.type === 'tree') {
        return (
          <Col span={item.width} key={item.uuid}>
            <NormalTree config={item} data={data} BID={_bid} mainSearch={mainSearch} menuType={menuType} />
          </Col>
        )
      } else if (item.type === 'code') {
        return (
          <Col span={item.width} key={item.uuid}>