king
2023-06-28 f07c42a322f41e14ef5b1bf8f2fd66fc5d338cdd
src/tabviews/custom/popview/index.jsx
@@ -1,7 +1,7 @@
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { is, fromJS } from 'immutable'
import { notification, Spin, Row, Col } from 'antd'
import { notification, Spin, Row, Col, Modal } from 'antd'
import Api from '@/api'
import zhCN from '@/locales/zh-CN/main.js'
@@ -20,6 +20,7 @@
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 DoubleDataCard = asyncComponent(() => import('../components/card/double-data-card'))
const SimpleForm = asyncComponent(() => import('../components/form/simple-form'))
const StepForm = asyncComponent(() => import('../components/form/step-form'))
const TabForm = asyncComponent(() => import('../components/form/tab-form'))
@@ -40,6 +41,7 @@
const Voucher = asyncComponent(() => import('../components/module/voucher'))
const Iframe = asyncComponent(() => import('../components/iframe'))
const AntvG6 = asyncComponent(() => import('../components/chart/antv-G6'))
const AntvX6 = asyncComponent(() => import('../components/chart/antv-X6'))
class CustomPage extends Component {
  static propTpyes = {
@@ -96,7 +98,7 @@
    // 数据缓存设置
    if (config.cacheUseful === 'true') {
      if (!['day', 'hour'].includes(config.timeUnit)) {
      if (!['day', 'hour', 'minute'].includes(config.timeUnit)) {
        config.timeUnit = 'day'
      }
      config.cacheTime = config.cacheTime || 1
@@ -129,7 +131,9 @@
      })
    }
    config.components = this.filterComponent(config.components, roleId, balMap, param, Tab)
    config.$cache = config.cacheLocal === 'true'
    config.components = this.filterComponent(config.components, roleId, balMap, param, Tab, config.$cache)
    
    // 获取主搜索条件
    let mainSearch = []
@@ -175,9 +179,10 @@
    })
  }
  filterComponent = (components, roleId, balMap, urlparam, Tab) => {
  filterComponent = (components, roleId, balMap, urlparam, Tab, cache) => {
    return components.filter(item => {
      item.$pageId = Tab.uuid
      item.$cache = cache
      
      if (item.style && item.style.boxShadow) {
        delete item.style.hShadow
@@ -261,7 +266,7 @@
        item.subtabs = item.subtabs.map(tab => {
          tab.$pageId = Tab.uuid
          tab.components = this.filterComponent(tab.components, roleId, balMap, urlparam, Tab)
          tab.components = this.filterComponent(tab.components, roleId, balMap, urlparam, Tab, cache)
          return tab
        })
@@ -274,7 +279,7 @@
          return false
        }
        item.components = this.filterComponent(item.components, roleId, balMap, urlparam, Tab)
        item.components = this.filterComponent(item.components, roleId, balMap, urlparam, Tab, cache)
        return true
      } else if (['pie', 'bar', 'line', 'dashboard', 'scatter', 'chart'].includes(item.type)) {
@@ -298,6 +303,29 @@
        item.search = Utils.initSearchVal(item.search)
      }
      if (item.wrap && item.wrap.supType === 'multi') { // 数据卡多上级组件
        item.setting.supModule = item.supNodes[0].componentId
      } else if (item.setting && item.setting.supModule && typeof(item.setting.supModule) !== 'string') {
        let pid = item.setting.supModule.pop()
        if (pid && pid !== 'empty') {
          item.setting.supModule = pid
        } else {
          item.setting.supModule = ''
        }
      }
      // 权限过滤
      if (item.action && item.action.length > 0) {
        item.action = item.action.filter(cell => {
          if (cell.hidden === 'true' || cell.OpenType === 'popview') return false
          cell = this.resetButton(item, cell, Tab)
          cell.$toolbtn = true
          return true
        })
      }
      if (item.type === 'table') {
        let statFields = []
        let getCols = (cols) => {
@@ -306,6 +334,8 @@
              return false
            } else if (col.Hide === 'true') {
              return false
            } else if (col.type === 'action') {
              col.type = 'custom'
            }
            
            if (col.type === 'number') {
@@ -318,26 +348,31 @@
                  col.decimal = col.decimal > 2 ? col.decimal - 2 : 0
                }
              }
            } else if (col.type === 'formula') {
              if (typeof(col.decimal) === 'number') {
                col.round = Math.pow(10, col.decimal)
              }
            } 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', 'formula'].includes(cell.eleType)) {
                  if (!cell.height) {
                    cell.innerHeight = 'auto'
                  }
                  if (cell.eleType === 'number' && typeof(cell.decimal) === 'number') {
                    cell.round = Math.pow(10, cell.decimal)
                    if (cell.format === 'percent') {
                      cell.decimal = cell.decimal > 2 ? cell.decimal - 2 : 0
                    }
                  }
              col.elements = col.elements.filter(cell => {
                if (cell.eleType === 'button') {
                  if (cell.hidden === 'true' || cell.OpenType === 'popview') return false
                  cell = this.resetButton(item, cell, Tab)
                } else {
                  cell = this.resetElement(cell)
                }
                return cell
                return true
              })
              if (col.elements.length === 0) {
                return false
              }
            }
      
            if (col.linkmenu && col.linkmenu.length > 0) {
@@ -353,46 +388,20 @@
        
        item.cols = getCols(item.cols)
        item.statFields = statFields
      }
      let mutil = false
      if (item.wrap && item.wrap.supType === 'multi') { // 数据卡多上级组件
        mutil = true
        item.setting.supModule = item.supNodes[0].componentId
      } else if (item.setting && item.setting.supModule) {
        let pid = item.setting.supModule.pop()
        if (pid && pid !== 'empty') {
          item.setting.supModule = pid
        } else {
          item.setting.supModule = ''
        if (item.subtype === 'editable') {
          item.submit.logLabel = item.$menuname + '-提交'
          item.submit.$menuId = item.uuid
          item.submit.syncComponentId = item.submit.syncComponent ? (item.submit.syncComponent.pop() || '') : ''
          if (item.submit.syncComponentId && item.submit.syncComponentId === item.setting.supModule) {
            item.submit.syncComponentId = ''
            if (item.submit.execSuccess === 'grid') {
              item.submit.execSuccess = 'mainline'
            }
          }
        }
      }
      // 权限过滤
      if (item.action && item.action.length > 0) {
        item.action = item.action.filter(cell => {
          if (cell.hidden === 'true' || ['popview', 'funcbutton'].includes(cell.OpenType)) return false
          cell.logLabel = item.$menuname + '-' + cell.label
          cell.syncComponentId = cell.syncComponent ? (cell.syncComponent.pop() || '') : ''
          cell.$menuId = item.uuid
          cell.$tabId = Tab.uuid
          cell.$toolbtn = true
          if (!mutil && cell.syncComponentId === item.setting.supModule) {
            cell.syncComponentId = ''
          }
          if (cell.btnstyle) { // 兼容
            cell.style = cell.style || {}
            cell.style = {...cell.style, ...cell.btnstyle}
          }
          return true
        })
      }
      if (item.type === 'card' || item.type === 'carousel' || item.type === 'timeline') {
      } else if (item.type === 'card' || item.type === 'carousel' || item.type === 'timeline') {
        item.subcards && item.subcards.forEach(card => {
          if (card.style.boxShadow) {
            delete card.style.hShadow
@@ -403,66 +412,49 @@
          card.elements = card.elements.filter(cell => {
            if (cell.eleType === 'button') {
              if (cell.hidden === 'true' || ['popview', 'funcbutton'].includes(cell.OpenType)) return false
              if (cell.hidden === 'true' || cell.OpenType === 'popview') return false
              cell.logLabel = item.$menuname + '-' + cell.label
              cell.Ot = cell.Ot || 'requiredSgl'
              cell.syncComponentId = cell.syncComponent ? (cell.syncComponent.pop() || '') : ''
              cell.$menuId = item.uuid
              cell.$tabId = Tab.uuid
              if (!mutil && cell.syncComponentId === item.setting.supModule) {
                cell.syncComponentId = ''
              }
              if (card.btnstyle) { // 兼容
                card.style = card.style || {}
                card.style = {...card.style, ...card.btnstyle}
              }
            } else if (['text', 'number', 'formula'].includes(cell.eleType)) {
              if (!cell.height) {
                cell.innerHeight = 'auto'
              }
              if (cell.eleType === 'number' && typeof(cell.decimal) === 'number') {
                cell.round = Math.pow(10, cell.decimal)
                if (cell.format === 'percent') {
                  cell.decimal = cell.decimal > 2 ? cell.decimal - 2 : 0
                }
              }
              cell = this.resetButton(item, cell, Tab)
            } else {
              cell = this.resetElement(cell)
            }
            return true
          })
          if (card.setting.click === 'menus') {
            if (card.menus) {
              card.menus = card.menus.filter(m => !!m.MenuID)
              if (card.menus.length === 0) {
                card.menus = null
              }
            }
            if (!card.menus || item.subtype !== 'datacard' || card.$cardType === 'extendCard') {
              card.setting.click = ''
            }
          } else if (card.setting.click === 'menu') {
            if (!Array.isArray(card.setting.menu)) {
              card.setting.click = ''
            }
          }
          if (item.subtype === 'dualdatacard' && card.$cardType !== 'extendCard') {
            if (card.backSetting && card.backSetting.click === 'menu') {
              if (!Array.isArray(card.backSetting.menu)) {
                card.backSetting.click = ''
              }
            }
          }
          if (!card.backElements || card.backElements.length === 0) return
          card.backElements = card.backElements.filter(cell => {
            if (cell.eleType === 'button') {
              if (cell.hidden === 'true' || ['popview', 'funcbutton'].includes(cell.OpenType)) return false
              if (cell.hidden === 'true' || cell.OpenType === 'popview') return false
              cell.logLabel = item.$menuname + '-' + cell.label
              cell.Ot = cell.Ot || 'requiredSgl'
              cell.syncComponentId = cell.syncComponent ? (cell.syncComponent.pop() || '') : ''
              cell.$menuId = item.uuid
              cell.$tabId = Tab.uuid
              if (!mutil && cell.syncComponentId === item.setting.supModule) {
                cell.syncComponentId = ''
              }
              if (card.btnstyle) { // 兼容
                card.style = card.style || {}
                card.style = {...card.style, ...card.btnstyle}
              }
            } else if (['text', 'number', 'formula'].includes(cell.eleType)) {
              if (!cell.height) {
                cell.innerHeight = 'auto'
              }
              if (cell.eleType === 'number' && typeof(cell.decimal) === 'number') {
                cell.round = Math.pow(10, cell.decimal)
                if (cell.format === 'percent') {
                  cell.decimal = cell.decimal > 2 ? cell.decimal - 2 : 0
                }
              }
              cell = this.resetButton(item, cell, Tab)
            } else {
              cell = this.resetElement(cell)
            }
            return true
@@ -478,60 +470,15 @@
        }
        item.elements = item.elements.filter(cell => {
          if (cell.eleType === 'button') {
            if (cell.hidden === 'true' || ['popview', 'funcbutton'].includes(cell.OpenType)) return false
            if (cell.hidden === 'true' || cell.OpenType === 'popview') return false
            cell.logLabel = item.$menuname + '-' + cell.label
            cell.syncComponentId = cell.syncComponent ? (cell.syncComponent.pop() || '') : ''
            cell.$menuId = item.uuid
            cell.$tabId = Tab.uuid
            if (cell.syncComponentId === item.wrap.supModule) {
              cell.syncComponentId = ''
            }
          } else if (['text', 'number', 'formula'].includes(cell.eleType)) {
            if (!cell.height) {
              cell.innerHeight = 'auto'
            }
            if (cell.eleType === 'number' && typeof(cell.decimal) === 'number') {
              cell.round = Math.pow(10, cell.decimal)
              if (cell.format === 'percent') {
                cell.decimal = cell.decimal > 2 ? cell.decimal - 2 : 0
              }
            }
            cell = this.resetButton(item, cell, Tab)
          } else {
            cell = this.resetElement(cell)
          }
          return true
        })
      } else if (item.type === 'table') {
        item.cols = item.cols.filter(col => {
          if (col.type !== 'action') return true
          col.elements = col.elements.filter(cell => {
            if (cell.hidden === 'true' || ['popview', 'funcbutton'].includes(cell.OpenType)) return false
            cell.logLabel = item.$menuname + '-' + cell.label
            cell.Ot = cell.Ot || 'requiredSgl'
            cell.syncComponentId = cell.syncComponent ? (cell.syncComponent.pop() || '') : ''
            cell.$menuId = item.uuid
            cell.$tabId = Tab.uuid
            if (cell.syncComponentId === item.setting.supModule) {
              cell.syncComponentId = ''
            }
            if (cell.btnstyle) { // 兼容
              cell.style = cell.style || {}
              cell.style = {...cell.style, ...cell.btnstyle}
            }
            return true
          })
          return col.elements.length !== 0
        })
        if (item.subtype === 'editable') {
          item.submit.logLabel = item.$menuname + '-提交'
          item.submit.$menuId = item.uuid
        }
      } else if (item.type === 'form') {
        item.subcards = item.subcards.map(group => {
          group.subButton.uuid = group.uuid
@@ -545,30 +492,21 @@
            group.subButton.Ot = item.wrap.datatype === 'static' ? 'notRequired' : 'requiredSgl'
          }
          group.subButton.syncComponentId = group.subButton.syncComponent ? group.subButton.syncComponent.pop() : ''
          group.subButton.syncComponentId = group.subButton.syncComponent ? (group.subButton.syncComponent.pop() || '') : ''
          if (group.subButton.syncComponentId === item.setting.supModule) {
          if (group.subButton.syncComponentId && group.subButton.syncComponentId === item.setting.supModule) {
            group.subButton.syncComponentId = ''
            if (group.subButton.execSuccess === 'grid') {
              group.subButton.execSuccess = 'mainline'
            }
          }
          let _sql = `Declare @mk_organization nvarchar(512)  select @mk_organization='${sessionStorage.getItem('organization') || ''}'\n`
          let _sso = _sql
          let _local = _sql
          group.fields = group.fields.map(cell => {
            // 数据源sql语句,预处理,权限黑名单字段设置为隐藏表单
            if (['select', 'link', 'multiselect', 'radio', 'checkbox', 'checkcard'].includes(cell.type) && cell.resourceType === '1') {
              let _option = Utils.getSelectQueryOptions(cell)
              if (cell.database === 'sso') {
                cell.data_sql = Utils.formatOptions(_sso + _option.sql)
                _sso = ''
              } else {
                cell.data_sql = Utils.formatOptions(_local + _option.sql)
                _local = ''
              }
              cell.base_sql = window.btoa(window.encodeURIComponent(_sql + _option.sql))
              cell.base_sql = _option.sql
              cell.arr_field = _option.field
            }
      
@@ -625,6 +563,93 @@
      
      return true
    })
  }
  resetButton = (item, cell, Tab) => {
    cell.logLabel = item.$menuname + '-' + cell.label
    cell.Ot = cell.Ot || 'requiredSgl'
    cell.syncComponentId = cell.syncComponent ? (cell.syncComponent.pop() || '') : ''
    cell.$menuId = item.uuid
    cell.$MenuID = Tab.$MenuID
    cell.$tabId = Tab.uuid
    if (cell.btnstyle) { // 兼容
      cell.style = cell.style || {}
      cell.style = {...cell.style, ...cell.btnstyle}
    }
    if (cell.controlField) {
      if (/,/ig.test(cell.controlVal)) {
        cell.controlVals = cell.controlVal.split(',')
      } else {
        cell.controlVals = [(cell.controlVal || '')]
      }
    }
    if (cell.syncComponentId) {
      if (cell.syncComponentId === item.setting.supModule) {
        cell.syncComponentId = ''
        if (cell.execSuccess === 'line' || cell.execSuccess === 'grid') {
          cell.execSuccess = 'mainline'
        }
      } else if (cell.syncComponentId === 'multiComponent') {
        let ids = cell.syncComponents.map(m => {
          return m.syncComId.pop() || ''
        })
        if (item.setting.supModule && ids.includes(item.setting.supModule)) {
          if (cell.execSuccess === 'line' || cell.execSuccess === 'grid') {
            cell.execSuccess = 'mainline'
          }
          ids = ids.filter(id => id !== item.setting.supModule)
        }
        if (ids.length === 0) {
          cell.syncComponentId = ''
        } else {
          cell.syncComponentIds = ids
        }
      }
    }
    return cell
  }
  resetElement = (cell) => {
    cell.style = cell.style || {}
    if (['text', 'number', 'formula'].includes(cell.eleType)) {
      if (!cell.height) {
        cell.innerHeight = 'auto'
      }
      cell.innerHeight = cell.innerHeight || 'auto'
      cell.alignItems = cell.height > 1 ? cell.alignItems : ''
      if (cell.eleType === 'number' && typeof(cell.decimal) === 'number') {
        cell.round = Math.pow(10, cell.decimal)
        if (cell.format === 'percent') {
          cell.decimal = cell.decimal > 2 ? cell.decimal - 2 : 0
        }
      } else if (cell.type === 'formula' && typeof(cell.decimal) === 'number') {
        cell.round = Math.pow(10, cell.decimal)
      }
    } else if (cell.eleType === 'icon') {
      if (!cell.innerHeight) { // 兼容
        let fontSize = 14
        let lineHeight = 1.5
        if (cell.style.fontSize) {
          fontSize = parseInt(cell.style.fontSize)
        }
        if (cell.style.lineHeight) {
          lineHeight = parseFloat(cell.style.lineHeight)
        }
        cell.innerHeight = fontSize * lineHeight
      }
    }
    return cell
  }
  getPrinter = (item, parentId) => {
@@ -721,7 +746,7 @@
      // dataName 系统生成的数据源名称
      if (component.setting.sync === 'true') {
        component.dataName = Utils.getdataName()
        component.dataName = 'mk' + component.uuid.slice(-18)
      }
      // floor    组件的层级
@@ -766,16 +791,41 @@
   * @description 主表数据加载
   */ 
  loadmaindata = (params) => {
    let param = getStructuredParams(params, this.state.config, this.state.BID || '')
    const { config } = this.state
    let param = getStructuredParams(params, config, this.state.BID || '')
    this.setState({loading: true})
    Api.genericInterface(param).then(result => {
      if (result.status) {
        if (result.message) {
          if (result.ErrCode === 'Y') {
            Modal.success({
              title: result.message
            })
          } else if (result.ErrCode === 'S') {
            notification.success({
              top: 92,
              message: result.message,
              duration: 2
            })
          }
        }
        delete result.status
        delete result.message
        delete result.ErrMesg
        delete result.ErrCode
        if (config.$cache) {
          params.forEach((item) => {
            let _data = result[item.name] || ''
            if (_data && !Array.isArray(_data)) {
              _data = [_data]
            }
            Api.writeCacheConfig(item.uuid, _data)
          })
        }
        this.setState({
          data: result,
@@ -786,11 +836,19 @@
          data: '',
          loading: false
        })
        notification.error({
          top: 92,
          message: result.message,
          duration: 10
        })
        if (!result.message) return
        if (result.ErrCode === 'N') {
          Modal.error({
            title: result.message,
          })
        } else if (result.ErrCode !== '-2') {
          notification.error({
            top: 92,
            message: result.message,
            duration: 10
          })
        }
      }
    })
  }
@@ -860,6 +918,12 @@
        return (
          <Col span={item.width} style={style} key={item.uuid}>
            <PropCard config={item} data={data} mainSearch={mainSearch}/>
          </Col>
        )
      } else if (item.type === 'card' && item.subtype === 'dualdatacard') {
        return (
          <Col span={item.width} style={style} key={item.uuid}>
            <DoubleDataCard config={item} mainSearch={mainSearch}/>
          </Col>
        )
      } else if (item.type === 'table' && item.subtype === 'basetable') {
@@ -1012,6 +1076,12 @@
            <AntvG6 config={item} data={data} mainSearch={mainSearch}/>
          </Col>
        )
      } else if (item.type === 'antvX6') {
        return (
          <Col span={item.width} style={style} key={item.uuid}>
            <AntvX6 config={item}/>
          </Col>
        )
      } else {
        return null
      }
@@ -1023,7 +1093,7 @@
    return (
      <div className={'pop-page-wrap ' + (loading ? 'loading' : '')} style={config ? config.style : null}>
        {loading ? <Spin className="view-spin" size="large" /> : null}
        {loading && !config.$cache ? <Spin className="view-spin" size="large" /> : null}
        <Row className="component-wrap">{this.getComponents()}</Row>
        {viewlost ? <NotFount msg={this.state.lostmsg} /> : null}
      </div>