king
2023-08-27 da64ab0923bf8817fc8599a6e37b953ce38f64c8
src/components/tabview/index.jsx
@@ -1,6 +1,4 @@
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import {connect} from 'react-redux'
import { fromJS } from 'immutable'
import {Tabs, BackTop, notification} from 'antd'
import { RedoOutlined, CloseOutlined } from '@ant-design/icons'
@@ -9,7 +7,6 @@
import asyncComponent from '@/utils/asyncLoadComponent'
import NotFount from '@/components/404'
import options from '@/store/options.js'
import MKEmitter from '@/utils/events.js'
import Api from '@/api'
import './index.scss'
@@ -18,21 +15,46 @@
const CustomPage = asyncComponent(() => import('@/tabviews/custom'))
const CommonTable = asyncComponent(() => import('@/tabviews/commontable'))
const BaseTable = asyncComponent(() => import('@/tabviews/basetable'))
const CalendarPage = asyncComponent(() => import('@/tabviews/calendar'))
const TreePage = asyncComponent(() => import('@/tabviews/treepage'))
const Iframe = asyncComponent(() => import('@/tabviews/iframe'))
const RoleManage = asyncComponent(() => import('@/tabviews/rolemanage'))
const FormTab = asyncComponent(() => import('@/tabviews/formtab'))
moment.locale('zh-cn')
class TabViews extends Component {
  static propTpyes = {
    collapse: PropTypes.bool
  }
  state = {
    activeId: '',
    tabviews: null, // 标签集
    tabviews: [],
    iFrameHeight: 0,
  }
  UNSAFE_componentWillMount () {
    if (!window.GLOB.mkHS) {
      this.setState({
        activeId: 'home_page_id',
        tabviews: [{
          MenuID: 'home_page_id',
          MenuName: '首页',
          type: 'Home'
        }]
      })
    }
  }
  componentDidMount () {
    MKEmitter.addListener('modifyTabs', this.modifyTabs)
    MKEmitter.addListener('closeTabView', this.closeTabView)
  }
  /**
   * @description 组件销毁,清除state更新
   */
  componentWillUnmount () {
    this.setState = () => {
      return
    }
    MKEmitter.removeListener('modifyTabs', this.modifyTabs)
    MKEmitter.removeListener('closeTabView', this.closeTabView)
  }
  // 关闭tab页,重新选择显示页
@@ -75,7 +97,7 @@
    e.stopPropagation()
    window.GLOB.CacheMap = new Map()
    if (options.sysType === 'local' && window.GLOB.systemType !== 'production') {
    if (window.GLOB.sysType === 'local' && window.GLOB.systemType !== 'production') {
      let roledefer = new Promise(resolve => {
        Api.getSystemConfig({
          func: 's_Get_TrdMenu_Role',
@@ -195,75 +217,31 @@
  selectcomponent = (view) => {
    // 根据tab页中菜单信息,选择所需的组件
    if (view.type === 'Home') {
      return (<Home MenuNo={view.MenuNo} MenuID={view.MenuID} MenuName={view.MenuName} key={view.MenuID}/>)
    } else if (view.type === 'CommonTable') {
      return (<CommonTable MenuNo={view.MenuNo} MenuID={view.MenuID} MenuName={view.MenuName} key={view.MenuID} param={view.param} changeTemp={this.changeTemp}/>)
      return (<Home MenuID={view.MenuID} MenuName={view.MenuName}/>)
    } else if (view.type === 'BaseTable') {
      return (<BaseTable MenuNo={view.MenuNo} MenuID={view.MenuID} MenuName={view.MenuName} key={view.MenuID} param={view.param} changeTemp={this.changeTemp}/>)
      return (<BaseTable MenuID={view.MenuID} MenuName={view.MenuName} param={view.param} changeTemp={this.changeTemp}/>)
    } else if (view.type === 'CustomPage') {
      return (<CustomPage MenuNo={view.MenuNo} MenuID={view.MenuID} MenuName={view.MenuName} key={view.MenuID} param={view.param} changeTemp={this.changeTemp}/>)
      return (<CustomPage MenuID={view.MenuID} MenuName={view.MenuName} param={view.param} changeTemp={this.changeTemp}/>)
    } else if (view.type === 'CommonTable') {
      return (<CommonTable MenuNo={view.MenuNo} MenuID={view.MenuID} MenuName={view.MenuName} param={view.param} changeTemp={this.changeTemp}/>)
    } else if (view.type === 'TreePage') {
      return (<TreePage MenuNo={view.MenuNo} MenuID={view.MenuID} MenuName={view.MenuName} key={view.MenuID} param={view.param}/>)
    } else if (view.type === 'CalendarPage') {
      return (<CalendarPage MenuNo={view.MenuNo} MenuID={view.MenuID} MenuName={view.MenuName} key={view.MenuID} param={view.param}/>)
      return (<TreePage MenuNo={view.MenuNo} MenuID={view.MenuID} MenuName={view.MenuName} param={view.param}/>)
    } else if (view.type === 'RolePermission') {
      return (<RoleManage MenuNo={view.MenuNo} MenuID={view.MenuID} MenuName={view.MenuName} key={view.MenuID}/>)
    } else if (view.type === 'FormTab') {
      return (<FormTab MenuNo={view.MenuNo} MenuID={view.MenuID} MenuName={view.MenuName} key={view.MenuID} param={view.param}/>)
      return (<RoleManage MenuID={view.MenuID}/>)
    } else if (view.type === 'iframe') {
      return (<Iframe key={view.MenuID} MenuID={view.MenuID} MenuNo={view.MenuNo} title={view.MenuName} MenuName={view.MenuName} url={window.GLOB.baseurl + 'zh-CN/' + view.LinkUrl}/>)
      return (<Iframe MenuID={view.MenuID} title={view.MenuName} url={view.src}/>)
    } else {
      return (<NotFount key={view.MenuID} />)
      return (<NotFount />)
    }
  }
  UNSAFE_componentWillMount () {
    if (!sessionStorage.getItem('lang') || sessionStorage.getItem('lang') === 'zh-CN') {
      moment.locale('zh-cn')
    } else {
      moment.locale('en')
    }
    if (sessionStorage.getItem('isEditState') !== 'true') {
      this.setState({
        activeId: 'home_page_id',
        tabviews: [{
          MenuID: 'home_page_id',
          MenuName: '首页',
          type: 'Home'
        }]
      })
    } else {
      this.setState({
        activeId: '',
        tabviews: []
      })
    }
  }
  componentDidMount () {
    MKEmitter.addListener('modifyTabs', this.modifyTabs)
    MKEmitter.addListener('closeTabView', this.closeTabView)
  }
  /**
   * @description 组件销毁,清除state更新
   */
  componentWillUnmount () {
    this.setState = () => {
      return
    }
    MKEmitter.removeListener('modifyTabs', this.modifyTabs)
    MKEmitter.removeListener('closeTabView', this.closeTabView)
  }
  render () {
    const { tabviews, activeId } = this.state
    return (
      <section className={'mk-tabview-wrap' + (this.props.collapse ? ' collapsed' : '')}>
      <section id="mk-tabgroup-wrap" className="mk-tabview-wrap">
        <div className="content-header">
          {tabviews && tabviews.length > 0 &&
          {tabviews.length > 0 &&
            <Tabs activeKey={activeId}>
              {tabviews.map(view => {
                return (
@@ -300,14 +278,4 @@
  }
}
const mapStateToProps = (state) => {
  return {
    collapse: state.collapse,
  }
}
const mapDispatchToProps = (dispatch) => {
  return {}
}
export default connect(mapStateToProps, mapDispatchToProps)(TabViews)
export default TabViews