import React, {Component} from 'react'
|
import { BackTop, Breadcrumb, notification} from 'antd'
|
import { HomeOutlined, RightOutlined, RedoOutlined } from '@ant-design/icons'
|
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 MKEmitter from '@/utils/events.js'
|
import Api from '@/api'
|
import './index.scss'
|
|
const Home = asyncComponent(() => import('@/tabviews/home'))
|
const CustomPage = asyncComponent(() => import('@/tabviews/custom'))
|
const CommonTable = asyncComponent(() => import('@/tabviews/commontable'))
|
const BaseTable = asyncComponent(() => import('@/tabviews/basetable'))
|
const TreePage = asyncComponent(() => import('@/tabviews/treepage'))
|
const Iframe = asyncComponent(() => import('@/tabviews/iframe'))
|
const RoleManage = asyncComponent(() => import('@/tabviews/rolemanage'))
|
|
moment.locale('zh-cn')
|
|
class BreadView extends Component {
|
state = {
|
tabview: null, // 标签
|
hasNavBar: window.GLOB.navBar === 'linkage_navigation'
|
}
|
|
refreshTabview = () => {
|
const { tabview } = this.state
|
window.GLOB.CacheMap = new Map()
|
|
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
|
})
|
}
|
|
window.GLOB.mkActions = _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)
|
}
|
}
|
|
changeTemp = (MenuID, Template) => {
|
this.setState({
|
tabview: {...this.state.tabview, type: Template}
|
})
|
}
|
|
selectcomponent = (view) => {
|
// 根据tab页中菜单信息,选择所需的组件
|
if (view.type === 'BaseTable') {
|
return (<BaseTable MenuID={view.MenuID} MenuName={view.MenuName} param={view.param} changeTemp={this.changeTemp}/>)
|
} else if (view.type === 'CustomPage') {
|
return (<CustomPage MenuID={view.MenuID} MenuName={view.MenuName} param={view.param} changeTemp={this.changeTemp}/>)
|
} else if (view.type === 'Home') {
|
return (<Home MenuID={view.MenuID} MenuName={view.MenuName}/>)
|
} else if (view.type === 'RolePermission') {
|
return (<RoleManage MenuID={view.MenuID}/>)
|
} 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} param={view.param}/>)
|
} else if (view.type === 'iframe') {
|
return (<Iframe MenuID={view.MenuID} title={view.MenuName} url={view.src}/>)
|
} else {
|
return (<NotFount />)
|
}
|
}
|
|
UNSAFE_componentWillMount () {
|
let home = {
|
MenuID: 'home_page_id',
|
MenuName: '首页',
|
type: 'Home'
|
}
|
this.setState({tabview: home})
|
}
|
|
gotoHome = () => {
|
let home = {
|
MenuID: 'home_page_id',
|
MenuName: '首页',
|
type: 'Home'
|
}
|
this.setState({tabview: home})
|
}
|
|
modifyTabs = (tab) => {
|
this.setState({
|
tabview: tab
|
})
|
|
let node = document.getElementById('root').parentNode.parentNode
|
if (node) {
|
node.scrollTop = 0
|
}
|
}
|
|
componentDidMount () {
|
MKEmitter.addListener('modifyTabs', this.modifyTabs)
|
}
|
|
/**
|
* @description 组件销毁,清除state更新
|
*/
|
componentWillUnmount () {
|
this.setState = () => {
|
return
|
}
|
MKEmitter.removeListener('modifyTabs', this.modifyTabs)
|
}
|
|
render () {
|
const { tabview, hasNavBar } = this.state
|
|
return (
|
<section id="mk-tabgroup-wrap" className="mk-breadview-wrap">
|
{hasNavBar && tabview ? <Breadcrumb separator="">
|
<Breadcrumb.Item>
|
<HomeOutlined onClick={this.gotoHome} />
|
</Breadcrumb.Item>
|
{tabview.ParentNames && tabview.ParentNames[0] ?
|
<Breadcrumb.Item>{tabview.ParentNames[0]}</Breadcrumb.Item> : null}
|
{tabview.ParentNames && tabview.ParentNames[0] ?
|
<Breadcrumb.Separator children={<RightOutlined />} /> : null}
|
{tabview.ParentNames && tabview.ParentNames[1] ?
|
<Breadcrumb.Item>{tabview.ParentNames[1]}</Breadcrumb.Item> : null}
|
{tabview.ParentNames && tabview.ParentNames[1] ?
|
<Breadcrumb.Separator children={<RightOutlined />} /> : null}
|
<Breadcrumb.Item><RedoOutlined onClick={this.refreshTabview}/>{tabview.MenuName}</Breadcrumb.Item>
|
</Breadcrumb> : null}
|
{tabview ? this.selectcomponent(tabview) : null}
|
<BackTop>
|
<div className="ant-back-top">
|
<div className="ant-back-top-content">
|
<div className="ant-back-top-icon"></div>
|
</div>
|
</div>
|
</BackTop>
|
</section>
|
)
|
}
|
}
|
|
export default BreadView
|