king
2023-06-14 08cce3334a2dc81d690b518136b0aaea64e48b0b
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 } from 'antd'
import { notification, Modal } from 'antd'
import Api from '@/api'
import Utils from '@/utils/utils.js'
@@ -46,7 +46,6 @@
   */
  UNSAFE_componentWillMount () {
    let _config = fromJS(this.props.config).toJS()
    let _cols = new Map()
    let BID = ''
    let BData = ''
@@ -70,22 +69,11 @@
    let setting = {..._config.setting, ..._config.wrap}
    if (setting.selected !== 'always' && setting.selected !== 'init') {
    if (setting.selected !== 'always' && setting.selected !== 'init' && setting.selected !== 'sign') {
      setting.selected = 'false'
    } else {
      setting.orisel = true
    }
    _config.columns.forEach(item => {
      if (item.type !== 'number') return
      _cols.set(item.field, item)
    })
    _config.cols.forEach(column => {
      if (column.type === 'action') {
        column.operations = column.elements
      }
    })
    _config.style = _config.style || {}
@@ -126,7 +114,7 @@
      })
      
      MKEmitter.emit('resetSelectLine', config.uuid, '', '') // 广播数据切换
      reset && MKEmitter.emit('resetTable', config.uuid, repage) // 列表重置
      reset && MKEmitter.emit('resetTable', config.uuid, 'true') // 列表重置
      if (setting.$hasSyncModule) {
        MKEmitter.emit('syncBalconyData', config.uuid, [], false)
      }
@@ -157,9 +145,26 @@
    let result = await Api.genericInterface(param)
    if (result.status) {
      if (repage === 'false' && result.data && result.data.length === 0 && result.total > 0 && pageIndex > 1) {
        let _pageIndex = Math.ceil(result.total / pageSize)
        if (_pageIndex < pageIndex) {
          MKEmitter.emit('resetTable', config.uuid, 'repage', _pageIndex)
          this.setState({
            pageIndex: _pageIndex,
            data: [],
            selectedData: [],
            total: result.total
          }, () => {
            this.loadmaindata()
          })
          return
        }
      }
      if ((setting.selected !== 'false' || (setting.orisel && id)) && result.data && result.data.length > 0) {
        setTimeout(() => {
          MKEmitter.emit('mkCheckTopLine', config.uuid, id)
          MKEmitter.emit('mkCheckTopLine', config.uuid, id, setting.selected)
        }, 200)
        if (setting.selected === 'init') {
          this.setState({setting: {...setting, selected: 'false'}})
@@ -195,7 +200,7 @@
            })
          }
          if (setting.controlField) {
            if (setting.controlVal.includes(item[setting.controlField])) {
            if (setting.controlVal.includes(item[setting.controlField] + '')) {
              item.$disabled = true
            }
          }
@@ -206,15 +211,34 @@
        total: result.total,
        loading: false
      })
      if (config.autoMatic) {
        if (result.data && result.data.length > 0) {
          MKEmitter.emit('autoGetData', config.MenuID)
        } else {
          MKEmitter.emit('autoMaticOver', config.MenuID)
        }
      }
    } else {
      this.setState({
        loading: false
      })
      notification.error({
        top: 92,
        message: result.message,
        duration: 10
      })
      if (config.autoMatic) {
        MKEmitter.emit('autoMaticError', config.MenuID)
      }
      if (result.ErrCode === 'N') {
        Modal.error({
          title: result.message,
        })
      } else {
        notification.error({
          top: 92,
          message: result.message,
          duration: 10
        })
      }
    }
  }
@@ -372,47 +396,42 @@
   * 含有初始不加载的页面,修改设置
   */
  refreshbysearch = (searches) => {
    const { setting } = this.state
    if (setting.onload === 'false') {
      this.setState({
        pageIndex: 1,
        search: searches,
        setting: {...setting, onload: 'true'}
      }, () => {
        this.loadmaindata()
        this.getStatFieldsValue()
      })
    } else {
      this.setState({
        pageIndex: 1,
        search: searches
      }, () => {
        this.loadmaindata(true, 'true')
        this.getStatFieldsValue()
      })
    }
    this.setState({
      pageIndex: 1,
      search: searches
    }, () => {
      this.loadmaindata(true, 'true')
      this.getStatFieldsValue()
    })
  }
  /**
   * @description 表格条件改变时重置数据(分页或排序)
   */
  refreshbytable = (pagination, filters, sorter) => {
    if (sorter.order) {
      let _chg = {
        ascend: 'asc',
        descend: 'desc'
    if (!sorter) { // 无人值守
      this.setState({
        pageIndex: pagination.pageIndex
      }, () => {
        this.loadmaindata()
      })
    } else {
      if (sorter.order) {
        let _chg = {
          ascend: 'asc',
          descend: 'desc'
        }
        sorter.order = _chg[sorter.order]
      }
      sorter.order = _chg[sorter.order]
      this.setState({
        pageIndex: pagination.current,
        pageSize: pagination.pageSize,
        orderBy: (sorter.field && sorter.order) ? `${sorter.field} ${sorter.order}` : ''
      }, () => {
        this.loadmaindata()
      })
    }
    this.setState({
      pageIndex: pagination.current,
      pageSize: pagination.pageSize,
      orderBy: (sorter.field && sorter.order) ? `${sorter.field} ${sorter.order}` : ''
    }, () => {
      this.loadmaindata()
    })
  }
  /**
@@ -518,7 +537,7 @@
  UNSAFE_componentWillReceiveProps(nextProps) {
    const { config } = this.state
    if (config.setting.syncRefresh && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) {
    if (config.setting.useMSearch && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) {
      this.setState({pageIndex: 1}, () => {
        this.reloadtable()
      })
@@ -551,20 +570,20 @@
  render() {
    const { BID, setting, actions, config, columns, selectedData, BData, data } = this.state
    return (
      <div className="custom-base-table" style={config.style}>
        {config.search.length ?
          <MainSearch BID={BID} config={config} refreshdata={this.refreshbysearch}/> : null
        }
        {actions.length ? <MainAction
        {actions.length > 0 ? <MainAction
          BID={BID}
          setting={setting}
          actions={actions}
          BData={BData}
          columns={config.columns}
          selectedData={selectedData}
        /> : <div style={{height: '15px'}}></div>}
        /> : <div style={{height: '25px'}}></div>}
        <div className="main-table-box">
          <MainTable
            data={data}
@@ -573,6 +592,7 @@
            MenuID={config.uuid}
            fields={config.columns}
            total={this.state.total}
            autoMatic={config.autoMatic}
            lineMarks={config.lineMarks}
            loading={this.state.loading}
            refreshdata={this.refreshbytable}