king
2023-08-14 cc20b3cfe18b36c7b0f75937f88679eb031ecc6f
src/tabviews/custom/components/carousel/prop-card/index.jsx
@@ -16,16 +16,13 @@
class PropCard extends Component {
  static propTpyes = {
    data: PropTypes.array,           // 统一查询数据
    config: PropTypes.object,        // 组件配置信息
    mainSearch: PropTypes.any,       // 外层搜索条件
    config: PropTypes.object
  }
  state = {
    BID: '',                   // 上级ID
    config: null,              // 图表配置信息
    loading: false,            // 数据加载状态
    sync: false,               // 是否统一请求数据
    data: {$$empty: true},
    BData: null,
    visible: false
@@ -34,11 +31,10 @@
  loaded = false
  UNSAFE_componentWillMount () {
    const { data, initdata } = this.props
    let _config = fromJS(this.props.config).toJS()
    const { config } = this.props
    let _config = fromJS(config).toJS()
    let _data = {$$empty: true}
    let _sync = false
    let BID = ''
    let BData = ''
@@ -53,25 +49,23 @@
    }
    
    if (_config.wrap.datatype === 'dynamic') {
      _sync = _config.setting.sync === 'true'
      _config.setting.onload = _config.setting.sync === 'true' ? 'false' : 'true'
      if (_sync && data) {
        _data = data[_config.dataName] || {$$empty: true}
        if (Array.isArray(_data)) {
          _data = _data[0] || {$$empty: true}
      if (_config.setting.sync === 'true' && window.GLOB.SyncData.has(_config.dataName)) {
        _data = window.GLOB.SyncData.get(_config.dataName) || []
        if (_config.$cache) {
          Api.writeCacheConfig(_config.uuid, fromJS(_data).toJS())
        }
        _sync = false
        _config.setting.sync = 'false'
        _data = _data[0] || {$$empty: true}
        this.loaded = true
      } else if (_sync && initdata) {
        _data = initdata
        if (Array.isArray(_data)) {
          _data = _data[0] || {$$empty: true}
        }
        _sync = false
        this.loaded = true
        window.GLOB.SyncData.delete(_config.dataName)
      }
    } else if (_config.wrap.datatype === 'static') {
      this.loaded = true
    }
    _data.$$uuid = _data[_config.setting.primaryKey] || ''
@@ -93,20 +87,11 @@
    _config.wrap.speed = (_config.wrap.speed || 3) * 1000
    this.setState({
      sync: _sync,
      data: _data,
      BID: BID || '',
      BData: BData || '',
      config: _config,
      arr_field: _config.columns.map(col => col.field).join(','),
    }, () => {
      if (_config.wrap.datatype === 'dynamic' && _config.setting && _config.setting.sync !== 'true' && _config.setting.onload === 'true') {
        setTimeout(() => {
          this.loadData()
        }, _config.setting.delay || 0)
      } else if (_config.wrap.display === 'modal' && _config.wrap.datatype === 'static') {
        this.openModal()
      }
      arr_field: _config.columns.map(col => col.field).join(',')
    })
  }
@@ -118,6 +103,14 @@
    MKEmitter.addListener('queryModuleParam', this.queryModuleParam)
    MKEmitter.addListener('refreshByButtonResult', this.refreshByButtonResult)
    if (config.setting.useMSearch) {
      MKEmitter.addListener('searchRefresh', this.searchRefresh)
    }
    if (config.setting.sync === 'true') {
      MKEmitter.addListener('transferSyncData', this.transferSyncData)
    }
    if (config.timer && config.wrap.datatype === 'dynamic') {
      this.timer = new TimerTask()
      this.timer.init(config.uuid, config.timer, config.timerRepeats, () => {
@@ -125,16 +118,7 @@
      })
    }
    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})
      })
    }
    this.initExec()
  }
  shouldComponentUpdate (nextProps, nextState) {
@@ -146,48 +130,115 @@
      return
    }
    MKEmitter.removeListener('reloadData', this.reloadData)
    MKEmitter.removeListener('searchRefresh', this.searchRefresh)
    MKEmitter.removeListener('resetSelectLine', this.resetParentParam)
    MKEmitter.removeListener('transferSyncData', this.transferSyncData)
    MKEmitter.removeListener('queryModuleParam', this.queryModuleParam)
    MKEmitter.removeListener('refreshByButtonResult', this.refreshByButtonResult)
    this.timer && this.timer.stop()
  }
  /**
   * @description 图表数据更新,刷新内容
   */
  UNSAFE_componentWillReceiveProps (nextProps) {
    const { sync, config, BID, BData } = this.state
  initExec = () => {
    const { config } = this.state
    if (sync && !is(fromJS(this.props.data), fromJS(nextProps.data))) {
      let _data = {$$empty: true}
      if (nextProps.data && nextProps.data[config.dataName]) {
        _data = nextProps.data[config.dataName]
        if (Array.isArray(_data)) {
          _data = _data[0] || {$$empty: true}
    if (config.wrap.datatype === 'dynamic') {
      if (config.$cache) {
        if (config.$time) {
          if (!this.loaded) {
            Api.getLCacheConfig(config.uuid, config.$time).then(res => {
              if (!res.valid && config.setting.onload === 'true') {
                setTimeout(() => {
                  this.loadData('init')
                }, config.setting.delay || 0)
              }
              if (!res.data || this.loaded) return
              let _data = res.data[0] || {$$empty: true}
              _data.$$uuid = _data[config.setting.primaryKey] || ''
              this.setState({data: _data})
            })
          } else {
            this.openModal()
          }
        } else {
          if (!this.loaded) {
            Api.getLCacheConfig(config.uuid, 0).then(res => {
              if (!res.data || this.loaded) return
              let _data = res.data[0] || {$$empty: true}
              _data.$$uuid = _data[config.setting.primaryKey] || ''
              this.setState({data: _data})
            })
          }
          if (config.setting.onload === 'true') {
            setTimeout(() => {
              this.loadData('init')
            }, config.setting.delay || 0)
          } else if (this.loaded) {
            this.openModal()
          }
        }
      } else if (config.setting.onload === 'true') {
        setTimeout(() => {
          this.loadData()
        }, config.setting.delay || 0)
      } else if (this.loaded) {
        this.openModal()
      }
      _data.$$uuid = _data[config.setting.primaryKey] || ''
      _data.$$BID = BID || ''
      _data.$$BData = BData || ''
      this.loaded = true
      this.setState({sync: false, data: _data}, () => {
        if (config.wrap.display === 'modal') {
          this.openModal()
        }
      })
    } else if (config.setting.useMSearch && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) {
      this.setState({}, () => {
        this.loadData()
      })
    } else if (config.wrap.datatype === 'static') {
      this.openModal()
    }
  }
  transferSyncData = (syncId) => {
    const { config } = this.state
    if (config.$syncId !== syncId) return
    const { BID, BData } = this.state
    let _data = window.GLOB.SyncData.get(config.dataName) || []
    if (config.$cache) {
      Api.writeCacheConfig(config.uuid, fromJS(_data).toJS())
    }
    _data = _data[0] || {$$empty: true}
    _data.$$BID = BID || ''
    _data.$$BData = BData || ''
    _data.$$uuid = _data[config.setting.primaryKey] || ''
    this.loaded = true
    this.setState({data: _data}, () => {
      this.openModal()
    })
    window.GLOB.SyncData.delete(config.dataName)
    MKEmitter.removeListener('transferSyncData', this.transferSyncData)
  }
  searchRefresh = (searchId) => {
    const { config } = this.state
    if (config.$searchId !== searchId) return
    this.setState({}, () => {
      this.loadData()
    })
  }
  openModal = (ErrCode) => {
    const { config, data } = this.state
    if (config.wrap.display !== 'modal') return
    
    let code = config.wrap.code || ('modal' + config.uuid)
    let tip = localStorage.getItem(code)
@@ -225,10 +276,6 @@
    } else {
      this.loadData()
    }
    if (position === 'popclose') { // 执行启动弹窗的按钮所选择的刷新项
      btn.$tabId && MKEmitter.emit('refreshPopButton', btn.$tabId)
    }
  }
  resetParentParam = (MenuID, id, data) => {
@@ -246,12 +293,14 @@
   * @description 导出Excel时,获取页面搜索排序等参数
   */
  queryModuleParam = (menuId, callback) => {
    const { mainSearch } = this.props
    const { config } = this.state
    if (config.uuid !== menuId) return
    let searches = config.setting.useMSearch && mainSearch ? mainSearch : []
    let searches = []
    if (config.setting.useMSearch) { // 主表搜索条件
      searches = window.GLOB.SearchBox.get(config.$searchId) || []
    }
    callback({
      arr_field: '',
@@ -270,7 +319,6 @@
  }
  async loadData (type) {
    const { mainSearch } = this.props
    const { config, arr_field, BID, BData } = this.state
    if (config.wrap.datatype === 'static') {
@@ -287,10 +335,12 @@
      return
    }
    let searches = config.setting.useMSearch && mainSearch ? mainSearch : []
    let searches = []
    if (config.setting.useMSearch) { // 主表搜索条件
      searches = window.GLOB.SearchBox.get(config.$searchId) || []
    }
    let requireFields = searches.filter(item => item.required && item.value === '')
    if (requireFields.length > 0) {
    if (config.$s_req && searches.filter(item => item.required && item.value === '').length > 0) {
      return
    }
@@ -308,8 +358,8 @@
      let _data = {}
      this.loaded = true
      if (config.$cache && config.setting.onload !== 'false') {
        Api.writeCacheConfig(config.uuid, result.data || '')
      if (config.$cache && type === 'init') {
        Api.writeCacheConfig(config.uuid, result.data || [])
      }
      if (!result.data || !result.data[0]) {
@@ -326,21 +376,40 @@
        data: _data,
        loading: false
      }, () => {
        if (config.wrap.display === 'modal') {
          this.openModal(result.ErrCode)
        }
        this.openModal(result.ErrCode)
      })
      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,