| | |
| | | import PropTypes from 'prop-types' |
| | | import {connect} from 'react-redux' |
| | | import { is, fromJS } from 'immutable' |
| | | import {Tabs, Icon, Button, ConfigProvider, message} from 'antd' |
| | | import {Tabs, Icon, Button, ConfigProvider, message, BackTop} from 'antd' |
| | | import {modifyTabview, toggleIsiframe} from '@/store/action' |
| | | // import asyncComponent from '@/utils/asyncComponent' |
| | | import asyncComponent from '@/utils/asyncLoadComponent' |
| | |
| | | } |
| | | |
| | | state = { |
| | | selectedTabId: '', // 当前选中tab页面 |
| | | tabviews: null, // 标签集 |
| | | iFrameHeight: 0, |
| | | dict: (!sessionStorage.getItem('lang') || sessionStorage.getItem('lang') === 'zh-CN') ? mzhCN : menUS, |
| | | locale: (!sessionStorage.getItem('lang') || sessionStorage.getItem('lang') === 'zh-CN') ? zhCN : enUS |
| | | } |
| | | |
| | | handleTabview (menu) { |
| | | handleTabview (e, menu) { |
| | | e.stopPropagation() |
| | | // 关闭tab页,重新选择显示页 |
| | | let tabs = JSON.parse(JSON.stringify(this.props.tabviews)) |
| | | let tabs = JSON.parse(JSON.stringify(this.state.tabviews)) |
| | | tabs = tabs.filter(tab => { |
| | | if (tab.MenuID === this.state.selectedTabId) { |
| | | tab.selected = true |
| | | } else { |
| | | tab.selected = false |
| | | } |
| | | return tab.MenuID !== menu.MenuID |
| | | }) |
| | | |
| | | if (menu.MenuID === this.state.selectedTabId) { |
| | | if (menu.selected) { |
| | | tabs[0] && (tabs[0].selected = true) |
| | | } |
| | | |
| | | this.props.modifyTabview(tabs) |
| | | } |
| | | |
| | | changeTab (menu) { |
| | | changeTab (e, menu) { |
| | | e.stopPropagation() |
| | | // 窗口切换 |
| | | this.setState({ |
| | | selectedTabId: menu.MenuID |
| | | }) |
| | | let tabs = JSON.parse(JSON.stringify(this.props.tabviews)) |
| | | let tabs = JSON.parse(JSON.stringify(this.state.tabviews)) |
| | | tabs = tabs.map(tab => { |
| | | tab.selected = false |
| | | |
| | | if (tab.MenuID === menu.MenuID) { |
| | | tab.selected = true |
| | | } else { |
| | | tab.selected = false |
| | | } |
| | | |
| | | return tab |
| | | }) |
| | | |
| | | this.setState({ |
| | | tabviews: tabs |
| | | }) |
| | | |
| | | this.props.modifyTabview(tabs) |
| | | this.resetWindow(menu) |
| | | } |
| | | |
| | | selectcomponent (view) { |
| | |
| | | return (<Comps.CommonTable MenuNo={view.MenuNo} MenuID={view.MenuID} MenuName={view.MenuName} key={view.MenuID}/>) |
| | | } else if (view.type === 'DataManage') { |
| | | return (<Comps.DataManage MenuNo={view.MenuNo} MenuID={view.MenuID} MenuName={view.MenuName} key={view.MenuID}/>) |
| | | } else if (view.type === 'RoleManage') { |
| | | } else if (view.type === 'RolePermission') { |
| | | return (<Comps.RoleManage MenuNo={view.MenuNo} MenuID={view.MenuID} MenuName={view.MenuName} key={view.MenuID}/>) |
| | | } else if (view.type === 'TabForm') { |
| | | return (<Comps.TabForm MenuNo={view.MenuNo} MenuID={view.MenuID} MenuName={view.MenuName} key={view.MenuID} param={view.param}/>) |
| | |
| | | } else { |
| | | moment.locale('en') |
| | | } |
| | | this.setState({ |
| | | tabviews: this.props.tabviews |
| | | }) |
| | | } |
| | | |
| | | componentDidMount () { |
| | |
| | | } |
| | | |
| | | UNSAFE_componentWillReceiveProps (nextProps) { |
| | | if (nextProps.tabviews && !is(fromJS(this.props.tabviews), fromJS(nextProps.tabviews))) { |
| | | if (nextProps.tabviews && !is(fromJS(this.state.tabviews), fromJS(nextProps.tabviews))) { |
| | | // tab窗口页增加或删除 |
| | | if (nextProps.tabviews.length > this.props.tabviews.length) { |
| | | if (nextProps.tabviews.length > this.state.tabviews.length) { |
| | | // 查看新tab页需要组件是否加载 |
| | | let MenuIDs = this.props.tabviews.map(tab => {return tab.MenuID}) |
| | | let MenuIDs = this.state.tabviews.map(tab => {return tab.MenuID}) |
| | | let newtab = nextProps.tabviews.filter(tab => !MenuIDs.includes(tab.MenuID))[0] |
| | | if (!Comps.Home && newtab.type === 'Home') { |
| | | Comps.Home = asyncComponent(() => import('@/tabviews/home')) |
| | |
| | | Comps.Iframe = asyncComponent(() => import('@/tabviews/iframe')) |
| | | } else if (!Comps.DataManage && newtab.type === 'DataManage') { |
| | | Comps.DataManage = asyncComponent(() => import('@/tabviews/datamanage')) |
| | | } else if (!Comps.RoleManage && newtab.type === 'RoleManage') { |
| | | } else if (!Comps.RoleManage && newtab.type === 'RolePermission') { |
| | | Comps.RoleManage = asyncComponent(() => import('@/tabviews/rolemanage')) |
| | | } else if (!Comps.TabForm && newtab.type === 'TabForm') { |
| | | Comps.TabForm = asyncComponent(() => import('@/tabviews/tabform')) |
| | |
| | | } |
| | | } |
| | | |
| | | // 设置选中窗口 |
| | | let view = nextProps.tabviews.filter(tab => tab.selected)[0] |
| | | // 保存修改标签集 |
| | | this.setState({ |
| | | selectedTabId: view ? view.MenuID : '' |
| | | tabviews: nextProps.tabviews |
| | | }) |
| | | this.resetWindow(view) |
| | | |
| | | let node = document.getElementById('root').parentNode.parentNode |
| | | if (node) { |
| | | node.scrollTop = 0 |
| | | } |
| | | } |
| | | } |
| | | |
| | | shouldComponentUpdate(nextProps, nextState) { |
| | | return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState)) |
| | | } |
| | | // shouldComponentUpdate(nextProps, nextState) { |
| | | // return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState)) |
| | | // } |
| | | |
| | | render () { |
| | | const { tabviews } = this.state |
| | | let view = tabviews.filter(tab => tab.selected)[0] |
| | | this.resetWindow(view) |
| | | let selectedTabId = view ? view.MenuID : '' |
| | | |
| | | return ( |
| | | <section className={'flex-container content-box' + (this.props.collapse ? ' collapsed' : '')}> |
| | | <ConfigProvider locale={this.state.locale}> |
| | | <div className="content-header"> |
| | | {this.props.tabviews && this.props.tabviews.length > 0 && |
| | | <Tabs activeKey={this.state.selectedTabId}> |
| | | {this.props.tabviews.map(view => { |
| | | {tabviews && tabviews.length > 0 && |
| | | <Tabs activeKey={selectedTabId}> |
| | | {tabviews.map(view => { |
| | | return ( |
| | | <Tabs.TabPane |
| | | className="test" |
| | | tab={ |
| | | <span className="tab-control"> |
| | | <span className="tab-name" onClick={() => {this.changeTab(view)}}> |
| | | <span className="tab-name" onClick={(e) => {this.changeTab(e, view)}}> |
| | | {view.MenuName} |
| | | </span> |
| | | {view.type !== 'Home' ? <Icon type="close" onClick={() => {this.handleTabview(view)}}/> : null} |
| | | {view.type !== 'Home' ? <Icon type="close" onClick={(e) => {this.handleTabview(e, view)}}/> : null} |
| | | </span> |
| | | } |
| | | key={view.MenuID} |
| | | > |
| | | {this.selectcomponent(view)} |
| | | <Button className={'main-copy ' + (view.type === 'iframe' ? 'ifr-copy' : '')} icon="copy" data-menuno={view.MenuNo} onClick={this.copyMenuNo} shape="circle" /> |
| | | {view.type !== 'CommonTable' ? |
| | | <Button |
| | | icon="copy" |
| | | shape="circle" |
| | | className={'main-copy ' + (view.type === 'iframe' ? 'ifr-copy' : '')} |
| | | data-menuno={view.MenuNo} |
| | | onClick={this.copyMenuNo} |
| | | /> : null |
| | | } |
| | | <BackTop> |
| | | <div className="ant-back-top"> |
| | | <div className="ant-back-top-content"> |
| | | <div className="ant-back-top-icon"></div> |
| | | </div> |
| | | </div> |
| | | </BackTop> |
| | | </Tabs.TabPane> |
| | | ) |
| | | })} |