king
2023-01-17 474c68f0fea10cc62977c67d186732b3346cdd53
src/tabviews/custom/components/chart/antv-G6/index.jsx
@@ -804,7 +804,6 @@
  state = {
    config: null,
    data: null,
    BID: '',
    BData: '',
    plot: null,
@@ -814,11 +813,12 @@
    empty: true
  }
  data = []
  UNSAFE_componentWillMount () {
    const { config, data, initdata } = this.props
    let _config = fromJS(config).toJS()
    let _data = null
    let _sync = _config.setting.sync === 'true'
    let BID = ''
@@ -834,10 +834,10 @@
    }
    if (_sync && data) {
      _data = data[config.dataName] || []
      this.data = data[config.dataName] || []
      _sync = false
    } else if (_sync && initdata) {
      _data = initdata || []
      this.data = initdata || []
      _sync = false
    }
@@ -850,7 +850,6 @@
    this.setState({
      config: _config,
      data: _data,
      BID: BID || '',
      BData: BData || '',
      arr_field: _config.columns.map(col => col.field).join(','),
@@ -861,44 +860,13 @@
        setTimeout(() => {
          this.loadData()
        }, _config.setting.delay || 0)
      } else if (config.setting.sync === 'true' && _data) {
        this.handleData()
      }
    })
  }
  /**
   * @description 图表数据更新,刷新内容
   */
  UNSAFE_componentWillReceiveProps (nextProps) {
    const { sync, config } = this.state
    if (sync && !is(fromJS(this.props.data), fromJS(nextProps.data))) {
      let _data = []
      if (nextProps.data && nextProps.data[config.dataName]) {
        _data = nextProps.data[config.dataName]
      }
      this.setState({sync: false, data: _data}, () => {
        this.handleData()
      })
    } else if (config.setting.useMSearch && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) {
      this.setState({}, () => {
        this.loadData()
      })
    if (this.data.length > 0) {
      this.handleData()
    }
  }
  shouldComponentUpdate (nextProps, nextState) {
    return !is(fromJS(this.state), fromJS(nextState))
  }
  componentDidMount () {
    const { config } = this.state
    MKEmitter.addListener('reloadData', this.reloadData)
    MKEmitter.addListener('resetSelectLine', this.resetParentParam)
    let that = this
    if (config.plot.subtype === 'mindmap') {
@@ -1028,6 +996,53 @@
  }
  /**
   * @description 图表数据更新,刷新内容
   */
  UNSAFE_componentWillReceiveProps (nextProps) {
    const { sync, config } = this.state
    if (sync && !is(fromJS(this.props.data), fromJS(nextProps.data))) {
      let _data = []
      if (nextProps.data && nextProps.data[config.dataName]) {
        _data = nextProps.data[config.dataName]
      }
      if (!is(fromJS(this.data), fromJS(_data))) {
        this.data = _data
        this.handleData()
      }
      this.setState({sync: false})
    } else if (config.setting.useMSearch && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) {
      this.setState({}, () => {
        this.loadData()
      })
    }
  }
  shouldComponentUpdate (nextProps, nextState) {
    return !is(fromJS(this.state), fromJS(nextState))
  }
  componentDidMount () {
    const { config, sync } = this.state
    MKEmitter.addListener('reloadData', this.reloadData)
    MKEmitter.addListener('resetSelectLine', this.resetParentParam)
    if (config.$cache && (config.setting.sync !== 'true' || sync)) {
      Api.getLCacheConfig(config.uuid).then(res => {
        if (!res || this.data.length > 0) return
        if (!is(fromJS(this.data), fromJS(res))) {
          this.data = res
          this.handleData()
        }
      })
    }
  }
  /**
   * @description 组件销毁,清除state更新,清除快捷键设置
   */
  componentWillUnmount () {
@@ -1062,11 +1077,10 @@
    const { config, arr_field, BID } = this.state
    if (config.setting.supModule && !BID) { // BID 不存在时,不做查询
      this.setState({
        data: {}
      }, () => {
      if (!is(fromJS(this.data), fromJS([]))) {
        this.data = []
        this.handleData()
      })
      }
      return
    }
@@ -1086,14 +1100,18 @@
    let result = await Api.genericInterface(param)
    if (result.status) {
      let data = result.data || []
      if (config.$cache) {
        Api.writeCacheConfig(config.uuid, result.data || '')
      }
      this.setState({
        data,
        loading: false
      }, () => {
        this.handleData()
      })
      if (!is(fromJS(this.data), fromJS(result.data || []))) {
        this.data = result.data || []
        this.handleData()
      }
    } else {
      this.setState({
        loading: false
@@ -1114,7 +1132,7 @@
  }
  getdata = () => {
    const { plot, data, config, BData } = this.state
    const { plot, config, BData } = this.state
    
    let root = {
      label: 'Root',
@@ -1140,7 +1158,7 @@
    let _options = []
    let logMap = new Map()
    data.forEach(item => {
    this.data.forEach(item => {
      let pval = item[plot.parentField]
      let val = item[plot.valueField]
      let label = item[plot.labelField] || ''
@@ -1256,14 +1274,20 @@
  }
  handleData = () => {
    const { plot, data } = this.state
    let _element = document.getElementById(this.state.chartId)
    if (_element) {
      _element.innerHTML = ''
    }
    if (!data || data.length === 0) {
    setTimeout(() => {
      this.viewrender()
    }, 100)
  }
  viewrender = () => {
    const { plot } = this.state
    if (this.data.length === 0) {
      this.setState({empty: true})
    } else {
      this.setState({empty: false})