king
2024-01-22 88859ccc6f057d638dd5ae8f6d5e84680fe11b09
src/tabviews/custom/components/card/balcony/index.jsx
@@ -49,11 +49,13 @@
    
    let _data = { $$empty: true }
    if (_config.wrap.datatype === 'dynamic') {
      _config.setting.onload = _config.setting.sync === 'true' ? 'false' : '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())
          Api.writeCacheConfig(_config.uuid, fromJS(_data).toJS(), BID)
        }
        _config.setting.sync = 'false'
@@ -64,12 +66,11 @@
        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)
      _data = fromJS(_data).toJS()
      this.loaded = true
    } else if (_config.wrap.datatype === 'static') {
      this.loaded = true
    } else if (_config.wrap.datatype === 'public') {
      if (window.GLOB.CacheData.has(_config.wrap.publicId)) {
        _data = window.GLOB.CacheData.get(_config.wrap.publicId)
        _data = fromJS(_data).toJS()
      }
    }
    _data.$$BID = BID || ''
@@ -117,14 +118,7 @@
      syncConfig,
      data: _data,
      BID: BID || '',
      config: _config,
      arr_field: _config.columns.map(col => col.field).join(','),
    }, () => {
      if (_config.wrap.datatype === 'dynamic' && config.setting.sync !== 'true') {
        setTimeout(() => {
          this.loadData()
        }, _config.setting.delay || 0)
      }
      config: _config
    })
  }
@@ -146,20 +140,13 @@
      MKEmitter.addListener('mkPublicData', this.mkPublicData)
    }
    
    if (config.timer && config.wrap.datatype === 'dynamic') {
      this.timer = new TimerTask()
      this.timer.init(config.uuid, config.timer, config.timerRepeats, () => {this.loadData(true)})
    }
    if (config.wrap.datatype === 'dynamic') {
      if (config.timer) {
        this.timer = new TimerTask()
        this.timer.init(config.uuid, config.timer, config.timerRepeats, () => {this.loadData('timer')})
      }
    if (config.$cache && !this.loaded) {
      Api.getLCacheConfig(config.uuid).then(res => {
        if (!res || this.loaded) return
        let _data = res[0] || {$$empty: true}
        _data.$$uuid = _data[config.setting.primaryKey] || ''
        this.setState({data: _data})
      })
      this.initExec()
    }
  }
@@ -183,6 +170,52 @@
    this.timer && this.timer.stop()
  }
  initExec = () => {
    const { config, BID } = this.state
    if (config.$cache) {
      if (config.$time) {
        if (!this.loaded) {
          Api.getLCacheConfig(config.uuid, config.$time, BID).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 {
        if (!this.loaded) {
          Api.getLCacheConfig(config.uuid, 0, BID).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 (config.setting.onload === 'true') {
      setTimeout(() => {
        this.loadData()
      }, config.setting.delay || 0)
    }
  }
  transferSyncData = (syncId) => {
    const { config } = this.state
@@ -193,7 +226,7 @@
    let _data = window.GLOB.SyncData.get(config.dataName) || []
    if (config.$cache) {
      Api.writeCacheConfig(config.uuid, fromJS(_data).toJS())
      Api.writeCacheConfig(config.uuid, fromJS(_data).toJS(), BID)
    }
    _data = _data[0] || {$$empty: true}
@@ -219,9 +252,6 @@
      _data.$$BID = BID || ''
      _data.$$BData = BData || ''
      _data.$$uuid = _data[config.setting.primaryKey] || ''
      this.loaded = true
      this.setState({data: _data})
    }
@@ -307,10 +337,8 @@
    if (config.uuid !== menuId) return
    callback({
      arr_field: '',
      orderBy: '',
      search: [],
      menuName: config.name
    })
  }
@@ -322,8 +350,8 @@
    this.loadData()
  }
  async loadData (hastimer) {
    const { config, arr_field, BID, BData } = this.state
  async loadData (type) {
    const { config, BID, BData } = this.state
    if (config.wrap.datatype === 'public') {
      MKEmitter.emit('reloadData', config.wrap.publicId)
@@ -332,7 +360,7 @@
    
    if (config.wrap.datatype === 'static') {
      this.setState({
        data: {$$BID: BID || '', $$BData: BData, $$empty: true},
        data: {$$BID: BID || '', $$BData: BData, $$empty: true, $$time: new Date().getTime()},
      })
      return
    } else if (config.setting.supModule && !BID) { // BID 不存在时,不做查询
@@ -345,22 +373,22 @@
    let searches = []
    if (!hastimer) {
    if (type !== 'timer') {
      this.setState({
        loading: true
      })
    }
    let _orderBy = config.setting.order || ''
    let param = UtilsDM.getQueryDataParams(config.setting, arr_field, searches, _orderBy, 1, 1, BID)
    let param = UtilsDM.getQueryDataParams(config.setting, searches, _orderBy, 1, 1, BID)
    let result = await Api.genericInterface(param)
    if (result.status) {
      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 || [], BID)
      }
      if (!result.data || !result.data[0]) {