king
2023-06-25 5025901e459ae49d85210573ad38fb3f3c1d9230
src/tabviews/custom/components/chart/antv-pie/index.jsx
@@ -32,16 +32,16 @@
    title: '',                 // 组件标题
    sync: false,               // 是否统一请求数据
    plot: null,                // 图表设置
    data: null,                // 数据
    search: null,              // 搜索条件
    chart: null
  }
  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 = ''
@@ -56,11 +56,11 @@
      BID = BData.$BID || ''
    }
    if (config.setting.sync === 'true' && data) {
      _data = data[config.dataName] || []
    if (_sync && data) {
      this.data = data[config.dataName] || []
      _sync = false
    } else if (config.setting.sync === 'true' && initdata) {
      _data = initdata || []
    } else if (_sync && initdata) {
      this.data = initdata || []
      _sync = false
    }
@@ -83,7 +83,6 @@
    this.setState({
      config: _config,
      data: _data,
      BID: BID || '',
      arr_field: _config.columns.map(col => col.field).join(','),
      plot: _config.plot,
@@ -95,10 +94,12 @@
        setTimeout(() => {
          this.loadData()
        }, _config.setting.delay || 0)
      } else if (config.setting.sync === 'true' && _data) {
        this.handleData()
      }
    })
    if (this.data.length > 0) {
      this.handleData()
    }
  }
  /**
@@ -113,9 +114,12 @@
        _data = nextProps.data[config.dataName] || []
      }
      this.setState({sync: false, data: _data}, () => {
      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()
@@ -128,7 +132,7 @@
  }
  componentDidMount () {
    const { config } = this.state
    const { config, sync } = this.state
    MKEmitter.addListener('reloadData', this.reloadData)
    MKEmitter.addListener('resetSelectLine', this.resetParentParam)
@@ -137,6 +141,17 @@
      this.timer = new TimerTask()
      this.timer.init(config.uuid, config.timer, config.timerRepeats, () => {
        this.loadData(true)
      })
    }
    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()
        }
      })
    }
  }
@@ -174,12 +189,18 @@
  }
  handleData = () => {
    const { plot, chartId } = this.state
    let _element = document.getElementById(chartId)
    let _element = document.getElementById(this.state.chartId)
    if (_element) {
      _element.innerHTML = ''
    }
    setTimeout(() => {
      this.viewrender()
    }, 100)
  }
  viewrender = () => {
    const { plot } = this.state
    if (plot.shape === 'nest') {
      this.nestrender()
@@ -193,11 +214,10 @@
    const { config, arr_field, search, BID } = this.state
    if (config.setting.supModule && !BID) { // BID 不存在时,不做查询
      this.setState({
        data: []
      }, () => {
      if (!is(fromJS(this.data), fromJS([]))) {
        this.data = []
        this.handleData()
      })
      }
      return
    }
@@ -227,30 +247,50 @@
    let result = await Api.genericInterface(param)
    if (result.status) {
      let reset = true
      if (hastimer && is(fromJS(result.data), fromJS(this.state.data))) {
        reset = false
      if (config.$cache && config.setting.onload !== 'false') {
        Api.writeCacheConfig(config.uuid, result.data || '')
      }
      this.setState({
        data: result.data,
        loading: false
      }, () => {
        if (!reset) return
        this.handleData()
      })
      if (!is(fromJS(this.data), fromJS(result.data || []))) {
        this.data = result.data || []
        this.handleData()
      }
      if (config.timer && config.clearField && result.data && result.data[0]) {
        let vals = (config.clearValue || '').split(',')
        if (vals.includes(result.data[0][config.clearField])) {
          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
          })
        }
      }
    } else {
      this.setState({
        loading: false
      })
      this.timer && this.timer.stop()
      
      if (!result.message) return
      if (result.ErrCode === 'N') {
        Modal.error({
          title: result.message,
        })
      } else {
      } else if (result.ErrCode !== '-2') {
        notification.error({
          top: 92,
          message: result.message,
@@ -267,15 +307,15 @@
   * 3、柱状图数据补齐
   */
  getdata = () => {
    const { data, plot } = this.state
    const { plot } = this.state
    if (!data) {
    if (this.data.length === 0) {
      this.setState({empty: true})
      return []
    }
    let _data = []
    let _cdata = fromJS(data).toJS()
    let _cdata = fromJS(this.data).toJS()
    if (plot.repeat === 'average') {
      let _mdata = new Map()
@@ -360,15 +400,15 @@
  }
  getnestdata = () => {
    const { data, plot } = this.state
    const { plot } = this.state
    if (!data) {
    if (this.data.length === 0) {
      this.setState({empty: true})
      return []
    }
    let _data = []
    let _cdata = fromJS(data).toJS()
    let _cdata = fromJS(this.data).toJS()
    if (plot.repeat === 'average') {
      let _mdata = new Map()