king
2020-11-16 3ca91a731665962918a026f521c556f4745ebf35
src/tabviews/commontable/index.jsx
@@ -13,7 +13,6 @@
import UtilsUpdate from '@/utils/utils-update.js'
import asyncComponent from '@/utils/asyncComponent'
import asyncSpinComponent from '@/utils/asyncSpinComponent'
import { refreshTabView } from '@/store/action'
import MKEmitter from '@/utils/events.js'
import MainSearch from '@/tabviews/zshare/topSearch'
@@ -66,7 +65,6 @@
    BIDs: {},             // 上级表id
    pickup: false,        // 主表数据隐藏显示切换
    treevisible: false,   // 菜单结构树弹框显示隐藏控制
    refreshtabs: null,    // 需要刷新的标签集
    tabActive: null,      // 标签页展开控制
    chartId: '',          // 展开图表ID
    statFields: [],       // 合计字段
@@ -545,6 +543,59 @@
  }
  /**
   * @description 获取单行数据
   */
  async loadmainLinedata (id) {
    const { setting, arr_field, search, orderBy, BID, pageIndex, pageSize } = this.state
    this.setState({
      loading: true
    })
    let _orderBy = orderBy || setting.order
    let param = UtilsDM.getQueryDataParams(setting, arr_field, search, _orderBy, pageIndex, pageSize, BID, this.props.menuType, this.props.dataManager, id)
    if (param.func === 'sPC_Get_TableData') {
      param.menuname = this.props.MenuName || ''
    }
    let result = await Api.genericInterface(param)
    if (result.status) {
      let data = fromJS(this.state.data).toJS()
      if (result.data && result.data[0]) {
        let _data = result.data[0]
        try {
          data = data.map(item => {
            if (item[setting.primaryKey] === _data[setting.primaryKey]) {
              _data.key = item.key
              return _data
            } else {
              return item
            }
          })
        } catch {
          console.warn('数据查询错误')
        }
      }
      this.setState({
        data: data,
        loading: false
      })
    } else {
      this.setState({
        loading: false
      })
      notification.error({
        top: 92,
        message: result.message,
        duration: 10
      })
    }
  }
  /**
   * @description 获取合计字段值
   */
  getStatFieldsValue = () => {
@@ -649,7 +700,8 @@
  /**
   * @description 表格刷新
   */
  reloadtable = () => {
  reloadtable = (btn) => {
    if (!btn || btn.resetPageIndex !== 'false') {
    MKEmitter.emit('resetTable', this.props.MenuID + 'mainTable') // 列表重置
    this.setState({
      pageIndex: 1
@@ -657,13 +709,18 @@
      this.loadmaindata()
      this.getStatFieldsValue()
    })
    } else {
      MKEmitter.emit('resetTable', this.props.MenuID + 'mainTable', 'false') // 列表重置
      this.loadmaindata()
      this.getStatFieldsValue()
    }
  }
  /**
   * @description 页面刷新,重新获取配置
   */
  reloadview = () => {
    this.setState({ loadingview: true, viewlost: false, lostmsg: '',
    this.setState({ loadingview: true, viewlost: false, config: {}, setting: null,
      data: null, total: 0, loading: false, pageIndex: 1,
      pageSize: 10, orderBy: '', search: '', BIDs: {}, pickup: false
    }, () => {
@@ -674,38 +731,9 @@
  /**
   * @description 按钮操作完成后(成功或失败),页面刷新,重置页码及选择项
   */
  refreshbyaction = (position) => {
    if (position === 'grid') {
      this.reloadtable()
    } else if (position === 'view') {
      this.reloadview()
    }
  }
  /**
   * @description 子表操作完成后刷新主表
   */
  handleMainTable = (type, tab) => {
    if (type === 'maingrid' && tab.supMenu === 'mainTable') {
      this.reloadtable()
    } else if (type === 'mainline' && tab.supMenu === 'mainTable') {
      this.reloadtable()
    } else if ((type === 'maingrid' || type === 'mainline') && tab.supMenu) {
      this.setState({
        refreshtabs: [type, tab.supMenu]
      }, () => {
        this.setState({
          refreshtabs: null
        })
      })
    } else if (type === 'equaltab' && tab.equalTab && tab.equalTab.length > 0) {
      this.setState({
        refreshtabs: tab.equalTab
      }, () => {
        this.setState({
          refreshtabs: null
        })
      })
  refreshbyaction = (position, btn) => {
    if (position === 'grid' || position === 'view') {
      this.reloadtable(btn)
    }
  }
@@ -822,16 +850,47 @@
    this.setState({chartId: uuid})
  }
  reloadData = (menuId, id, btn) => {
    const { MenuID } = this.props
    if (MenuID !== menuId) return
    if (id === 'empty') return
    if (id === 'formtab') { // 表单标签页刷新
      this.reloadtable(btn)
      return
    }
    if (!id) {
      this.reloadtable()
    } else {
      this.loadmainLinedata(id)
    }
  }
  reloadMenuView = (menuId) => {
    const { MenuID } = this.props
    if (MenuID !== menuId) return
    this.reloadview()
  }
  resetActiveMenu = (menuId) => {
    const { MenuID } = this.props
    if (MenuID !== menuId) return
    this.setShortcut()
  }
  UNSAFE_componentWillMount () {
    // 组件加载时,获取菜单数据
    this.loadconfig()
  }
  UNSAFE_componentWillReceiveProps(nextProps) {
    if (nextProps.refreshTab && nextProps.refreshTab.MenuID === this.props.MenuID) {
      this.reloadview()
      this.props.refreshTabView('')
    } else if (!is(fromJS(this.props.tabviews), fromJS(nextProps.tabviews))) {
     if (!is(fromJS(this.props.tabviews), fromJS(nextProps.tabviews))) {
      let selectTab = nextProps.tabviews.filter(tab => tab.selected)[0]
      if (selectTab && selectTab.MenuID === this.props.MenuID) {
        this.setShortcut()
@@ -851,6 +910,12 @@
    return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState))
  }
  componentDidMount () {
    MKEmitter.addListener('reloadData', this.reloadData)
    MKEmitter.addListener('reloadMenuView', this.reloadMenuView)
    MKEmitter.addListener('resetActiveMenu', this.resetActiveMenu)
  }
  /**
   * @description 组件销毁,清除state更新,清除快捷键设置
   */
@@ -859,6 +924,9 @@
      return
    }
    document.onkeydown = () => {}
    MKEmitter.removeListener('reloadData', this.reloadData)
    MKEmitter.removeListener('reloadMenuView', this.reloadMenuView)
    MKEmitter.removeListener('resetActiveMenu', this.resetActiveMenu)
  }
  render() {
@@ -1001,12 +1069,10 @@
                      mainSearch={_tab.searchPass === 'true' ? search : null}
                      userConfig={userConfig ? userConfig[_tab.uuid] : null}
                      SupMenuID={this.props.MenuID}
                      refreshtabs={this.state.refreshtabs}
                      ContainerId={this.state.ContainerId}
                      BID={this.state.BIDs[_tab.supMenu] || ''}
                      BData={this.state.BIDs[_tab.supMenu + 'data'] || ''}
                      handleTableId={this.handleTableId}
                      handleMainTable={(type) => this.handleMainTable(type, _tab)}
                    />
                  </TabPane>
                )
@@ -1050,7 +1116,6 @@
  return {
    menuType: state.editLevel,
    tabviews: state.tabviews,
    refreshTab: state.refreshTab,
    permAction: state.permAction,
    permMenus: state.permMenus,
    permRoles: state.permRoles,
@@ -1058,10 +1123,8 @@
  }
}
const mapDispatchToProps = (dispatch) => {
  return {
    refreshTabView: (refreshTab) => dispatch(refreshTabView(refreshTab))
  }
const mapDispatchToProps = () => {
  return {}
}
export default connect(mapStateToProps, mapDispatchToProps)(NormalTable)