king
2023-03-24 deab3ddf1990cd25b4692d1358ac9d50856644f0
src/tabviews/custom/components/card/prop-card/index.jsx
@@ -1,7 +1,7 @@
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { is, fromJS } from 'immutable'
import { Spin, notification, Col, Row } from 'antd'
import { Spin, notification, Col, Row, Modal } from 'antd'
import Api from '@/api'
import UtilsDM from '@/utils/utils-datamanage.js'
@@ -31,10 +31,11 @@
    selected: 'false',
  }
  loaded = false
  UNSAFE_componentWillMount () {
    const { data, initdata } = this.props
    let _config = fromJS(this.props.config).toJS()
    let _cols = new Map()
    let _data = { $$empty: true }
    let _sync = false
@@ -60,16 +61,21 @@
          _data = _data[0] || {$$empty: true}
        }
        _sync = false
        this.loaded = true
      } else if (_sync && initdata) {
        _data = initdata
        if (Array.isArray(_data)) {
          _data = _data[0] || {$$empty: true}
        }
        _sync = false
        this.loaded = true
      }
    } else if (_config.wrap.datatype === 'public' && window.GLOB.CacheData.get(_config.wrap.publicId)) {
      _data = window.GLOB.CacheData.get(_config.wrap.publicId)
      _data = fromJS(_data).toJS()
      this.loaded = true
    } else if (_config.wrap.datatype === 'static') {
      this.loaded = true
    }
    _data.$$BID = BID || ''
@@ -77,11 +83,6 @@
    if (_config.setting.primaryKey) {
      _data.$$uuid = _data[_config.setting.primaryKey] || ''
    }
    _config.columns.forEach(item => {
      if (item.type !== 'number') return
      _cols.set(item.field, item)
    })
    _config.subcards.forEach(card => {
      if (card.setting.click === 'button' && !card.setting.linkbtn) {
@@ -94,18 +95,6 @@
          card.setting.click = ''
        }
      }
      card.elements = card.elements.map(item => {
        if (item.eleType === 'number' && item.field && _cols.has(item.field) && typeof(item.decimal) !== 'number') {
          item.decimal = _cols.get(item.field).decimal || 0
        }
        return item
      })
      card.backElements = card.backElements.map(item => {
        if (item.eleType === 'number' && item.field && _cols.has(item.field) && typeof(item.decimal) !== 'number') {
          item.decimal = _cols.get(item.field).decimal || 0
        }
        return item
      })
    })
    let selected = _config.wrap.selected || 'false'
@@ -115,6 +104,10 @@
    _config.wrap.scale = _config.wrap.scale === 'true' ? 'scale' : ''
    _config.wrap.wrapClass =  `${_config.wrap.selStyle} ${_config.wrap.cardType || ''} ${_config.wrap.scale || ''} ${_config.wrap.layout || 'grid'}-layout float-${_config.wrap.cardFloat || 'left'}`
    if (_config.wrap.display === 'hidden') {
      _config.style.display = 'none'
    }
    this.setState({
      selected,
@@ -141,6 +134,9 @@
        }, 200)
      }
      if (_config.wrap.datatype === 'dynamic' && this.loaded) {
        this.autoExec()
      }
      if (!_config.wrap.cardType && _data.$$uuid) {
        setTimeout(() => {
          this.transferLine()
@@ -165,6 +161,17 @@
      this.timer = new TimerTask()
      this.timer.init(config.uuid, config.timer, config.timerRepeats, () => {this.loadData(true)})
    }
    if (config.$cache && !this.loaded) {
      Api.getLCacheConfig(config.uuid).then(res => {
        if (!res || this.loaded) return
        let _data = res[0]
        _data.$$uuid = _data[config.setting.primaryKey] || ''
        this.setState({data: _data})
      })
    }
  }
  shouldComponentUpdate (nextProps, nextState) {
@@ -185,7 +192,7 @@
  }
  /**
   * @description 图表数据更新,刷新内容
   * @description 数据更新,刷新内容
   */
  UNSAFE_componentWillReceiveProps (nextProps) {
    const { sync, config, BID, BData, selected } = this.state
@@ -203,14 +210,17 @@
      _data.$$BData = BData || ''
      _data.$$uuid = _data[config.setting.primaryKey] || ''
      this.loaded = true
      this.setState({sync: false, data: _data}, () => {
        if (selected !== 'false') {
          this.checkTopLine()
        } else if (!config.wrap.cardType && _data.$$uuid) {
          this.transferLine()
        }
        this.autoExec()
      })
    } else if (config.setting.syncRefresh && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) {
    } else if (config.setting.useMSearch && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) {
      this.setState({}, () => {
        this.loadData()
      })
@@ -227,6 +237,8 @@
      _data.$$BData = BData || ''
      _data.$$uuid = _data[config.setting.primaryKey] || ''
      this.loaded = true
      this.setState({data: _data}, () => {
        if (selected !== 'false') {
          this.checkTopLine()
@@ -235,6 +247,16 @@
        }
      })
    }
  }
  autoExec = () => {
    const { config, data } = this.state
    if (!config.wrap.autoExec) return
    setTimeout(() => {
      MKEmitter.emit('triggerBtnId', config.wrap.autoExec, data.$$empty ? [] : [data])
    }, 200)
  }
  checkTopLine = () => {
@@ -342,6 +364,7 @@
      this.setState({
        data: {$$BID: BID || '', $$BData: BData, $$empty: true},
      })
      this.loaded = true
      return
    }
@@ -365,6 +388,11 @@
    if (result.status) {
      let _data = {}
      this.loaded = true
      if (config.$cache && config.setting.onload !== 'false') {
        Api.writeCacheConfig(config.uuid, result.data || '')
      }
      if (!result.data || !result.data[0]) {
        _data.$$empty = true
      } else {
@@ -379,16 +407,23 @@
        data: _data,
        loading: false
      }, () => {
        if (selected !== 'false') {
          this.checkTopLine()
        if (config.wrap.goback === 'true' && _data.$$empty) {
          this.timer && this.timer.stop()
          MKEmitter.emit('closeTabView', config.$pageId)
        } else {
          this.transferLine()
          if (selected !== 'false') {
            this.checkTopLine()
          } else {
            this.transferLine()
          }
          this.autoExec()
        }
      })
      if (config.timer && config.clearField) {
      if (config.timer && config.clearField && result.data && result.data[0]) {
        let vals = (config.clearValue || '').split(',')
        if (vals.includes(_data[config.clearField])) {
        if (vals.includes(result.data[0][config.clearField])) {
          this.timer && this.timer.stop()
        }
      }
@@ -397,11 +432,17 @@
        loading: false
      })
      this.timer && this.timer.stop()
      notification.error({
        top: 92,
        message: result.message,
        duration: 10
      })
      if (result.ErrCode === 'N') {
        Modal.error({
          title: result.message,
        })
      } else {
        notification.error({
          top: 92,
          message: result.message,
          duration: 10
        })
      }
    }
  }
@@ -440,14 +481,14 @@
        <NormalHeader config={config}/>
        <Row className={`card-row-list data-zoom ${config.wrap.wrapClass}`}>
          {config.subcards.map((item, index) => {
            let className = item.setting.click ? 'mk-card pointer ' : 'mk-card '
            let className = 'mk-card '
            if (activeKey === index) {
              className += 'active'
            }
            return (
              <Col className={className} key={index} span={item.setting.width || 6} offset={item.offset || 0} onClick={() => {this.changeCard(index, item)}}>
                <CardItem card={item} cards={config} data={data}/>
              <Col className={className} key={index} span={item.setting.width || 6} offset={item.offset || 0}>
                <CardItem card={item} cards={config} data={data} onClick={() => {this.changeCard(index, item)}}/>
              </Col>
            )
          })}