king
2025-01-24 e1cee96b38805bcccf48e7bcb9d296f2bc54c720
src/tabviews/custom/components/chart/antv-dashboard/index.jsx
@@ -2,8 +2,8 @@
import PropTypes from 'prop-types'
import { is, fromJS } from 'immutable'
import { Chart, registerShape } from '@antv/g2'
import { Spin, notification, Modal } from 'antd'
import { DownloadOutlined } from '@ant-design/icons'
import { Spin } from 'antd'
// import { DownloadOutlined } from '@ant-design/icons'
import moment from 'moment'
import Api from '@/api'
@@ -84,18 +84,24 @@
      BID = BData.$BID || ''
    }
    if (_config.setting.sync === 'true' && window.GLOB.SyncData.has(_config.dataName)) {
      this.data = window.GLOB.SyncData.get(_config.dataName) || []
    if (_config.setting.sync === 'true') {
      _config.setting.onload = 'false'
      if (_config.$cache) {
        Api.writeCacheConfig(_config.uuid, fromJS(this.data).toJS())
      if (window.GLOB.SyncData.has(_config.dataName)) {
        this.data = window.GLOB.SyncData.get(_config.dataName) || []
        if (_config.$cache) {
          Api.writeCacheConfig(_config.uuid, fromJS(this.data).toJS(), BID)
        }
        _config.setting.sync = 'false'
        this.loaded = true
        window.GLOB.SyncData.delete(_config.dataName)
      }
      _config.setting.sync = 'false'
      this.loaded = true
      window.GLOB.SyncData.delete(_config.dataName)
    } else if (_config.setting.supModule && !BID) {
      _config.setting.onload = 'false'
    }
    if (_config.subtype !== 'ratioboard') {
@@ -116,19 +122,8 @@
    this.setState({
      config: _config,
      BID: BID || '',
      arr_field: _config.columns.map(col => col.field).join(','),
      plot: _config.plot
    }, () => {
      if (config.setting.sync !== 'true' && config.setting.onload === 'true') {
        setTimeout(() => {
          this.loadData()
        }, _config.setting.delay || 0)
      }
    })
    if (config.setting.sync === 'true' && this.loaded) {
      this.handleData()
    }
  }
  shouldComponentUpdate (nextProps, nextState) {
@@ -152,28 +147,11 @@
    if (config.timer) {
      this.timer = new TimerTask()
      this.timer.init(config.uuid, config.timer, config.timerRepeats, () => {
        this.loadData(true)
        this.loadData('timer')
      })
    }
    if (config.$cache && !this.loaded) {
      Api.getLCacheConfig(config.uuid).then(res => {
        if (!res || this.loaded) return
        let _data = null
        if (config.subtype === 'ratioboard') {
          _data = res
        } else {
          _data = res[0] || {}
          _data.value = _data[config.plot.valueField] || 0
        }
        if (!is(fromJS(this.data), fromJS(_data))) {
          this.data = _data
          this.handleData()
        }
      })
    }
    this.initExec()
  }
  /**
@@ -191,15 +169,79 @@
    this.timer && this.timer.stop()
  }
  initExec = () => {
    const { config, BID } = this.state
    if (config.$cache) {
      if (config.$time) {
        if (!this.loaded) {
          Api.getLCacheConfig(config.uuid, config.$time, BID).then(res => {
            if (!res.valid && config.setting.onload === 'true') {
              setTimeout(() => {
                this.loadData('init')
              }, config.setting.delay || 0)
            }
            if (!res.data || this.loaded) return
            this.data = res.data
            if (config.subtype !== 'ratioboard') {
              if (Array.isArray(this.data)) {
                this.data = this.data[0] || {}
              }
              this.data.value = this.data[config.plot.valueField] || 0
            }
            this.handleData()
          })
        } else {
          this.handleData()
        }
      } else {
        if (!this.loaded) {
          Api.getLCacheConfig(config.uuid, 0, BID).then(res => {
            if (!res.data || this.loaded) return
            this.data = res.data
            if (config.subtype !== 'ratioboard') {
              if (Array.isArray(this.data)) {
                this.data = this.data[0] || {}
              }
              this.data.value = this.data[config.plot.valueField] || 0
            }
            this.handleData()
          })
        }
        if (config.setting.onload === 'true') {
          setTimeout(() => {
            this.loadData('init')
          }, config.setting.delay || 0)
        } else if (this.loaded) {
          this.handleData()
        }
      }
    } else if (config.setting.onload === 'true') {
      setTimeout(() => {
        this.loadData()
      }, config.setting.delay || 0)
    } else if (this.loaded) {
      this.handleData()
    }
  }
  transferSyncData = (syncId) => {
    const { config } = this.state
    const { config, BID } = this.state
    if (config.$syncId !== syncId) return
    let _data = window.GLOB.SyncData.get(config.dataName) || []
    if (config.$cache) {
      Api.writeCacheConfig(config.uuid, fromJS(_data).toJS())
      Api.writeCacheConfig(config.uuid, fromJS(_data).toJS(), BID)
    }
    if (config.subtype !== 'ratioboard') {
@@ -209,10 +251,8 @@
      _data.value = _data[config.plot.valueField] || 0
    }
    if (!is(fromJS(this.data), fromJS(_data))) {
      this.data = _data
      this.handleData()
    }
    this.data = _data
    this.handleData()
    this.loaded = true
@@ -261,8 +301,8 @@
    }, 100)
  }
  async loadData (hastimer) {
    const { config, arr_field, BID } = this.state
  async loadData (type) {
    const { config, BID } = this.state
    if (config.setting.supModule && !BID) { // BID 不存在时,不做查询
      let _data = null
@@ -290,19 +330,19 @@
      return
    }
    if (!hastimer) {
    if (type !== 'timer') {
      this.setState({
        loading: true
      })
    }
    let _orderBy = config.setting.order || ''
    let param = UtilsDM.getQueryDataParams(config.setting, arr_field, searches, _orderBy, '', '', BID)
    let param = UtilsDM.getQueryDataParams(config.setting, searches, _orderBy, '', '', BID)
    let result = await Api.genericInterface(param)
    if (result.status) {
      if (config.$cache && config.setting.onload !== 'false') {
        Api.writeCacheConfig(config.uuid, result.data || [])
      if (config.$cache && type === 'init') {
        Api.writeCacheConfig(config.uuid, result.data || [], BID)
      }
      this.loaded = true
@@ -312,7 +352,7 @@
        _data = result.data || []
      } else {
        _data = result.data && result.data[0] ? result.data && result.data[0] : {}
        _data.value = _data.value[config.plot.valueField] || 0
        _data.value = _data[config.plot.valueField] || 0
      }
      if (!is(fromJS(this.data), fromJS(_data))) {
@@ -330,37 +370,15 @@
          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
          })
        }
      }
      UtilsDM.querySuccess(result)
    } else {
      this.setState({
        loading: false
      })
      this.timer && this.timer.stop()
      
      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
        })
      }
      UtilsDM.queryFail(result)
    }
  }
@@ -693,7 +711,7 @@
        }
        <NormalHeader config={config} />
        <div className="canvas-wrap">
          {config.plot.download === 'enable' && this.state.chart ? <DownloadOutlined onClick={this.downloadImage} className="system-color download"/> : null}
          {/* {config.plot.download === 'enable' && this.state.chart ? <DownloadOutlined onClick={this.downloadImage} className="system-color download"/> : null} */}
          <div className="canvas" id={this.state.chartId}></div>
        </div>
      </div>