king
2023-01-16 913ea012f420311d18cc875934bae6b4ce3b2d13
src/tabviews/custom/components/chart/custom-chart/index.jsx
@@ -28,14 +28,14 @@
    loading: false,            // 数据加载状态
    sync: false,               // 是否统一请求数据
    plot: null,                // 图表设置
    data: [],                  // 数据
    search: 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 = ''
@@ -50,11 +50,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
    }
@@ -63,8 +63,7 @@
    this.setState({
      config: _config,
      data: _data || [],
      empty: !_data || _data.length === 0,
      empty: this.data.length === 0,
      BID: BID || '',
      arr_field: _config.columns.map(col => col.field).join(','),
      plot: _config.plot,
@@ -75,10 +74,12 @@
        setTimeout(() => {
          this.loadData()
        }, _config.setting.delay || 0)
      } else if (config.setting.sync === 'true' && _data) {
        this.handleData()
      }
    })
    if (this.data.length > 0) {
      this.handleData()
    }
  }
  /**
@@ -93,11 +94,12 @@
        _data = nextProps.data[config.dataName] || []
      }
      this.setState({sync: false, data: _data, empty: _data.length === 0})
      if (!is(fromJS(this.state.data), fromJS(_data))) {
      if (!is(fromJS(this.data), fromJS(_data))) {
        this.data = _data
        this.handleData()
      }
      this.setState({sync: false, empty: _data.length === 0})
    } else if (config.setting.useMSearch && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) {
      this.setState({}, () => {
        this.loadData()
@@ -126,11 +128,13 @@
    if (config.$cache && (config.setting.sync !== 'true' || sync)) {
      Api.getLCacheConfig(config.uuid).then(res => {
        if (!res) return
        if (!res || this.data.length > 0) return
        this.setState({data: res, empty: false}, () => {
        if (!is(fromJS(this.data), fromJS(res))) {
          this.data = res
          this.handleData()
        })
        }
        this.setState({empty: false})
      })
    }
  }
@@ -227,10 +231,13 @@
    if (config.setting.supModule && !BID) { // BID 不存在时,不做查询
      this.setState({
        data: []
      }, () => {
        this.handleData()
        empty: true
      })
      if (!is(fromJS(this.data), fromJS([]))) {
        this.data = []
        this.handleData()
      }
      return
    }
@@ -265,12 +272,12 @@
      }
      this.setState({
        data: result.data,
        loading: false,
        empty: result.data.length === 0
        empty: !result.data || result.data.length === 0
      })
      if (!is(fromJS(this.state.data), fromJS(result.data || []))) {
      if (!is(fromJS(this.data), fromJS(result.data || []))) {
        this.data = result.data || []
        this.handleData()
      }
    } else {
@@ -305,7 +312,7 @@
   * @description 图表渲染分组
   */
  viewrender = () => {
    const { config, data } = this.state
    const { config } = this.state
    if (!config.plot.script) return
@@ -313,7 +320,7 @@
      try {
        // eslint-disable-next-line
        let func = new Function('Chart', 'DataSet', 'wrap', 'data', 'config', config.plot.script)
        func(Chart, DataSet, this.wrap, data, config)
        func(Chart, DataSet, this.wrap, this.data, config)
      } catch (e) {
        console.warn(e)
  
@@ -327,7 +334,7 @@
      try {
        // eslint-disable-next-line
        let func = new Function('echarts', 'DataSet', 'wrap', 'data', 'config', config.plot.script)
        func(echarts, DataSet, this.wrap, data, config)
        func(echarts, DataSet, this.wrap, this.data, config)
      } catch (e) {
        console.warn(e)
  
@@ -358,7 +365,7 @@
            <Spin />
          </div> : null
        }
        <NormalHeader config={config} BID={BID} refresh={this.refreshSearch} />
        <NormalHeader config={config} BID={BID} refresh={this.refreshSearch}/>
        <div className="canvas-wrap" style={{height: (config.plot.height + 30) + 'px'}}>
          <div className={'canvas' + (empty ? ' empty' : '')} style={{height: config.plot.height + 'px'}} ref={ref => this.wrap = ref}></div>
        </div>