king
2023-01-17 d5ce81026882ada34e5d49411be7c90ee96cc102
src/tabviews/custom/components/card/data-card/index.jsx
@@ -46,6 +46,8 @@
    supComs: null
  }
  loaded = false
  UNSAFE_componentWillMount () {
    const { data, initdata } = this.props
    let _config = fromJS(this.props.config).toJS()
@@ -102,16 +104,16 @@
    let _data = null
    let _sync = _config.setting.sync === 'true'
    if (_config.setting.sync === 'true' && data) {
    if (_sync && data) {
      _data = data[_config.dataName] || []
      _sync = false
    } else if (_config.setting.sync === 'true' && initdata) {
    } else if (_sync && initdata) {
      _data = initdata || []
      _sync = false
    }
    let selected = 'false'
    if (_config.wrap.selected === 'always' || _config.wrap.selected === 'init') {
    if (_config.wrap.selected === 'always' || _config.wrap.selected === 'init' || _config.wrap.selected === 'sign') {
      selected = _config.wrap.selected
    } else {
      _config.wrap.selected = 'false'
@@ -173,6 +175,8 @@
    _config.wrap.wrapClass =  `${_config.wrap.selStyle} ${_config.wrap.cardType || ''} ${_config.wrap.scale}`
    this.loaded = _data !== null
    this.setState({
      supComs,
      selected,
@@ -214,6 +218,27 @@
        })
      })
    }
    if (config.$cache && !this.loaded) {
      Api.getLCacheConfig(config.uuid).then(res => {
        if (!res || this.loaded) return
        let _data = res.map((item, index) => {
          item.key = index
          item.$$uuid = item[config.setting.primaryKey] || ''
          item.$Index = index + 1 + ''
          if (config.wrap.controlField) {
            if (config.wrap.controlVal.includes(item[config.wrap.controlField])) {
              item.$disabled = true
            }
          }
          return item
        })
        this.setState({data: _data})
      })
    }
  }
  shouldComponentUpdate (nextProps, nextState) {
@@ -252,6 +277,8 @@
          }
        }
      }
      this.loaded = true
      this.setState({sync: false, data: _data})
    } else if (config.setting.useMSearch && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) {
@@ -342,17 +369,58 @@
  }
  checkTopLine = (id) => {
    const { config, data } = this.state
    const { config, data, selected } = this.state
    if (!data || data.length === 0) {
      this.setState({
        activeKey: '',
        selectKeys: [],
        selectedData: []
      })
      MKEmitter.emit('resetSelectLine', config.uuid, '', '')
      if (config.setting.$hasSyncModule) {
        MKEmitter.emit('syncBalconyData', config.uuid, [], false)
      }
      return
    }
    if (selected === 'sign') {
      let index = ''
      let keys = []
      let items = []
      let last = ''
      data.forEach((item, i) => {
        if (!item.$disabled && item.selected === 'true') {
          items.push(item)
          keys.push(i)
          index = i
          last = item
        }
      })
      this.setState({
        activeKey: index,
        selectKeys: keys,
        selectedData: items
      })
      MKEmitter.emit('resetSelectLine', config.uuid, last ? last.$$uuid : '', last)
      if (config.setting.$hasSyncModule) {
        MKEmitter.emit('syncBalconyData', config.uuid, items, data.length === keys.length)
      }
      return
    }
    let index = 0
    if (id && data) {
    if (id) {
      index = data.findIndex(item => item.$$uuid === id)
      if (index === -1) {
        index = 0
      }
    }
    if (!data || data.length === 0 || data[index].$disabled) {
    if (data[index].$disabled) {
      this.setState({
        activeKey: '',
        selectKeys: [],
@@ -485,6 +553,8 @@
    const { config, arr_field, pageIndex, search, BID, BData, selected } = this.state
    if (config.setting.supModule && !BID && config.wrap.supKey !== 'false') { // BID 不存在时,不做查询
      this.loaded = true
      this.setState({
        activeKey: '',
        selectKeys: [],
@@ -542,6 +612,11 @@
        start = config.setting.pageSize * (pageIndex - 1) + 1
      }
      this.loaded = true
      if (config.$cache && pageIndex === 1) {
        Api.writeCacheConfig(config.uuid, result.data || '')
      }
      if (selected !== 'false' || (id && config.wrap.selected !== 'false')) {
        setTimeout(() => {
          this.checkTopLine(id)