king
2024-07-30 31df729bbc664b826536a344e2bf7dd81854c477
src/tabviews/custom/components/table/base-table/index.jsx
@@ -1,7 +1,7 @@
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { is, fromJS } from 'immutable'
import { notification, Modal } from 'antd'
import { notification } from 'antd'
import Api from '@/api'
import UtilsDM from '@/utils/utils-datamanage.js'
@@ -104,14 +104,17 @@
      this.setState({
        data: [],
        selectedData: [],
        loading: false,
        total: 0
      })
      
      MKEmitter.emit('resetSelectLine', config.uuid, '', '') // 广播数据切换
      reset && MKEmitter.emit('resetTable', config.uuid, 'true') // 列表重置
      if (setting.$hasSyncModule) {
        MKEmitter.emit('syncBalconyData', config.uuid, [], false)
      }
      // if (setting.$hasSyncModule) {
      //   MKEmitter.emit('syncBalconyData', config.uuid, [], false)
      // }
      this.requestId = ''
      return
    }
@@ -137,8 +140,13 @@
    let _orderBy = orderBy || setting.order
    let param = UtilsDM.getQueryDataParams(setting, searches, _orderBy, pageIndex, pageSize, BID)
    let result = await Api.genericInterface(param)
    this.requestId = config.uuid + new Date().getTime()
    let result = await Api.genericInterface(param, setting.js_script, '', this.requestId)
    if (result.status) {
      if (result.$requestId && this.requestId !== result.$requestId) return
      if (repage === 'false' && result.data && result.data.length === 0 && result.total > 0 && pageIndex > 1) {
        let _pageIndex = Math.ceil(result.total / pageSize)
@@ -165,9 +173,9 @@
        }
      } else {
        MKEmitter.emit('resetSelectLine', config.uuid, '', '') // 广播数据切换
        if (setting.$hasSyncModule) {
          MKEmitter.emit('syncBalconyData', config.uuid, [], false)
        }
        // if (setting.$hasSyncModule) {
        //   MKEmitter.emit('syncBalconyData', config.uuid, [], false)
        // }
      }
      
      reset && MKEmitter.emit('resetTable', config.uuid, repage) // 列表重置
@@ -221,19 +229,7 @@
        }
      }
      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
@@ -243,25 +239,14 @@
        MKEmitter.emit('autoMaticError', config.MenuID)
      }
      
      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)
    }
  }
  /**
   * @description 获取单行数据
   */ 
  async loadmainLinedata (id) {
  async loadLinedata (id, position) {
    const { setting, config, search, orderBy, BID, pageIndex, pageSize, BData } = this.state
    if (config.forbidLine) {
@@ -289,6 +274,11 @@
    let result = await Api.genericInterface(param)
    if (result.status) {
      if (position === 'line_grid' && (!result.data || !result.data[0])) {
        this.loadmaindata(true, 'false')
        return
      }
      let data = fromJS(this.state.data).toJS()
      let selectedData = fromJS(this.state.selectedData).toJS()
@@ -371,11 +361,8 @@
      this.setState({
        loading: false
      })
      notification.error({
        top: 92,
        message: result.message,
        duration: 10
      })
      UtilsDM.queryFail(result)
    }
  }
@@ -452,7 +439,19 @@
   * 含有初始不加载的页面,修改设置
   */
  refreshbysearch = (searches) => {
    const { config} = this.state
    const { config, BID } = this.state
    if (config.setting.supModule && !BID) {
      notification.warning({
        top: 92,
        message: window.GLOB.dict['sup_key_req'] || '需要上级主键值!',
        duration: 5
      })
      this.setState({
        search: searches
      })
      return
    }
    this.setState({
      pageIndex: 1,
@@ -547,7 +546,7 @@
    if (!id) {
      this.reloadtable()
    } else {
      this.loadmainLinedata(id)
      this.loadLinedata(id)
    }
  }
@@ -561,8 +560,10 @@
        BID: id,
        BData: data
      }, () => {
        this.loadmaindata(true, 'true')
        this.getStatFieldsValue()
        if (!setting.checkBid) {
          this.loadmaindata(true, 'true')
          this.getStatFieldsValue()
        }
      })
    }
  }
@@ -578,14 +579,14 @@
    if (config.uuid !== menuId) return
    if (position === 'line') {
      if (lines && lines.length === 1) {
        this.loadmainLinedata(lines[0].$$uuid)
    if (position === 'line' || position === 'line_grid') {
      if (lines && lines.length === 1 && !config.forbidLine) {
        this.loadLinedata(lines[0].$$uuid, position)
      } else {
        this.reloadtable(btn, id)
      }
    } else if ((position === 'mainline' || position === 'popclose') && config.setting.supModule && BID) { // 刷新源组件时,附带刷新上级行与当前组件
      MKEmitter.emit('reloadData', config.setting.supModule, BID)
    } else if (['mainline', 'maingrid', 'popclose'].includes(position) && config.setting.supModule) {
      MKEmitter.emit('reloadData', config.setting.supModule, position === 'maingrid' ? '' : BID)
    } else {
      this.reloadtable(btn, id)
    }
@@ -596,9 +597,26 @@
    if (config.$searchId !== searchId) return
    
    this.setState({pageIndex: 1}, () => {
      this.reloadtable()
    })
    this.reloadtable()
  }
  autoExec = (times) => {
    const { config } = this.state
    if (!config.wrap.autoExec) return
    let btn = document.getElementById('button' + config.wrap.autoExec)
    this.autoTimer && clearTimeout(this.autoTimer)
    if (btn) {
      MKEmitter.emit('triggerBtnId', config.wrap.autoExec, [])
    } else if (!times || times < 20) {
      times = times ? times + 1 : 1
      this.autoTimer = setTimeout(() => {
        this.autoExec(times)
      }, 1000)
    }
  }
  shouldComponentUpdate (nextProps, nextState) {
@@ -616,6 +634,8 @@
    if (config.setting.useMSearch) {
      MKEmitter.addListener('searchRefresh', this.searchRefresh)
    }
    this.autoExec()
  }
  /**
@@ -648,22 +668,20 @@
          columns={config.columns}
          selectedData={selectedData}
        /> : <div style={{height: '25px'}}></div>}
        <div className="main-table-box">
          <MainTable
            data={data}
            setting={setting}
            columns={columns}
            MenuID={config.uuid}
            fields={config.columns}
            total={this.state.total}
            autoMatic={config.autoMatic}
            lineMarks={config.lineMarks}
            loading={this.state.loading}
            refreshdata={this.refreshbytable}
            statFValue={this.state.statFValue}
            chgSelectData={(selects) => this.setState({selectedData: selects})}
          />
        </div>
        <MainTable
          data={data}
          setting={setting}
          columns={columns}
          MenuID={config.uuid}
          fields={config.columns}
          total={this.state.total}
          autoMatic={config.autoMatic}
          lineMarks={config.lineMarks}
          loading={this.state.loading}
          refreshdata={this.refreshbytable}
          statFValue={this.state.statFValue}
          chgSelectData={(selects) => this.setState({selectedData: selects})}
        />
      </div>
    )
  }