king
2024-05-16 b69b5f6329ca5f87932436b7a6c1ddfc3377e10f
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, Modal } from 'antd'
import { Spin, Col, Row } from 'antd'
import Api from '@/api'
import UtilsDM from '@/utils/utils-datamanage.js'
@@ -47,7 +47,7 @@
    if (BData) {
      BID = BData.$BID || ''
    }
    if (_config.wrap.datatype === 'dynamic') {
      _config.setting.onload = _config.setting.sync === 'true' ? 'false' : 'true'
@@ -55,7 +55,7 @@
        _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'
@@ -72,10 +72,26 @@
      this.loaded = true
    } else if (_config.wrap.datatype === 'static') {
      this.loaded = true
      _config.subcards.forEach(card => {
        card.elements.forEach(ele => {
          if (ele.eleType === 'button') return
          if (ele.datatype === 'dynamic' && ele.field) {
            ele.field = ele.field.toLowerCase()
          }
        })
      })
    }
    _data.$$BID = BID || ''
    _data.$$BData = BData || ''
    if (_config.wrap.datatype === 'static' && BData) {
      Object.keys(BData).forEach(key => {
        if (/\$/.test(key)) return
        _data[key.toLowerCase()] = BData[key]
      })
    }
    if (_config.setting.primaryKey) {
      _data.$$uuid = _data[_config.setting.primaryKey] || ''
    }
@@ -118,8 +134,7 @@
      data: _data,
      BID: BID || '',
      BData: BData || '',
      config: _config,
      arr_field: _config.columns.map(col => col.field).join(',')
      config: _config
    })
  }
@@ -132,16 +147,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.wrap.datatype === 'public') {
      MKEmitter.addListener('mkPublicData', this.mkPublicData)
    } else if (config.setting.useMSearch) {
      MKEmitter.addListener('searchRefresh', this.searchRefresh)
    }
    if (config.timer && config.wrap.datatype === 'dynamic') {
@@ -173,13 +186,13 @@
  }
  initExec = () => {
    const { config, selected, data } = this.state
    const { config, selected, data, BID } = this.state
    if (config.wrap.datatype === 'dynamic') {
      if (config.$cache) {
        if (config.$time) {
          if (!this.loaded) {
            Api.getLCacheConfig(config.uuid, config.$time).then(res => {
            Api.getLCacheConfig(config.uuid, config.$time, BID).then(res => {
              if (!res.valid && config.setting.onload === 'true') {
                setTimeout(() => {
                  this.loadData('init')
@@ -191,7 +204,11 @@
              let _data = res.data[0] || {$$empty: true}
              _data.$$uuid = _data[config.setting.primaryKey] || ''
      
              this.setState({data: _data})
              this.setState({data: _data}, () => {
                if (selected !== 'false') {
                  this.checkTopLine()
                }
              })
            })
          } else {
            if (config.wrap.goback === 'true' && data.$$empty) {
@@ -209,7 +226,7 @@
          }
        } else {
          if (!this.loaded) {
            Api.getLCacheConfig(config.uuid, 0).then(res => {
            Api.getLCacheConfig(config.uuid, 0, BID).then(res => {
              if (!res.data || this.loaded) return
      
              let _data = res.data[0] || {$$empty: true}
@@ -277,12 +294,12 @@
      }
      if (config.$cache && config.$time && config.wrap.autoExec) {
        Api.getLCacheConfig(config.uuid, config.$time).then(res => {
          if (!res.valid) {
            this.autoExec()
          } else {
            Api.writeCacheConfig(config.uuid, [])
          }
        Api.getLCacheConfig(config.uuid, config.$time, BID).then(res => {
          if (res.valid) return
          this.autoExec()
          Api.writeCacheConfig(config.uuid, [], BID)
        })
      } else {
        this.autoExec()
@@ -300,7 +317,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}
@@ -349,7 +366,6 @@
      _data.$$BID = BID || ''
      _data.$$BData = BData || ''
      _data.$$uuid = _data[config.setting.primaryKey] || ''
      this.loaded = true
@@ -373,11 +389,11 @@
  autoExec = (times) => {
    const { config, data } = this.state
    if (!config.wrap.autoExec) return
    if (!config.wrap.autoExec || (config.wrap.emptyExec === 'false' && data.$$empty)) return
    let btn = document.getElementById('button' + config.wrap.autoExec)
    clearTimeout(this.autoTimer)
    this.autoTimer && clearTimeout(this.autoTimer)
    if (btn) {
      MKEmitter.emit('triggerBtnId', config.wrap.autoExec, data.$$empty ? [] : [data])
@@ -426,8 +442,8 @@
    if (config.uuid !== menuId) return
    if ((position === 'mainline' || position === 'popclose') && config.setting.supModule && BID) { // 刷新源组件时,附带刷新上级行与当前组件
      MKEmitter.emit('reloadData', config.setting.supModule, BID)
    if (['mainline', 'maingrid', 'popclose'].includes(position) && config.setting.supModule) {
      MKEmitter.emit('reloadData', config.setting.supModule, position === 'maingrid' ? '' : BID)
    } else {
      this.loadData('', btn)
    }
@@ -472,10 +488,8 @@
    }
    callback({
      arr_field: '',
      orderBy: '',
      search: searches,
      menuName: config.name
      search: searches
    })
  }
@@ -488,7 +502,7 @@
  }
  async loadData (type, btn) {
    const { config, arr_field, BID, BData, selected } = this.state
    const { config, BID, BData, selected } = this.state
    if (config.wrap.datatype === 'public') {
      MKEmitter.emit('reloadData', config.wrap.publicId)
@@ -496,8 +510,16 @@
    }
    
    if (config.wrap.datatype === 'static') {
      let _data = {$$BID: BID || '', $$BData: BData, $$empty: true, $$time: new Date().getTime()}
      if (BData) {
        Object.keys(BData).forEach(key => {
          if (/\$/.test(key)) return
          _data[key.toLowerCase()] = BData[key]
        })
      }
      this.setState({
        data: {$$BID: BID || '', $$BData: BData, $$empty: true},
        data: _data,
      })
      if (!btn) {
@@ -528,7 +550,7 @@
    }
    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) {
@@ -536,7 +558,7 @@
      this.loaded = true
      if (config.$cache && type === 'init') {
        Api.writeCacheConfig(config.uuid, result.data || [])
        Api.writeCacheConfig(config.uuid, result.data || [], BID)
      }
      if (!result.data || !result.data[0]) {
@@ -575,37 +597,15 @@
          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
          })
        }
      }
      UtilsDM.querySuccess(result)
    } else {
      this.setState({
        loading: false
      })
      this.timer && this.timer.stop()
      if (!result.message) return
      if (result.ErrCode === 'N') {
        Modal.error({
          title: result.message,
        })
      } else if (result.ErrCode !== '-2') {
        notification.error({
          top: 92,
          message: result.message,
          duration: 10
        })
      }
      UtilsDM.queryFail(result)
    }
  }