king
2023-07-12 238987f2d0765dd5d7f5978ed71793632c4eff5f
src/tabviews/custom/components/card/prop-card/index.jsx
@@ -1,7 +1,7 @@
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { is, fromJS } from 'immutable'
import { Spin, notification, Col, Row } from 'antd'
import { Spin, notification, Col, Row, Modal } from 'antd'
import Api from '@/api'
import UtilsDM from '@/utils/utils-datamanage.js'
@@ -31,10 +31,11 @@
    selected: 'false',
  }
  loaded = false
  UNSAFE_componentWillMount () {
    const { data, initdata } = this.props
    let _config = fromJS(this.props.config).toJS()
    let _cols = new Map()
    let _data = { $$empty: true }
    let _sync = false
@@ -60,13 +61,21 @@
          _data = _data[0] || {$$empty: true}
        }
        _sync = false
        this.loaded = true
      } else if (_sync && initdata) {
        _data = initdata
        if (Array.isArray(_data)) {
          _data = _data[0] || {$$empty: true}
        }
        _sync = false
        this.loaded = true
      }
    } else if (_config.wrap.datatype === 'public' && window.GLOB.CacheData.get(_config.wrap.publicId)) {
      _data = window.GLOB.CacheData.get(_config.wrap.publicId)
      _data = fromJS(_data).toJS()
      this.loaded = true
    } else if (_config.wrap.datatype === 'static') {
      this.loaded = true
    }
    _data.$$BID = BID || ''
@@ -74,11 +83,6 @@
    if (_config.setting.primaryKey) {
      _data.$$uuid = _data[_config.setting.primaryKey] || ''
    }
    _config.columns.forEach(item => {
      if (item.type !== 'number') return
      _cols.set(item.field, item)
    })
    _config.subcards.forEach(card => {
      if (card.setting.click === 'button' && !card.setting.linkbtn) {
@@ -91,18 +95,14 @@
          card.setting.click = ''
        }
      }
      card.elements = card.elements.map(item => {
        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.eleType === 'number' && item.field && _cols.has(item.field) && typeof(item.decimal) !== 'number') {
          item.decimal = _cols.get(item.field).decimal || 0
        }
        return item
      })
      if (card.style.clear === 'left') {
        card.wStyle = {clear: 'left'}
      } else if (card.style.clear === 'right') {
        card.wStyle = {float: 'right'}
      }
      delete card.style.clear
    })
    let selected = _config.wrap.selected || 'false'
@@ -112,6 +112,10 @@
    _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'}`
    if (_config.wrap.display === 'hidden') {
      _config.style.display = 'none'
    }
    this.setState({
      selected,
@@ -126,9 +130,30 @@
        setTimeout(() => {
          this.loadData()
        }, _config.setting.delay || 0)
      } else if (_config.wrap.datatype === 'public') {
        if (_data.$$loaded && selected !== 'false') {
          setTimeout(() => {
            this.checkTopLine()
          }, 200)
        }
      } else if (!_sync && selected !== 'false') {
        setTimeout(() => {
          this.checkTopLine()
        }, 200)
      }
      if (_config.wrap.datatype === 'dynamic' && this.loaded) {
        if (_config.wrap.goback === 'true' && _data.$$empty) {
          this.timer && this.timer.stop()
          MKEmitter.emit('closeTabView', _config.$pageId)
        } else {
          this.autoExec()
        }
      }
      if (_data.$$uuid) {
        setTimeout(() => {
          this.transferLine()
        }, 200)
      }
    })
@@ -140,11 +165,27 @@
    MKEmitter.addListener('reloadData', this.reloadData)
    MKEmitter.addListener('resetSelectLine', this.resetParentParam)
    MKEmitter.addListener('queryModuleParam', this.queryModuleParam)
    MKEmitter.addListener('refreshLineData', this.refreshLineData)
    MKEmitter.addListener('refreshByButtonResult', this.refreshByButtonResult)
    if (config.wrap.datatype === 'public') {
      MKEmitter.addListener('mkPublicData', this.mkPublicData)
    }
    if (config.timer && config.wrap.datatype === 'dynamic') {
      this.timer = new TimerTask()
      this.timer.init(config.uuid, config.timer, config.timerRepeats, () => {this.loadData(true)})
    }
    if (config.$cache && !this.loaded) {
      Api.getLCacheConfig(config.uuid).then(res => {
        if (!res || this.loaded) return
        let _data = res[0]
        _data.$$uuid = _data[config.setting.primaryKey] || ''
        this.setState({data: _data})
      })
    }
  }
@@ -157,15 +198,17 @@
      return
    }
    MKEmitter.removeListener('reloadData', this.reloadData)
    MKEmitter.removeListener('mkPublicData', this.mkPublicData)
    MKEmitter.removeListener('resetSelectLine', this.resetParentParam)
    MKEmitter.removeListener('queryModuleParam', this.queryModuleParam)
    MKEmitter.removeListener('refreshLineData', this.refreshLineData)
    MKEmitter.removeListener('refreshByButtonResult', this.refreshByButtonResult)
    this.timer && this.timer.stop()
  }
  /**
   * @description 图表数据更新,刷新内容
   * @description 数据更新,刷新内容
   */
  UNSAFE_componentWillReceiveProps (nextProps) {
    const { sync, config, BID, BData, selected } = this.state
@@ -183,18 +226,66 @@
      _data.$$BData = BData || ''
      _data.$$uuid = _data[config.setting.primaryKey] || ''
      this.loaded = true
      this.setState({sync: false, data: _data}, () => {
        if (selected !== 'false') {
          setTimeout(() => {
        if (config.wrap.goback === 'true' && _data.$$empty) {
          this.timer && this.timer.stop()
          MKEmitter.emit('closeTabView', config.$pageId)
        } else {
          if (selected !== 'false') {
            this.checkTopLine()
          }, 200)
          } else if (_data.$$uuid) {
            this.transferLine()
          }
          this.autoExec()
        }
      })
    } else if ( config.setting.syncRefresh && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) {
    } else if (config.setting.useMSearch && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) {
      this.setState({}, () => {
        this.loadData()
      })
    }
  }
  mkPublicData = (publicId, data) => {
    const { config, selected, BID, BData } = this.state
    if (config.wrap.datatype === 'public' && config.wrap.publicId === publicId) {
      let _data = fromJS(data).toJS()
      _data.$$BID = BID || ''
      _data.$$BData = BData || ''
      _data.$$uuid = _data[config.setting.primaryKey] || ''
      this.loaded = true
      this.setState({data: _data}, () => {
        if (config.wrap.goback === 'true' && _data.$$empty) {
          this.timer && this.timer.stop()
          MKEmitter.emit('closeTabView', config.$pageId)
        } else {
          if (selected !== 'false') {
            this.checkTopLine()
          } else {
            this.transferLine()
          }
          this.autoExec()
        }
      })
    }
  }
  autoExec = () => {
    const { config, data } = this.state
    if (!config.wrap.autoExec) return
    setTimeout(() => {
      MKEmitter.emit('triggerBtnId', config.wrap.autoExec, data.$$empty ? [] : [data])
    }, 200)
  }
  checkTopLine = () => {
@@ -215,6 +306,14 @@
    MKEmitter.emit('resetSelectLine', config.uuid, primaryId, data)
  }
  transferLine = () => {
    const { config, data } = this.state
    if (config.wrap.cardType) return
    MKEmitter.emit('resetSelectLine', config.uuid, data.$$uuid || '', data)
  }
  /**
   * @description 按钮执行完成后页面刷新
   * @param {*} menuId     // 菜单Id
@@ -231,10 +330,19 @@
    } else {
      this.loadData()
    }
  }
    if (position === 'popclose') { // 执行启动弹窗的按钮所选择的刷新项
      btn.$tabId && MKEmitter.emit('refreshPopButton', btn.$tabId)
    }
  refreshLineData = (menuId, btn, uuid, count) => {
    const { config, data } = this.state
    if (config.uuid !== menuId) return
    let _data = fromJS(data).toJS()
    _data[btn.field] = count
    this.setState({
      data: _data
    })
  }
  resetParentParam = (MenuID, id, data) => {
@@ -280,6 +388,11 @@
    const { mainSearch } = this.props
    const { config, arr_field, BID, BData, selected } = this.state
    if (config.wrap.datatype === 'public') {
      MKEmitter.emit('reloadData', config.wrap.publicId)
      return
    }
    if (config.wrap.datatype === 'static') {
      this.setState({
        data: {$$BID: BID || '', $$BData: BData, $$empty: true},
@@ -289,6 +402,7 @@
      this.setState({
        data: {$$BID: BID || '', $$BData: BData, $$empty: true},
      })
      this.loaded = true
      return
    }
@@ -312,6 +426,11 @@
    if (result.status) {
      let _data = {}
      this.loaded = true
      if (config.$cache && config.setting.onload !== 'false') {
        Api.writeCacheConfig(config.uuid, result.data || '')
      }
      if (!result.data || !result.data[0]) {
        _data.$$empty = true
      } else {
@@ -326,15 +445,37 @@
        data: _data,
        loading: false
      }, () => {
        if (selected !== 'false') {
          this.checkTopLine()
        if (config.wrap.goback === 'true' && _data.$$empty) {
          this.timer && this.timer.stop()
          MKEmitter.emit('closeTabView', config.$pageId)
        } else {
          if (selected !== 'false') {
            this.checkTopLine()
          } else {
            this.transferLine()
          }
          this.autoExec()
        }
      })
      if (config.timer && config.clearField) {
      if (config.timer && config.clearField && result.data && result.data[0]) {
        let vals = (config.clearValue || '').split(',')
        if (vals.includes(_data[config.clearField])) {
        if (vals.includes(result.data[0][config.clearField])) {
          this.timer && this.timer.stop()
        }
      }
      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
          })
        }
      }
    } else {
@@ -342,11 +483,19 @@
        loading: false
      })
      this.timer && this.timer.stop()
      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
        })
      }
    }
  }
@@ -385,14 +534,14 @@
        <NormalHeader config={config}/>
        <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 '
            let className = '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 className={className} key={index} style={item.wStyle} span={item.setting.width || 6} offset={item.offset || 0}>
                <CardItem card={item} cards={config} data={data} onClick={() => {this.changeCard(index, item)}}/>
              </Col>
            )
          })}