king
2021-12-22 bd1dfc9e6c9b9f8076ca2783ce598e0936b4c664
src/tabviews/commontable/index.jsx
@@ -2,7 +2,7 @@
import PropTypes from 'prop-types'
import {connect} from 'react-redux'
import { is, fromJS } from 'immutable'
import { notification, Spin, Tabs, Icon, Switch, Row, Col } from 'antd'
import { notification, Spin, Tabs, Switch, Row, Col } from 'antd'
import Api from '@/api'
import zhCN from '@/locales/zh-CN/main.js'
@@ -13,6 +13,7 @@
import { updateCommonTable } from '@/utils/utils-update.js'
import asyncComponent from '@/utils/asyncComponent'
import asyncSpinComponent from '@/utils/asyncSpinComponent'
import MkIcon from '@/components/mk-icon'
import MKEmitter from '@/utils/events.js'
import NotFount from '@/components/404'
import './index.scss'
@@ -392,12 +393,15 @@
        _actions.forEach(item => {
          if (item.uuid === config.autoMatic.action && (['pop', 'prompt', 'exec'].includes(item.OpenType) || (item.OpenType === 'funcbutton' && item.funcType === 'print'))) {
            autoMatic = config.autoMatic
            autoMatic.OpenType = item.execMode || item.OpenType
            config.setting.selected = 'false'
            item.autoMatic = true
          }
        })
      }
      this.setState({
        pageSize: config.setting.pageSize || 10,
        loadingview: false,
        absFields,
        autoMatic,
@@ -474,16 +478,13 @@
  }
  loadData = () => {
    const { setting, search, BIDs, loadCustomApi, hasReqFields } = this.state
    const { MenuID } = this.props
    const { setting, search, loadCustomApi, hasReqFields, ContainerId } = this.state
    this.setState({
      selectedData: [],
      BIDs: {
        ...BIDs,
        mainTable: '',
        mainTabledata: ''
      }
      selectedData: []
    })
    MKEmitter.emit('changeTableLine', ContainerId, MenuID, '', '')
    if (hasReqFields) {
      let requireFields = search.filter(item => item.required && item.value === '')
@@ -690,7 +691,7 @@
   * @description 主表数据加载
   */ 
  async loadmaindata () {
    const { setting, arr_field, search, orderBy, BID, pageIndex, pageSize, absFields } = this.state
    const { setting, arr_field, search, orderBy, BID, pageIndex, pageSize, absFields, autoMatic } = this.state
    this.setState({
      loading: true
@@ -740,10 +741,21 @@
        loading: false,
        pickup: false
      })
      if (autoMatic) {
        if (result.data && result.data.length > 0) {
          MKEmitter.emit('autoGetData', this.props.MenuID)
        } else {
          MKEmitter.emit('autoMaticOver', this.props.MenuID)
        }
      }
    } else {
      this.setState({
        loading: false
      })
      if (autoMatic) {
        MKEmitter.emit('autoMaticError', this.props.MenuID)
      }
      notification.error({
        top: 92,
        message: result.message,
@@ -881,7 +893,7 @@
        this.loadData()
      })
    } else {
      MKEmitter.emit('resetTable', this.props.MenuID + 'mainTable') // 列表重置
      MKEmitter.emit('resetTable', this.props.MenuID) // 列表重置
      this.setState({
        pageIndex: 1,
        search: searches
@@ -895,6 +907,15 @@
   * @description 表格条件改变时重置数据(分页或排序)
   */
  refreshbytable = (pagination, filters, sorter) => {
    if (!sorter) {
      this.setState({
        pageIndex: pagination.pageIndex
      }, () => {
        this.loadData()
      })
      return
    }
    if (sorter.order) {
      let _chg = {
        ascend: 'asc',
@@ -917,14 +938,14 @@
   */
  reloadtable = (btn) => {
    if (!btn || btn.resetPageIndex !== 'false') {
      MKEmitter.emit('resetTable', this.props.MenuID + 'mainTable') // 列表重置
      MKEmitter.emit('resetTable', this.props.MenuID) // 列表重置
      this.setState({
        pageIndex: 1
      }, () => {
        this.loadData()
      })
    } else {
      MKEmitter.emit('resetTable', this.props.MenuID + 'mainTable', 'false') // 列表重置
      MKEmitter.emit('resetTable', this.props.MenuID, 'false') // 列表重置
      this.loadData()
    }
  }
@@ -963,21 +984,6 @@
   */
  changeSelectedData = (selectedData) => {
    this.setState({selectedData})
  }
  /**
   * @description 表格Id变化
   */
  handleTableId = (type, id, data) => {
    const { BIDs } = this.state
    this.setState({
      BIDs: {
        ...BIDs,
        [type]: id,
        [type + 'data']: data
      }
    })
  }
  
  /**
@@ -1035,18 +1041,30 @@
    this.setShortcut()
  }
  changeTableLine = (ContainerId, tableId, id, data) => {
    if (this.state.ContainerId !== ContainerId) return
    this.setState({
      BIDs: {...this.state.BIDs, [tableId]: id, [tableId + 'data']: data}
    })
  }
  /**
   * @description 按钮执行完成后页面刷新
   * @param {*} menuId     // 菜单Id
   * @param {*} position   // 刷新位置
   * @param {*} btn        // 执行的按钮
   */
  refreshByButtonResult = (menuId, position, btn) => {
  refreshByButtonResult = (menuId, position, btn, id, lines) => {
    const { MenuID } = this.props
    if (MenuID !== menuId) return
    this.reloadtable(btn)
    if (position === 'line' && lines && lines.length === 1) {
      this.loadmainLinedata(lines[0].$$uuid)
    } else {
      this.reloadtable(btn)
    }
  }
  UNSAFE_componentWillMount () {
@@ -1061,6 +1079,7 @@
  componentDidMount () {
    MKEmitter.addListener('reloadData', this.reloadData)
    MKEmitter.addListener('reloadMenuView', this.reloadMenuView)
    MKEmitter.addListener('changeTableLine', this.changeTableLine)
    MKEmitter.addListener('resetActiveMenu', this.resetActiveMenu)
    MKEmitter.addListener('queryModuleParam', this.queryModuleParam)
    MKEmitter.addListener('refreshByButtonResult', this.refreshByButtonResult)
@@ -1076,6 +1095,7 @@
    document.onkeydown = () => {}
    MKEmitter.removeListener('reloadData', this.reloadData)
    MKEmitter.removeListener('reloadMenuView', this.reloadMenuView)
    MKEmitter.removeListener('changeTableLine', this.changeTableLine)
    MKEmitter.removeListener('resetActiveMenu', this.resetActiveMenu)
    MKEmitter.removeListener('queryModuleParam', this.queryModuleParam)
    MKEmitter.removeListener('refreshByButtonResult', this.refreshByButtonResult)
@@ -1095,7 +1115,7 @@
          {/* 视图组 */}
          {!config.expand ? <Tabs activeKey={chartId} onChange={this.changeChart}>
            {config.charts.map(item => (
              <TabPane tab={<Icon type={item.icon} />} key={item.uuid}></TabPane>
              <TabPane tab={<MkIcon type={item.icon} />} key={item.uuid}></TabPane>
            ))}
          </Tabs> : null}
          {config.charts.map(item => {
@@ -1135,7 +1155,6 @@
                      statFValue={this.state.statFValue}
                      ContainerId={this.state.ContainerId}
                      refreshdata={this.refreshbytable}
                      handleTableId={this.handleTableId}
                      chgSelectData={this.changeSelectedData}
                    />
                  </div>
@@ -1154,7 +1173,6 @@
                    data={this.state.data}
                    loading={this.state.loading}
                    ContainerId={this.state.ContainerId}
                    handleTableId={this.handleTableId}
                  />
                </Col>
              )
@@ -1179,7 +1197,7 @@
              return (
                <TabPane tab={
                  <span id={_tab.uuid}>
                    {_tab.icon ? <Icon type={_tab.icon} /> : null}
                    {_tab.icon ? <MkIcon type={_tab.icon} /> : null}
                    {_tab.label}
                  </span>
                } key={_tab.uuid}>
@@ -1191,7 +1209,6 @@
                    ContainerId={this.state.ContainerId}
                    BID={this.state.BIDs[_tab.supMenu] || ''}
                    BData={this.state.BIDs[_tab.supMenu + 'data'] || ''}
                    handleTableId={this.handleTableId}
                  />
                </TabPane>
              )