king
2021-05-08 6afdec0062dacbded57e166230eb22cc55ced0c1
src/tabviews/custom/index.jsx
@@ -21,8 +21,11 @@
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'))
@@ -136,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
@@ -153,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') { // 缓存继承
@@ -162,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,
@@ -436,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)
            }
          })
@@ -451,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
@@ -480,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
      }
      // 权限过滤
@@ -493,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'
@@ -519,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'
@@ -538,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'
@@ -560,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'
@@ -581,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]
@@ -630,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 (['propcard', 'brafteditor', 'sandbox'].includes(component.subtype) && component.wrap.datatype === 'static') {
      if (['propcard', 'brafteditor', 'sandbox', 'stepform'].includes(component.subtype) && component.wrap.datatype === 'static') {
        component.format = ''
      }
@@ -692,7 +755,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 统一格式
@@ -712,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 // 整理后自定义脚本
@@ -785,8 +853,8 @@
    // 测试系统打印查询语句
    if ((options.sysType === 'local' && !window.GLOB.systemType) || window.debugger === true) {
      _customScript &&  console.info(`${_dataresource ? '' : '/*不执行默认sql*/\n'}${_customScript}`)
      _dataresource &&  console.info(_dataresource)
      _customScript &&  console.info(`${setting.$name ? `/*组件-${setting.$name} 自定义脚本*/\n` : ''}${_dataresource ? '' : '/*不执行默认sql*/\n'}${_customScript}`)
      _dataresource &&  console.info(`${setting.$name ? `/*组件-${setting.$name} 数据源*/\n` : ''}` + _dataresource)
    }
    return {
@@ -810,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') || ''
@@ -820,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}
        `
      }
@@ -973,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}>