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,15 +56,21 @@
      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
    }
    _config.style.height = config.plot.height || 400
    _config.plot.height = Utils.getHeight(_config.plot.height)
    _config.style.height = 'auto'
    _config.style.minHeight = _config.plot.height + 30
    if (_config.plot.title) {
      _config.style.minHeight = _config.style.minHeight + 45
    }
    let decimal = 0
    _config.columns.forEach(col => {
@@ -77,7 +83,6 @@
    this.setState({
      config: _config,
      data: _data,
      BID: BID || '',
      arr_field: _config.columns.map(col => col.field).join(','),
      plot: _config.plot,
@@ -89,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()
    }
  }
  /**
@@ -107,10 +114,13 @@
        _data = nextProps.data[config.dataName] || []
      }
      this.setState({sync: false, data: _data}, () => {
      if (!is(fromJS(this.data), fromJS(_data))) {
        this.data = _data
        this.handleData()
      })
    } else if (config.setting.syncRefresh && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) {
      }
      this.setState({sync: false})
    } else if (config.setting.useMSearch && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) {
      this.setState({}, () => {
        this.loadData()
      })
@@ -122,7 +132,7 @@
  }
  componentDidMount () {
    const { config } = this.state
    const { config, sync } = this.state
    MKEmitter.addListener('reloadData', this.reloadData)
    MKEmitter.addListener('resetSelectLine', this.resetParentParam)
@@ -131,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()
        }
      })
    }
  }
@@ -168,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()
@@ -187,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
    }
@@ -221,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,
@@ -261,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()
@@ -354,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()
@@ -378,14 +424,15 @@
          return
        }
        let sign = item[plot.type] + item[plot.Xaxis]
        item.$type = item[plot.type]
        let sign = item.$type + item[plot.Xaxis]
        if (!_mdata.has(sign)) {
          let _sort = sort
          if (map.has(item.type)) {
            _sort = map.get(item.type)
          if (map.has(item.$type)) {
            _sort = map.get(item.$type)
          } else {
            map.set(item.type, _sort)
            map.set(item.$type, _sort)
            sort++
          }
@@ -421,14 +468,15 @@
          return
        }
        let sign = item[plot.type] + item[plot.Xaxis]
        item.$type = item[plot.type]
        let sign = item.$type + item[plot.Xaxis]
        if (!_mdata.has(sign)) {
          let _sort = sort
          if (map.has(item.type)) {
            _sort = map.get(item.type)
          if (map.has(item.$type)) {
            _sort = map.get(item.$type)
          } else {
            map.set(item.type, _sort)
            map.set(item.$type, _sort)
            sort++
          }
@@ -463,11 +511,13 @@
          }
        }
        item.$type = item[plot.type]
        let _sort = sort
        if (map.has(item.type)) {
          _sort = map.get(item.type)
        if (map.has(item.$type)) {
          _sort = map.get(item.$type)
        } else {
          map.set(item.type, _sort)
          map.set(item.$type, _sort)
          sort++
        }
@@ -535,7 +585,7 @@
    const chart = new Chart({
      container: chartId,
      autoFit: true,
      height: this.wrap.offsetHeight - 30,
      height: plot.height,
      padding: 0,
    })
@@ -731,7 +781,7 @@
    const chart = new Chart({
      container: chartId,
      autoFit: true,
      height: this.wrap.offsetHeight - 30
      height: plot.height
    })
    if (plot.shape !== 'nightingale' && plot.show !== 'value') {
@@ -956,11 +1006,7 @@
            }
          }
          if (['linkage_navigation', 'linkage', 'menu_board'].includes(window.GLOB.navBar)) {
            MKEmitter.emit('modifyTabs', newtab, 'replace')
          } else {
            MKEmitter.emit('modifyTabs', newtab, 'plus', true)
          }
          MKEmitter.emit('modifyTabs', newtab, true)
        } catch (e) {
          console.warn('菜单打开失败!')
        }
@@ -1039,7 +1085,7 @@
          </div> : null
        }
        <NormalHeader config={config} BID={BID} refresh={this.refreshSearch} />
        <div className="canvas-wrap" ref={ref => this.wrap = ref}>
        <div className="canvas-wrap">
          {config.plot.download === 'enable' && this.state.chart && !empty ? <DownloadOutlined onClick={this.downloadImage} className="system-color download"/> : null}
          <div className={'canvas' + (empty ? ' empty' : '')} id={this.state.chartId}></div>
        </div>