king
2023-07-21 71e3da644eca32a5aa40503e903efb0640748093
src/tabviews/custom/components/card/prop-card/index.jsx
@@ -15,9 +15,7 @@
class PropCard extends Component {
  static propTpyes = {
    data: PropTypes.array,           // 统一查询数据
    config: PropTypes.object,        // 组件配置信息
    mainSearch: PropTypes.any,       // 外层搜索条件
    config: PropTypes.object
  }
  state = {
@@ -25,18 +23,18 @@
    config: null,              // 图表配置信息
    loading: false,            // 数据加载状态
    activeKey: '',             // 选中数据
    sync: false,               // 是否统一请求数据
    data: {},                  // 数据
    BData: '',
    selected: 'false',
  }
  loaded = false
  autoTimer = null
  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
@@ -53,22 +51,20 @@
    }
    
    if (_config.wrap.datatype === 'dynamic') {
      _sync = _config.setting.sync === 'true'
      if (_config.setting.sync === 'true' && window.GLOB.SyncData.has(_config.dataName)) {
        _data = window.GLOB.SyncData.get(_config.dataName) || []
      if (_sync && data) {
        _data = data[_config.dataName] || {$$empty: true}
        if (Array.isArray(_data)) {
          _data = _data[0] || {$$empty: true}
        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 === 'public' && window.GLOB.CacheData.get(_config.wrap.publicId)) {
      _data = window.GLOB.CacheData.get(_config.wrap.publicId)
@@ -95,6 +91,14 @@
          card.setting.click = ''
        }
      }
      if (card.style.clear === 'left') {
        card.wStyle = {clear: 'left'}
      } else if (card.style.clear === 'right') {
        card.wStyle = {float: 'right'}
      }
      delete card.style.clear
    })
    let selected = _config.wrap.selected || 'false'
@@ -111,14 +115,13 @@
    this.setState({
      selected,
      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.sync !== 'true' && _config.setting.onload === 'true') {
      if (_config.wrap.datatype === 'dynamic' && config.setting.sync !== 'true' && _config.setting.onload === 'true') {
        setTimeout(() => {
          this.loadData()
        }, _config.setting.delay || 0)
@@ -142,6 +145,8 @@
        } else {
          this.autoExec()
        }
      } else if (_config.wrap.datatype === 'static') {
        this.autoExec()
      }
      if (_data.$$uuid) {
        setTimeout(() => {
@@ -155,10 +160,18 @@
    const { config } = this.state
    MKEmitter.addListener('reloadData', this.reloadData)
    MKEmitter.addListener('refreshLineData', this.refreshLineData)
    MKEmitter.addListener('resetSelectLine', this.resetParentParam)
    MKEmitter.addListener('queryModuleParam', this.queryModuleParam)
    MKEmitter.addListener('refreshLineData', this.refreshLineData)
    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.wrap.datatype === 'public') {
      MKEmitter.addListener('mkPublicData', this.mkPublicData)
@@ -173,7 +186,7 @@
      Api.getLCacheConfig(config.uuid).then(res => {
        if (!res || this.loaded) return
        let _data = res[0]
        let _data = res[0] || {$$empty: true}
        _data.$$uuid = _data[config.setting.primaryKey] || ''
        this.setState({data: _data})
@@ -191,54 +204,65 @@
    }
    MKEmitter.removeListener('reloadData', this.reloadData)
    MKEmitter.removeListener('mkPublicData', this.mkPublicData)
    MKEmitter.removeListener('resetSelectLine', this.resetParentParam)
    MKEmitter.removeListener('queryModuleParam', this.queryModuleParam)
    MKEmitter.removeListener('searchRefresh', this.searchRefresh)
    MKEmitter.removeListener('refreshLineData', this.refreshLineData)
    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, selected } = this.state
  transferSyncData = (syncId) => {
    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.$syncId !== syncId) return
      _data.$$BID = BID || ''
      _data.$$BData = BData || ''
      _data.$$uuid = _data[config.setting.primaryKey] || ''
    const { BID, BData, selected } = this.state
      this.loaded = true
    let _data = window.GLOB.SyncData.get(config.dataName) || []
      this.setState({sync: false, data: _data}, () => {
        if (config.wrap.goback === 'true' && _data.$$empty) {
          this.timer && this.timer.stop()
          MKEmitter.emit('closeTabView', config.$pageId)
        } else {
          if (selected !== 'false') {
            this.checkTopLine()
          } else if (_data.$$uuid) {
            this.transferLine()
          }
          this.autoExec()
        }
      })
    } else if (config.setting.useMSearch && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) {
      this.setState({}, () => {
        this.loadData()
      })
    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}, () => {
      if (config.wrap.goback === 'true' && _data.$$empty) {
        this.timer && this.timer.stop()
        MKEmitter.emit('closeTabView', config.$pageId)
      } else {
        if (selected !== 'false') {
          this.checkTopLine()
        } else if (_data.$$uuid) {
          this.transferLine()
        }
        this.autoExec()
      }
    })
    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()
    })
  }
  mkPublicData = (publicId, data) => {
@@ -270,14 +294,23 @@
    }
  }
  autoExec = () => {
  autoExec = (times) => {
    const { config, data } = this.state
    if (!config.wrap.autoExec) return
    setTimeout(() => {
    let btn = document.getElementById('button' + config.wrap.autoExec)
    clearTimeout(this.autoTimer)
    if (btn) {
      MKEmitter.emit('triggerBtnId', config.wrap.autoExec, data.$$empty ? [] : [data])
    }, 200)
    } else if (!times || times < 20) {
      times = times ? times + 1 : 1
      this.autoTimer = setTimeout(() => {
        this.autoExec(times)
      }, 1000)
    }
  }
  checkTopLine = () => {
@@ -320,11 +353,7 @@
    if ((position === 'mainline' || position === 'popclose') && config.setting.supModule && BID) { // 刷新源组件时,附带刷新上级行与当前组件
      MKEmitter.emit('reloadData', config.setting.supModule, BID)
    } else {
      this.loadData()
    }
    if (position === 'popclose') { // 执行启动弹窗的按钮所选择的刷新项
      btn.$tabId && MKEmitter.emit('refreshPopButton', btn.$tabId)
      this.loadData(false, btn)
    }
  }
@@ -357,12 +386,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: '',
@@ -380,8 +411,7 @@
    this.loadData()
  }
  async loadData (hastimer) {
    const { mainSearch } = this.props
  async loadData (hastimer, btn) {
    const { config, arr_field, BID, BData, selected } = this.state
    if (config.wrap.datatype === 'public') {
@@ -393,6 +423,10 @@
      this.setState({
        data: {$$BID: BID || '', $$BData: BData, $$empty: true},
      })
      if (!btn) {
        this.autoExec()
      }
      return
    } else if (config.setting.supModule && !BID) { // BID 不存在时,不做查询
      this.setState({
@@ -402,10 +436,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
    }
@@ -424,7 +460,7 @@
      this.loaded = true
      if (config.$cache && config.setting.onload !== 'false') {
        Api.writeCacheConfig(config.uuid, result.data || '')
        Api.writeCacheConfig(config.uuid, result.data || [])
      }
      if (!result.data || !result.data[0]) {
@@ -451,7 +487,9 @@
          } else {
            this.transferLine()
          }
          this.autoExec()
          if (!btn) {
            this.autoExec()
          }
        }
      })
@@ -461,16 +499,31 @@
          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,
@@ -521,7 +574,7 @@
            }
            return (
              <Col className={className} key={index} span={item.setting.width || 6} offset={item.offset || 0}>
              <Col className={className} key={index} style={item.wStyle} span={item.setting.width || 6} offset={item.offset || 0}>
                <CardItem card={item} cards={config} data={data} onClick={() => {this.changeCard(index, item)}}/>
              </Col>
            )