king
2024-05-09 a975aa770d1f5d0ae133f0e87a28b5d6b94734ef
src/tabviews/custom/components/chart/custom-chart/index.jsx
@@ -4,7 +4,7 @@
import { Chart } from '@antv/g2'
import DataSet from '@antv/data-set'
import * as echarts from 'echarts'
import { Spin, Empty, notification, Modal } from 'antd'
import { Spin, Empty, notification } from 'antd'
import Api from '@/api'
import Utils from '@/utils/utils.js'
@@ -50,38 +50,31 @@
    _config.plot.height = Utils.getHeight(_config.plot.height)
    _config.style.height = 'auto'
    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)
    }
    this.setState({
      config: _config,
      empty: this.data.length === 0,
      BID: BID || '',
      arr_field: _config.columns.map(col => col.field).join(','),
      plot: _config.plot,
      search: _config.$searches
    }, () => {
      if (config.setting.sync !== 'true' && config.setting.onload === 'true') {
        setTimeout(() => {
          this.loadData()
        }, _config.setting.delay || 0)
      }
    })
    if (this.data.length > 0) {
      this.handleData()
    }
  }
  shouldComponentUpdate (nextProps, nextState) {
@@ -107,21 +100,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
        if (!is(fromJS(this.data), fromJS(res))) {
          this.data = res
          this.handleData()
        }
        this.setState({empty: res.length > 0})
      })
    }
    this.initExec()
  }
  /**
@@ -141,15 +124,67 @@
    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
            this.handleData()
            this.setState({empty: res.data.length === 0})
          })
        } 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
            this.handleData()
            this.setState({empty: res.data.length === 0})
          })
        }
        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 (!is(fromJS(this.data), fromJS(_data))) {
@@ -187,8 +222,8 @@
    if (config.uuid !== menuId) return
    if ((position === 'mainline' || position === 'popclose') && config.setting.supModule && BID) { // 刷新源组件时,附带刷新上级行与当前组件
      MKEmitter.emit('reloadData', config.setting.supModule, BID)
    if (['mainline', 'maingrid', 'popclose'].includes(position) && config.setting.supModule) {
      MKEmitter.emit('reloadData', config.setting.supModule, position === 'maingrid' ? '' : BID)
    } else {
      this.loadData()
    }
@@ -217,7 +252,7 @@
   * @description 导出Excel时,获取页面搜索排序等参数
   */
  queryModuleParam = (menuId, callback) => {
    const { arr_field, config, search } = this.state
    const { config, search } = this.state
    if (config.uuid !== menuId) return
@@ -233,18 +268,16 @@
    }
    callback({
      arr_field: arr_field,
      orderBy: config.setting.order || '',
      search: searches,
      menuName: config.name
      search: searches
    })
  }
  /**
   * @description 数据加载
   */
  async loadData (hastimer) {
    const { config, arr_field, BID, search } = this.state
  async loadData (type) {
    const { config, BID, search } = this.state
    if (config.setting.supModule && !BID) { // BID 不存在时,不做查询
      this.setState({
@@ -275,19 +308,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
@@ -307,37 +340,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)
    }
  }