king
2024-03-29 deb2536eaaa559d6c8ec94f81afb94b6c7806b4d
src/tabviews/custom/components/chart/antv-G6/index.jsx
@@ -1,7 +1,7 @@
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { is, fromJS } from 'immutable'
import { Modal, notification, Spin, Empty } from 'antd'
import { Spin, Empty } from 'antd'
import G6 from '@antv/g6'
import Api from '@/api'
@@ -805,7 +805,6 @@
    BID: '',
    BData: '',
    plot: null,
    arr_field : '',
    chartId: Utils.getuuid(),
    empty: true
  }
@@ -831,18 +830,22 @@
      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)
    }
    _config.plot.height = Utils.getHeight(_config.plot.height)
@@ -856,19 +859,8 @@
      config: _config,
      BID: BID || '',
      BData: BData || '',
      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 (this.data.length > 0) {
      this.handleData()
    }
    
    let that = this
@@ -1015,16 +1007,7 @@
      MKEmitter.addListener('transferSyncData', this.transferSyncData)
    }
    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.initExec()
  }
  /**
@@ -1040,15 +1023,63 @@
    MKEmitter.removeListener('transferSyncData', this.transferSyncData)
  }
  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()
          })
        } 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()
          })
        }
        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))) {
@@ -1092,8 +1123,8 @@
    }
  }
  async loadData () {
    const { config, arr_field, BID } = this.state
  async loadData (type) {
    const { config, BID } = this.state
    if (config.setting.supModule && !BID) { // BID 不存在时,不做查询
      if (!is(fromJS(this.data), fromJS([]))) {
@@ -1118,12 +1149,12 @@
    })
    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
@@ -1136,36 +1167,14 @@
        this.data = result.data || []
        this.handleData()
      }
      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
      })
      
      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)
    }
  }
@@ -1629,34 +1638,32 @@
      if (!data) return
      
      let menuId = plot.menu.slice(-1)[0]
      let newtab = window.GLOB.mkThdMenus.filter(m => m.MenuID === menuId)[0]
      let menu = null
      if (!newtab && plot.MenuID) {
        newtab = {
      if (window.GLOB.mkThdMenus.has(menuId)) {
        menu = {...window.GLOB.mkThdMenus.get(menuId)}
      } else if (plot.MenuID) {
        menu = {
          MenuID: plot.MenuID,
          MenuName: plot.MenuName,
          MenuNo: plot.MenuNo,
          type: plot.tabType
        }
      } else if (!newtab) {
        return
      }
      newtab = {
        ...newtab,
        param: {}
      }
      if (!menu) return
      menu.param = {}
      if (plot.joint === 'true') {
        newtab.param.$BID = data.$$uuid || ''
        menu.param.$BID = data.$$uuid || ''
        Object.keys(data).forEach(key => {
          if (/^\$/.test(key)) return
          newtab.param[key] = data[key]
          menu.param[key] = data[key]
        })
      }
      MKEmitter.emit('modifyTabs', newtab, true)
      MKEmitter.emit('modifyTabs', menu, true)
    } else {
      if (data) {
        this.selectedId = data.$$uuid || ''