king
2022-07-22 0c439ced2c97905cb2b02f5f689a37b19369fb8a
src/tabviews/custom/components/card/prop-card/index.jsx
@@ -20,7 +20,6 @@
    data: PropTypes.array,           // 统一查询数据
    config: PropTypes.object,        // 组件配置信息
    mainSearch: PropTypes.any,       // 外层搜索条件
    menuType: PropTypes.any,         // 菜单类型
  }
  state = {
@@ -31,7 +30,8 @@
    sync: false,               // 是否统一请求数据
    data: {},                  // 数据
    timer: null,               // 定时器时间间隔
    BData: ''
    BData: '',
    selected: 'false',
  }
  UNSAFE_componentWillMount () {
@@ -42,34 +42,35 @@
    let _data = { $$empty: true }
    let _sync = false
    
    if (_config.setting && _config.wrap.datatype !== 'static') {
    if (_config.wrap.datatype !== 'static') {
      _sync = _config.setting.sync === 'true'
      if (_sync && data) {
        _data = data[_config.dataName] || {}
        if (_data && Array.isArray(_data)) {
          _data = _data[0] || {}
        _data = data[_config.dataName] || {$$empty: true}
        if (Array.isArray(_data)) {
          _data = _data[0] || {$$empty: true}
        }
        _sync = false
      } else if (_sync && initdata) {
        _data = initdata || {}
        if (_data && Array.isArray(_data)) {
          _data = _data[0] || {}
        _data = initdata
        if (Array.isArray(_data)) {
          _data = _data[0] || {$$empty: true}
        }
        _sync = false
      }
    }
    if (_data) {
      _data.$$BID = BID || ''
      _data.$$BData = BData || ''
    _data.$$BID = BID || ''
    _data.$$BData = BData || ''
    if (_config.setting.primaryKey) {
      _data.$$uuid = _data[_config.setting.primaryKey] || ''
    }
    _config.columns.forEach(item => {
      if (item.type !== 'number') return
      _cols.set(item.field, item)
    })
    let _width = 0
    _config.subcards.forEach(card => {
      if (card.setting.click === 'button' && !card.setting.linkbtn) {
        card.elements.forEach(ele => {
@@ -81,37 +82,30 @@
          card.setting.click = ''
        }
      }
      _width += card.setting.width
      card.elements = card.elements.map(item => {
        if (item.field && _cols.has(item.field)) {
          item.col = _cols.get(item.field)
        if (item.eleType === 'number' && item.field && _cols.has(item.field) && typeof(item.decimal) !== 'number') {
          item.decimal = _cols.get(item.field).decimal || 0
        }
        return item
      })
      card.backElements = card.backElements.map(item => {
        if (item.field && _cols.has(item.field)) {
          item.col = _cols.get(item.field)
        if (item.eleType === 'number' && item.field && _cols.has(item.field) && typeof(item.decimal) !== 'number') {
          item.decimal = _cols.get(item.field).decimal || 0
        }
        return item
      })
    })
    let offset = 0
    if (_config.wrap.cardFloat && _config.wrap.cardFloat !== 'left' && _config.subcards[0] && _width < 24) {
      offset = 24 - _width
      if (_config.wrap.cardFloat === 'center') {
        offset = Math.floor(offset / 2)
      }
      _config.subcards[0].offset = offset
    }
    let selected = _config.wrap.selected || 'false'
    if (_config.subcards[0] && (_config.wrap.selected === 'always' || _config.wrap.selected === 'init')) {
      setTimeout(() => {
        this.checkTopLine()
      }, 200)
    }
    _config.wrap.selStyle = _config.wrap.selStyle || 'active'
    _config.wrap.priKeyType = _config.wrap.priKeyType || 'static'
    _config.wrap.scale = _config.wrap.scale === 'true' ? 'scale' : ''
    _config.wrap.wrapClass =  `${_config.wrap.selStyle} ${_config.wrap.cardType || ''} ${_config.wrap.scale || ''} ${_config.wrap.layout || 'grid'}-layout float-${_config.wrap.cardFloat || 'left'}`
    this.setState({
      selected,
      sync: _sync,
      data: _data,
      BID: BID || '',
@@ -119,8 +113,14 @@
      config: _config,
      arr_field: _config.columns.map(col => col.field).join(','),
    }, () => {
      if (_config.wrap.datatype !== 'static' && _config.setting && _config.setting.sync !== 'true' && _config.setting.onload === 'true') {
        this.loadData()
      if (_config.wrap.datatype !== 'static' && _config.setting.sync !== 'true' && _config.setting.onload === 'true') {
        setTimeout(() => {
          this.loadData()
        }, _config.setting.delay || 0)
      } else if ((!_sync || _config.wrap.priKeyType === 'static') && selected !== 'false') {
        setTimeout(() => {
          this.checkTopLine()
        }, 200)
      }
    })
  }
@@ -128,6 +128,7 @@
  componentDidMount () {
    MKEmitter.addListener('reloadData', this.reloadData)
    MKEmitter.addListener('resetSelectLine', this.resetParentParam)
    MKEmitter.addListener('queryModuleParam', this.queryModuleParam)
    MKEmitter.addListener('refreshByButtonResult', this.refreshByButtonResult)
    this.handleTimer()
  }
@@ -143,6 +144,7 @@
    }
    MKEmitter.removeListener('reloadData', this.reloadData)
    MKEmitter.removeListener('resetSelectLine', this.resetParentParam)
    MKEmitter.removeListener('queryModuleParam', this.queryModuleParam)
    MKEmitter.removeListener('refreshByButtonResult', this.refreshByButtonResult)
  }
@@ -150,23 +152,28 @@
   * @description 图表数据更新,刷新内容
   */
  UNSAFE_componentWillReceiveProps (nextProps) {
    const { sync, config, BID, BData } = this.state
    const { sync, config, BID, BData, selected } = this.state
    if (sync && !is(fromJS(this.props.data), fromJS(nextProps.data))) {
      let _data = { $$empty: true }
      if (nextProps.data && nextProps.data[config.dataName]) {
        _data = nextProps.data[config.dataName]
        if (_data && Array.isArray(_data)) {
          _data = _data[0]
        if (Array.isArray(_data)) {
          _data = _data[0] || {$$empty: true}
        }
      }
      if (_data) {
        _data.$$BID = BID || ''
        _data.$$BData = BData || ''
      }
      _data.$$BID = BID || ''
      _data.$$BData = BData || ''
      _data.$$uuid = _data[config.setting.primaryKey] || ''
      this.setState({sync: false, data: _data})
      this.setState({sync: false, data: _data}, () => {
        if (config.wrap.priKeyType !== 'static' && selected !== 'false') {
          setTimeout(() => {
            this.checkTopLine()
          }, 200)
        }
      })
    } else if ( config.setting.syncRefresh && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) {
      this.setState({}, () => {
        this.loadData()
@@ -175,13 +182,21 @@
  }
  checkTopLine = () => {
    const { config, data } = this.state
    const { config, data, selected } = this.state
    this.setState({
      activeKey: 0
      activeKey: 0,
      selected: selected === 'init' ? 'false' : selected
    })
    MKEmitter.emit('resetSelectLine', config.uuid, (config.subcards[0].setting.primaryId || ''), data)
    let primaryId = config.subcards[0].setting.primaryId || ''
    if (config.wrap.priKeyType === 'dynamic') {
      primaryId = data.$$uuid || ''
    } else if (config.wrap.priKeyType === 'joint') {
      primaryId = (data.$$uuid || '') + ',' + primaryId
    }
    MKEmitter.emit('resetSelectLine', config.uuid, primaryId, data)
  }
  handleTimer = () => {
@@ -245,16 +260,13 @@
    if (config.uuid !== menuId) return
    this.loadData()                                                            // 数据刷新
    if (btn.syncComponentId && btn.syncComponentId !== config.uuid && btn.syncComponentId !== config.setting.supModule) {
      MKEmitter.emit('reloadData', btn.syncComponentId)                        // 同级标签刷新
    if ((position === 'mainline' || position === 'popclose') && config.setting.supModule && BID) { // 刷新源组件时,附带刷新上级行与当前组件
      MKEmitter.emit('reloadData', config.setting.supModule, BID)
    } else {
      this.loadData()
    }
    if (position === 'mainline' && config.setting.supModule) {                 // 主表行刷新
      MKEmitter.emit('reloadData', config.setting.supModule, (BID || 'empty'))
    } else if (position === 'popclose') {                                      // 标签关闭刷新
      config.setting.supModule && MKEmitter.emit('reloadData', config.setting.supModule, (BID || 'empty'))
    if (position === 'popclose') { // 执行启动弹窗的按钮所选择的刷新项
      btn.$tabId && MKEmitter.emit('refreshPopButton', btn.$tabId)
    }
  }
@@ -262,12 +274,32 @@
  resetParentParam = (MenuID, id, data) => {
    const { config } = this.state
    if (!config.setting || !config.setting.supModule || config.setting.supModule !== MenuID) return
    if (!config.setting.supModule || config.setting.supModule !== MenuID) return
    if (id !== this.state.BID || id !== '') {
      this.setState({ BID: id, BData: data }, () => {
        this.loadData()
      })
    }
  }
  /**
   * @description 导出Excel时,获取页面搜索排序等参数
   */
  queryModuleParam = (menuId, btnId) => {
    const { mainSearch } = this.props
    const { config } = this.state
    if (config.uuid !== menuId) return
    let searches = config.setting.useMSearch && mainSearch ? mainSearch : []
    MKEmitter.emit('returnModuleParam', config.uuid, btnId, {
      arr_field: '',
      orderBy: '',
      search: searches,
      menuName: config.name
    })
  }
  reloadData = (menuId) => {
@@ -279,8 +311,8 @@
  }
  async loadData (hastimer) {
    const { mainSearch, menuType } = this.props
    const { config, arr_field, BID, BData } = this.state
    const { mainSearch } = this.props
    const { config, arr_field, BID, BData, selected } = this.state
    if (config.wrap.datatype === 'static') {
      this.setState({
@@ -308,7 +340,7 @@
    }
    let _orderBy = config.setting.order || ''
    let param = UtilsDM.getQueryDataParams(config.setting, arr_field, searches, _orderBy, 1, 1, BID, menuType)
    let param = UtilsDM.getQueryDataParams(config.setting, arr_field, searches, _orderBy, 1, 1, BID)
    let result = await Api.genericInterface(param)
    if (result.status) {
@@ -322,10 +354,15 @@
      _data.$$BID = BID || ''
      _data.$$BData = BData
      _data.$$uuid = _data[config.setting.primaryKey] || ''
      this.setState({
        data: _data,
        loading: false
      }, () => {
        if (config.wrap.priKeyType !== 'static' && selected !== 'false') {
          this.checkTopLine()
        }
      })
      if (config.timer && config.clearField) {
@@ -356,14 +393,23 @@
      activeKey: index
    })
    MKEmitter.emit('resetSelectLine', config.uuid, (item.setting.primaryId || ''), data)
    let primaryId = item.setting.primaryId || ''
    if (config.wrap.priKeyType === 'dynamic') {
      primaryId = data.$$uuid || ''
    } else if (config.wrap.priKeyType === 'joint') {
      primaryId = (data.$$uuid || '') + ',' + primaryId
    }
    MKEmitter.emit('resetSelectLine', config.uuid, primaryId, data)
  }
  render() {
    const { config, loading, data, activeKey } = this.state
    if (config.wrap.empty === 'hidden' && (!data || data.$$empty)) return null
    return (
      <div className="custom-prop-card-box" style={config.style}>
      <div className="custom-prop-card-box" id={'anchor' + config.uuid} style={config.style}>
        {loading ?
          <div className="loading-mask">
            <div className="ant-spin-blur"></div>
@@ -371,12 +417,19 @@
          </div> : null
        }
        <NormalHeader config={config}/>
        <Row className={`card-row-list ${config.wrap.cardType || ''} ${config.wrap.scale || ''}`}>
          {config.subcards.map((item, index) => (
            <Col className={(activeKey === index ? 'active' : '') + (item.setting.click ? ' pointer' : '')} key={index} span={item.setting.width || 6} offset={item.offset || 0} onClick={() => {this.changeCard(index, item)}}>
              <CardItem card={item} cards={config} data={data}/>
            </Col>
          ))}
        <Row className={`card-row-list data-zoom ${config.wrap.wrapClass}`}>
          {config.subcards.map((item, index) => {
            let className = item.setting.click ? 'mk-card pointer ' : 'mk-card '
            if (activeKey === index) {
              className += 'active'
            }
            return (
              <Col className={className} key={index} span={item.setting.width || 6} offset={item.offset || 0} onClick={() => {this.changeCard(index, item)}}>
                <CardItem card={item} cards={config} data={data}/>
              </Col>
            )
          })}
        </Row>
      </div>
    )