king
2023-08-14 cc20b3cfe18b36c7b0f75937f88679eb031ecc6f
src/tabviews/custom/components/chart/custom-chart/index.jsx
@@ -50,18 +50,22 @@
    _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())
        }
        _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({
@@ -71,17 +75,7 @@
      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 +101,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()
  }
  /**
@@ -139,6 +123,58 @@
    MKEmitter.removeListener('refreshByButtonResult', this.refreshByButtonResult)
    this.timer && this.timer.stop()
  }
  initExec = () => {
    const { config } = this.state
    if (config.$cache) {
      if (config.$time) {
        if (!this.loaded) {
          Api.getLCacheConfig(config.uuid, config.$time).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).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) => {
@@ -243,7 +279,7 @@
  /**
   * @description 数据加载
   */
  async loadData (hastimer) {
  async loadData (type) {
    const { config, arr_field, BID, search } = this.state
    if (config.setting.supModule && !BID) { // BID 不存在时,不做查询
@@ -275,7 +311,7 @@
      return
    }
    if (!hastimer) {
    if (type !== 'timer') {
      this.setState({
        loading: true
      })
@@ -286,7 +322,7 @@
    let result = await Api.genericInterface(param)
    if (result.status) {
      if (config.$cache && config.setting.onload !== 'false') {
      if (config.$cache && type === 'init') {
        Api.writeCacheConfig(config.uuid, result.data || [])
      }
      this.loaded = true