| | |
| | | import React, {Component} from 'react' |
| | | import PropTypes from 'prop-types' |
| | | import {connect} from 'react-redux' |
| | | import { is, fromJS } from 'immutable' |
| | | import { fromJS } from 'immutable' |
| | | import {Tabs, Icon, BackTop, notification} from 'antd' |
| | | import moment from 'moment' |
| | | import 'moment/locale/zh-cn' |
| | | |
| | | import { modifyTabview, toggleIsiframe, initActionPermission } from '@/store/action' |
| | | import { toggleIsiframe, initActionPermission } from '@/store/action' |
| | | import asyncComponent from '@/utils/asyncLoadComponent' |
| | | import NotFount from '@/components/404' |
| | | import options from '@/store/options.js' |
| | |
| | | |
| | | class TabViews extends Component { |
| | | static propTpyes = { |
| | | collapse: PropTypes.bool, |
| | | tabviews: PropTypes.array // 标签页数组 |
| | | collapse: PropTypes.bool |
| | | } |
| | | |
| | | state = { |
| | | activeId: '', |
| | | // tabviews: [{ |
| | | // MenuID: 'home_page_id', |
| | | // MenuName: '首页', |
| | | // selected: true, |
| | | // type: 'Home' |
| | | // }], // 标签集 |
| | | tabviews: null, // 标签集 |
| | | iFrameHeight: 0, |
| | | dict: sessionStorage.getItem('lang') !== 'en-US' ? mzhCN : menUS, |
| | | } |
| | | |
| | | // 关闭tab页,重新选择显示页 |
| | | handleTabview = (e, menu, index) => { |
| | | e.stopPropagation() |
| | | let tabs = fromJS(this.state.tabviews).toJS() |
| | | tabs = tabs.filter(tab => { |
| | | return tab.MenuID !== menu.MenuID |
| | | }) |
| | | |
| | | if (menu.selected && tabs[index - 1]) { |
| | | tabs[index - 1].selected = true |
| | | this.setState({ |
| | | activeId: tabs[index - 1].MenuID || '' |
| | | }) |
| | | |
| | | if (this.props.isiframe) { |
| | | this.props.toggleIsiframe(false) |
| | | } |
| | | } |
| | | |
| | | this.props.modifyTabview(tabs) |
| | | } |
| | | |
| | | // 关闭tab页,重新选择显示页 |
| | | closeTabView = (id) => { |
| | | let tabs = fromJS(this.state.tabviews).toJS() |
| | | let index = 0 |
| | | let index = -1 |
| | | |
| | | tabs = tabs.filter((tab, i) => { |
| | | if (tab.MenuID === id) { |
| | | index = i |
| | |
| | | } |
| | | }) |
| | | |
| | | if (tabs[index - 1]) { |
| | | tabs[index - 1].selected = true |
| | | if (index > -1) { |
| | | let activeId = '' |
| | | if (index > 0) { |
| | | activeId = tabs[index - 1].MenuID || '' |
| | | } else if (tabs[index]) { |
| | | activeId = tabs[index].MenuID || '' |
| | | } |
| | | |
| | | this.setState({ |
| | | activeId: tabs[index - 1].MenuID || '' |
| | | activeId, |
| | | tabviews: tabs |
| | | }) |
| | | |
| | | if (this.props.isiframe) { |
| | | this.props.toggleIsiframe(false) |
| | | } |
| | | } |
| | | |
| | | this.props.modifyTabview(tabs) |
| | | let node = document.getElementById('root').parentNode.parentNode |
| | | if (node) { |
| | | node.scrollTop = 0 |
| | | } |
| | | } |
| | | } |
| | | |
| | | refreshTabview = (e, menu) => { |
| | |
| | | } |
| | | } |
| | | |
| | | // modifyTabs = (tab, type) => { |
| | | modifyTabs = (tab, type) => { |
| | | const { tabviews } = this.state |
| | | |
| | | // } |
| | | if (type === 'plus') { |
| | | if (tabviews.findIndex(item => item.MenuID === tab.MenuID) > -1) { |
| | | let _tabs = tabviews.filter(item => item.MenuID !== tab.MenuID) |
| | | this.setState({ |
| | | tabviews: _tabs |
| | | }, () => { |
| | | this.setState({ |
| | | tabviews: [..._tabs, tab], |
| | | activeId: tab.MenuID |
| | | }) |
| | | }) |
| | | } else { |
| | | this.setState({ |
| | | tabviews: [...tabviews, tab], |
| | | activeId: tab.MenuID |
| | | }) |
| | | } |
| | | } else if (type === 'replace') { |
| | | this.setState({ |
| | | tabviews: tab ? [tab] : [], |
| | | activeId: tab ? tab.MenuID : '' |
| | | }) |
| | | } |
| | | |
| | | let node = document.getElementById('root').parentNode.parentNode |
| | | if (node) { |
| | | node.scrollTop = 0 |
| | | } |
| | | } |
| | | |
| | | changeTab = (e, menu) => { |
| | | e.stopPropagation() |
| | | // 窗口切换 |
| | | let tabs = fromJS(this.state.tabviews).toJS() |
| | | tabs = tabs.map(tab => { |
| | | tab.selected = false |
| | | let _isiframe = this.props.isiframe |
| | | if (menu.type === 'iframe') { |
| | | _isiframe = true |
| | | } else { |
| | | _isiframe = false |
| | | } |
| | | |
| | | if (tab.MenuID === menu.MenuID) { |
| | | tab.selected = true |
| | | } |
| | | |
| | | return tab |
| | | }) |
| | | |
| | | if (menu) { |
| | | let _isiframe = this.props.isiframe |
| | | if (menu.type === 'iframe') { |
| | | _isiframe = true |
| | | } else { |
| | | _isiframe = false |
| | | } |
| | | |
| | | if (_isiframe !== this.props.isiframe) { |
| | | this.props.toggleIsiframe(_isiframe) |
| | | } |
| | | if (_isiframe !== this.props.isiframe) { |
| | | this.props.toggleIsiframe(_isiframe) |
| | | } |
| | | |
| | | this.setState({ |
| | | tabviews: tabs, |
| | | activeId: menu.MenuID || '' |
| | | }, () => { |
| | | if (menu.MenuID) { |
| | | MKEmitter.emit('resetActiveMenu', menu.MenuID) |
| | | } |
| | | MKEmitter.emit('resetActiveMenu', menu.MenuID || '') |
| | | }) |
| | | |
| | | this.props.modifyTabview(tabs) |
| | | } |
| | | |
| | | selectcomponent = (view) => { |
| | |
| | | } else { |
| | | moment.locale('en') |
| | | } |
| | | this.setState({ |
| | | tabviews: this.props.tabviews |
| | | }) |
| | | |
| | | 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 () { |
| | | if (sessionStorage.getItem('isEditState') !== 'true') { |
| | | let home = { |
| | | MenuID: 'home_page_id', |
| | | MenuName: '首页', |
| | | selected: true, |
| | | type: 'Home' |
| | | } |
| | | this.props.modifyTabview([home]) |
| | | } |
| | | // MKEmitter.addListener('modifyTabs', this.modifyTabs) |
| | | MKEmitter.addListener('modifyTabs', this.modifyTabs) |
| | | MKEmitter.addListener('closeTabView', this.closeTabView) |
| | | } |
| | | |
| | | UNSAFE_componentWillReceiveProps (nextProps) { |
| | | if (nextProps.tabviews && !is(fromJS(this.state.tabviews), fromJS(nextProps.tabviews))) { |
| | | let view = nextProps.tabviews.filter(tab => tab.selected)[0] |
| | | |
| | | // 窗口在iframe与普通页面切换时,修改左侧菜单栏样式 |
| | | let activeId = '' |
| | | if (view) { |
| | | let _isiframe = this.props.isiframe |
| | | if (view.type === 'iframe') { |
| | | _isiframe = true |
| | | } else { |
| | | _isiframe = false |
| | | } |
| | | |
| | | if (_isiframe !== this.props.isiframe) { |
| | | this.props.toggleIsiframe(_isiframe) |
| | | } |
| | | |
| | | activeId = view.MenuID |
| | | } |
| | | |
| | | // 保存修改标签集 |
| | | this.setState({ |
| | | tabviews: nextProps.tabviews, |
| | | activeId |
| | | }) |
| | | |
| | | let node = document.getElementById('root').parentNode.parentNode |
| | | if (node) { |
| | | node.scrollTop = 0 |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | |
| | | this.setState = () => { |
| | | return |
| | | } |
| | | // MKEmitter.removeListener('modifyTabs', this.modifyTabs) |
| | | MKEmitter.removeListener('modifyTabs', this.modifyTabs) |
| | | MKEmitter.removeListener('closeTabView', this.closeTabView) |
| | | } |
| | | |
| | |
| | | {view.MenuName} |
| | | </span> |
| | | {view.type !== 'Home' ? |
| | | <Icon type="close" onClick={(e) => {this.handleTabview(e, view, index)}}/> : null |
| | | <Icon type="close" onClick={(e) => {e.stopPropagation();this.closeTabView(view.MenuID)}}/> : null |
| | | } |
| | | </span> |
| | | } |
| | |
| | | |
| | | const mapStateToProps = (state) => { |
| | | return { |
| | | tabviews: state.tabviews, |
| | | collapse: state.collapse, |
| | | isiframe: state.isiframe |
| | | } |
| | |
| | | |
| | | const mapDispatchToProps = (dispatch) => { |
| | | return { |
| | | modifyTabview: (tabviews) => dispatch(modifyTabview(tabviews)), |
| | | initActionPermission: (permAction) => dispatch(initActionPermission(permAction)), |
| | | toggleIsiframe: (isiframe) => dispatch(toggleIsiframe(isiframe)) |
| | | } |