| | |
| | | import React, {Component} from 'react' |
| | | import {connect} from 'react-redux' |
| | | import { is, fromJS } from 'immutable' |
| | | import { BackTop, Breadcrumb, Icon} from 'antd' |
| | | import { BackTop, Breadcrumb, Icon, notification} from 'antd' |
| | | import moment from 'moment' |
| | | import 'moment/locale/zh-cn' |
| | | |
| | | import asyncComponent from '@/utils/asyncLoadComponent' |
| | | import NotFount from '@/components/404' |
| | | import options from '@/store/options.js' |
| | | import mzhCN from '@/locales/zh-CN/main.js' |
| | | import menUS from '@/locales/en-US/main.js' |
| | | import MKEmitter from '@/utils/events.js' |
| | | |
| | | import { initActionPermission } from '@/store/action' |
| | | import Api from '@/api' |
| | | import './index.scss' |
| | | |
| | | const Home = asyncComponent(() => import('@/tabviews/home')) |
| | |
| | | state = { |
| | | tabview: null, // 标签 |
| | | dict: sessionStorage.getItem('lang') !== 'en-US' ? mzhCN : menUS, |
| | | hasNavBar: window.GLOB.navBar === 'linkage_navigation' |
| | | } |
| | | |
| | | refreshTabview = () => { |
| | | const { tabview } = this.state |
| | | window.GLOB.CacheMap = new Map() |
| | | |
| | | MKEmitter.emit('reloadMenuView', tabview.MenuID) |
| | | if (options.sysType === 'local' && window.GLOB.systemType !== 'production') { |
| | | let roledefer = new Promise(resolve => { |
| | | Api.getSystemConfig({ |
| | | func: 's_Get_TrdMenu_Role', |
| | | edition_type: 'A', |
| | | pro_sys: '' |
| | | }).then(result => { |
| | | if (!result) return |
| | | if (!result.status) { |
| | | notification.error({ |
| | | top: 92, |
| | | message: result.message, |
| | | duration: 10 |
| | | }) |
| | | } else { |
| | | let _permAction = {loaded: true} // 按钮权限 |
| | | |
| | | if (result.UserRoles_Menu) { |
| | | result.UserRoles_Menu.forEach(menu => { |
| | | if (!menu.MenuID) return |
| | | _permAction[menu.MenuID] = true |
| | | }) |
| | | } |
| | | |
| | | this.props.initActionPermission(_permAction) |
| | | } |
| | | |
| | | resolve() |
| | | }) |
| | | }) |
| | | |
| | | // 获取主菜单参数 |
| | | let menudefer = new Promise(resolve => { |
| | | Api.getAppVersion().then(() => { |
| | | resolve() |
| | | }, () => { |
| | | resolve() |
| | | }) |
| | | }) |
| | | |
| | | Promise.all([roledefer, menudefer]).then(() => { |
| | | MKEmitter.emit('reloadMenuView', tabview.MenuID) |
| | | }) |
| | | } else { |
| | | MKEmitter.emit('reloadMenuView', tabview.MenuID) |
| | | } |
| | | } |
| | | |
| | | selectcomponent = (view) => { |
| | |
| | | |
| | | let home = { |
| | | MenuID: 'home_page_id', |
| | | MenuName: this.state.dict['main.homepage'], |
| | | selected: true, |
| | | MenuName: '首页', |
| | | type: 'Home' |
| | | } |
| | | this.setState({tabview: home}) |
| | |
| | | gotoHome = () => { |
| | | let home = { |
| | | MenuID: 'home_page_id', |
| | | MenuName: this.state.dict['main.homepage'], |
| | | selected: true, |
| | | MenuName: '首页', |
| | | type: 'Home' |
| | | } |
| | | this.setState({tabview: home}) |
| | | } |
| | | |
| | | UNSAFE_componentWillReceiveProps (nextProps) { |
| | | if (nextProps.tabviews && !is(fromJS(this.state.tabviews), fromJS(nextProps.tabviews))) { |
| | | // 保存修改标签集 |
| | | this.setState({ |
| | | tabview: nextProps.tabviews[nextProps.tabviews.length - 1] |
| | | }) |
| | | modifyTabs = (tab, type) => { |
| | | if (!tab || type !== 'replace') return |
| | | |
| | | let node = document.getElementById('root').parentNode.parentNode |
| | | if (node) { |
| | | node.scrollTop = 0 |
| | | } |
| | | this.setState({ |
| | | tabview: tab, |
| | | }) |
| | | |
| | | let node = document.getElementById('root').parentNode.parentNode |
| | | if (node) { |
| | | node.scrollTop = 0 |
| | | } |
| | | } |
| | | |
| | | componentDidMount () { |
| | | MKEmitter.addListener('modifyTabs', this.modifyTabs) |
| | | } |
| | | |
| | | /** |
| | |
| | | this.setState = () => { |
| | | return |
| | | } |
| | | MKEmitter.removeListener('modifyTabs', this.modifyTabs) |
| | | } |
| | | |
| | | render () { |
| | | const { tabview } = this.state |
| | | const { tabview, hasNavBar } = this.state |
| | | |
| | | return ( |
| | | <section id="mk-breadview-wrap" className="mk-breadview-wrap"> |
| | | {tabview ? <Breadcrumb separator=""> |
| | | {hasNavBar && tabview ? <Breadcrumb separator=""> |
| | | <Breadcrumb.Item> |
| | | <Icon type="home" onClick={this.gotoHome} /> |
| | | </Breadcrumb.Item> |
| | |
| | | } |
| | | } |
| | | |
| | | const mapStateToProps = (state) => { |
| | | return { |
| | | tabviews: state.tabviews |
| | | } |
| | | const mapStateToProps = () => { |
| | | return {} |
| | | } |
| | | |
| | | const mapDispatchToProps = () => { |
| | | return {} |
| | | const mapDispatchToProps = (dispatch) => { |
| | | return { |
| | | initActionPermission: (permAction) => dispatch(initActionPermission(permAction)), |
| | | } |
| | | } |
| | | |
| | | export default connect(mapStateToProps, mapDispatchToProps)(BreadView) |