king
2020-11-16 3ca91a731665962918a026f521c556f4745ebf35
src/tabviews/formtab/index.jsx
@@ -11,11 +11,12 @@
import Utils from '@/utils/utils.js'
import options from '@/store/options.js'
import asyncComponent from '@/utils/asyncLoadComponent'
import MKEmitter from '@/utils/events.js'
import FormGroup from './formgroup'
import FormAction from './actionList'
import NotFount from '@/components/404'
import {refreshTabView, modifyTabview} from '@/store/action'
import {modifyTabview} from '@/store/action'
import './index.scss'
const { TabPane } = Tabs
@@ -25,7 +26,6 @@
  static propTpyes = {
    MenuID: PropTypes.string,       // 菜单Id
    param: PropTypes.any,           // 主表传递参数
    refresh: PropTypes.any          // 刷新主表页面
  }
  state = {
@@ -40,14 +40,8 @@
    arr_field: '',        // 使用 sPC_Get_TableData 时的查询字段集
    setting: null,        // 页面全局设置:数据源、按钮及显示列固定、主键等
    data: null,           // 列表数据集
    configMap: {},        // 页面配置信息:下拉、按钮等
    BIDs: {},             // 上级表id
    setsingle: false,     // 主表单选多选切换
    pickup: false,        // 主表数据隐藏显示切换
    popData: false,       // 弹框页面,所选的表格数据
    visible: false,       // 弹框显示隐藏控制
    primaryId: null,
    refreshtabs: null
  }
  /**
@@ -503,7 +497,7 @@
      this.setState({
        primaryId: primaryId
      }, () => {
        if (btn.execSuccess === 'refresh') {
        if (btn.execSuccess === 'refresh' || btn.execSuccess === 'grid') {
          this.loadmaindata()
        } else {
          let data = {}
@@ -524,53 +518,39 @@
        }
      })
    } else if (type === 'success' && btn.afterExecSuccess === 'close') {
      if (this.props.refresh) {
        this.props.refresh(btn.execSuccess)
      } else {
        if (btn.execSuccess !== 'never') {
          let PMenu = {
            MenuID: this.props.param.parentId || ''
          }
          this.props.refreshTabView(PMenu)
      if (btn.execSuccess !== 'never') {
        MKEmitter.emit('reloadData', this.props.param.parentId, 'formtab', btn)
      }
      let tabs = this.props.tabviews.filter(tab => {
        tab.selected = false
        if (tab.MenuID === this.props.param.parentId) {
          tab.selected = true
        }
        let tabs = this.props.tabviews.filter(tab => {
          tab.selected = false
          if (tab.MenuID === this.props.param.parentId) {
            tab.selected = true
          }
        return tab.MenuID !== this.props.MenuID
      })
          return tab.MenuID !== this.props.MenuID
        })
        this.props.modifyTabview(tabs)
      }
      this.props.modifyTabview(tabs)
    } else if (type === 'error' && btn.afterExecError === 'notclose') {
      if (btn.execError === 'refresh') {
        this.loadmaindata()
      }
    } else if (type === 'error' && btn.afterExecError === 'close') {
      if (this.props.refresh) {
        this.props.refresh(btn.execError)
      } else {
        if (btn.execError !== 'never') {
          let PMenu = {
            MenuID: this.props.param.parentId || '',
          }
          this.props.refreshTabView(PMenu)
      if (btn.execError !== 'never') {
        MKEmitter.emit('reloadData', this.props.param.parentId, 'formtab', btn)
      }
      let tabs = this.props.tabviews.filter(tab => {
        tab.selected = false
        if (tab.MenuID === this.props.param.parentId) {
          tab.selected = true
        }
        let tabs = this.props.tabviews.filter(tab => {
          tab.selected = false
          if (tab.MenuID === this.props.param.parentId) {
            tab.selected = true
          }
        return tab.MenuID !== this.props.MenuID
      })
          return tab.MenuID !== this.props.MenuID
        })
        this.props.modifyTabview(tabs)
      }
      this.props.modifyTabview(tabs)
    }
  }
@@ -590,31 +570,6 @@
  }
  /**
   * @description 子表操作完成后刷新主表
   */
  handleMainTable = (type, tab) => {
    if ((type === 'maingrid' || type === 'mainline') && tab.supMenu === 'mainTable') {
      this.loadmaindata()
    } 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
        })
      })
    }
  }
  /**
   * @description 获取表单参数
   */
  getFormData = () => {
@@ -629,20 +584,29 @@
      config: {},
      groups: null,
      actions: null,
      arr_field: '',
      setting: null,
      data: null,
      configMap: {},
      BIDs: {},
      setsingle: false,
      pickup: false,
      popData: false,
      visible: false,
      primaryId: null,
      refreshtabs: null
    }, () => {
      this.loadconfig()
    })
  }
  reloadMenuView = (menuId) => {
    const { MenuID } = this.props
    if (MenuID !== menuId) return
    this.reloadview()
  }
  reloadData = (menuId) => {
    const { MenuID } = this.props
    if (MenuID !== menuId) return
    this.loadmaindata()
  }
  UNSAFE_componentWillMount () {
@@ -650,15 +614,13 @@
    this.loadconfig()
  }
  UNSAFE_componentWillReceiveProps(nextProps) {
    if (nextProps.refreshTab && nextProps.refreshTab.MenuID === this.props.MenuID) {
      this.reloadview()
      this.props.refreshTabView('')
    }
  }
  shouldComponentUpdate (nextProps, nextState) {
    return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState))
  }
  componentDidMount () {
    MKEmitter.addListener('reloadMenuView', this.reloadMenuView)
    MKEmitter.addListener('reloadData', this.reloadData)
  }
  /**
@@ -668,6 +630,9 @@
    this.setState = () => {
      return
    }
    MKEmitter.removeListener('reloadMenuView', this.reloadMenuView)
    MKEmitter.removeListener('reloadData', this.reloadData)
  }
  render() {
@@ -722,12 +687,10 @@
                          Tab={_tab}
                          MenuID={_tab.linkTab}
                          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)}
                        /> : null}
                    </TabPane>
                  )
@@ -746,7 +709,6 @@
  return {
    menuType: state.editLevel,
    tabviews: state.tabviews,
    refreshTab: state.refreshTab,
    permAction: state.permAction,
    dataManager: state.dataManager,
    permRoles: state.permRoles
@@ -755,7 +717,6 @@
const mapDispatchToProps = (dispatch) => {
  return {
    refreshTabView: (refreshTab) => dispatch(refreshTabView(refreshTab)),
    modifyTabview: (tabviews) => dispatch(modifyTabview(tabviews))
  }
}