import React, {Component} from 'react'
|
import { Spin, notification, ConfigProvider } from 'antd'
|
import zhCN from 'antd/es/locale/zh_CN'
|
|
import Api from '@/api'
|
import asyncComponent from '@/utils/asyncLoadComponent'
|
import MKEmitter from '@/utils/events.js'
|
import ImgScale from '@/components/imgScale'
|
import './index.scss'
|
|
const CustomPage = asyncComponent(() => import('@/tabviews/custom'))
|
const BaseTable = asyncComponent(() => import('@/tabviews/basetable'))
|
|
class MkIframe extends Component {
|
state = {
|
loading: true,
|
BID: '',
|
MenuId: '',
|
type: 'CustomPage'
|
}
|
|
UNSAFE_componentWillMount() {
|
const { params, path } = this.props.match
|
const { menuId, loginUid, bid } = params
|
|
if (/^\/view\//.test(path)) {
|
localStorage.setItem('getSysPermission', window.GLOB.appkey)
|
const that = this
|
|
window.addEventListener('storage', function(event) {
|
if (event.key === 'sysPermissions' && event.newValue) {
|
let values = event.newValue
|
values = JSON.parse(values)
|
|
window.GLOB.mkThdMenus = values.mkThdMenus
|
window.GLOB.mkActions = values.mkActions
|
} else if (event.key === 'menuUpdate') {
|
let vals = event.newValue.split(',')
|
let MenuId = vals[1]
|
let position = vals[2] || ''
|
if (position === 'menu' && menuId === MenuId) {
|
that.setState({loading: true}, () => {
|
that.setState({loading: false})
|
})
|
}
|
}
|
})
|
|
setTimeout(() => {
|
localStorage.removeItem('getSysPermission')
|
localStorage.removeItem('sysPermissions')
|
|
if (window.GLOB.mkActions && window.GLOB.mkActions.loaded) {
|
this.setState({loading: false})
|
} else {
|
this.getPermRole()
|
}
|
}, 20)
|
} else if (sessionStorage.getItem('UserID')) {
|
this.getPermRole()
|
} else {
|
sessionStorage.setItem('LoginUID', loginUid)
|
|
Api.getTouristMsg('login_check').then(res => {
|
if (res.status) {
|
sessionStorage.setItem('UserID', res.UserID)
|
sessionStorage.setItem('LoginUID', res.LoginUID)
|
sessionStorage.setItem('User_Name', res.UserName)
|
sessionStorage.setItem('Full_Name', res.FullName)
|
sessionStorage.setItem('avatar', res.icon || '')
|
sessionStorage.setItem('dataM', res.dataM ? 'true' : '')
|
sessionStorage.setItem('debug', res.debug || '')
|
sessionStorage.setItem('role_id', res.role_id || '')
|
sessionStorage.setItem('departmentcode', res.departmentcode || '')
|
sessionStorage.setItem('organization', res.organization || '')
|
sessionStorage.setItem('mk_user_type', res.mk_user_type || '')
|
this.getPermRole()
|
} else {
|
sessionStorage.clear()
|
sessionStorage.setItem('iframe', `/iframe/${menuId}/@loginuid@/${bid || ''}`)
|
this.props.history.replace('/login')
|
}
|
})
|
}
|
|
this.setState({BID: bid || '', MenuId: menuId})
|
}
|
|
componentDidMount () {
|
MKEmitter.addListener('modifyTabs', this.modifyTabs)
|
MKEmitter.addListener('closeTabView', this.closeTabView)
|
|
if (window.GLOB.sysType !== 'cloud') {
|
Object.defineProperty(window, 'debugger', {
|
configurable: true,
|
enumerable: true,
|
set(value) {
|
if (value + '' === 'false') {
|
window.GLOB.debugger = false
|
} else {
|
window.GLOB.debugger = true
|
}
|
}
|
})
|
|
Object.defineProperty(window, 'debug', {
|
configurable: true,
|
enumerable: true,
|
set(value) {
|
if (value + '' === 'false') {
|
window.GLOB.debugger = false
|
window.GLOB.breakpoint = false
|
sessionStorage.removeItem('breakpoint')
|
} else {
|
window.GLOB.debugger = true
|
window.GLOB.breakpoint = value + ''
|
sessionStorage.setItem('breakpoint', value)
|
}
|
MKEmitter.emit('debugChange')
|
}
|
})
|
}
|
}
|
|
/**
|
* @description 组件销毁,清除state更新
|
*/
|
componentWillUnmount () {
|
this.setState = () => {
|
return
|
}
|
MKEmitter.removeListener('modifyTabs', this.modifyTabs)
|
MKEmitter.removeListener('closeTabView', this.closeTabView)
|
}
|
|
modifyTabs = (tab) => {
|
const { MenuId, BID } = this.state
|
|
let _menuId = tab.MenuID
|
let _BID = tab.param && tab.param.$BID ? tab.param.$BID : ''
|
|
let historys = sessionStorage.getItem('page_historys')
|
historys = historys ? JSON.parse(historys) : []
|
|
historys.push({MenuId: MenuId, BID: BID})
|
|
sessionStorage.setItem('page_historys', JSON.stringify(historys))
|
|
this.setState({
|
MenuId: _menuId,
|
BID: _BID,
|
loading: true
|
}, () => {
|
this.setState({
|
loading: false
|
})
|
})
|
}
|
|
closeTabView = () => {
|
let historys = sessionStorage.getItem('page_historys')
|
historys = historys ? JSON.parse(historys) : []
|
|
if (historys.length === 0) return
|
|
let tab = historys.shift()
|
|
sessionStorage.setItem('page_historys', JSON.stringify(historys))
|
|
this.setState({
|
MenuId: tab.MenuId,
|
BID: tab.BID,
|
loading: true
|
}, () => {
|
this.setState({
|
loading: false
|
})
|
})
|
}
|
|
getPermRole = () => {
|
Api.getSystemConfig({
|
func: 's_Get_TrdMenu_Role',
|
edition_type: 'A',
|
pro_sys: window.GLOB.systemType === 'production' ? 'Y' : ''
|
}).then(result => {
|
if (!result.status) {
|
notification.error({
|
top: 92,
|
message: result.message,
|
duration: 10
|
})
|
return
|
}
|
|
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
|
|
this.setState({loading: false})
|
})
|
}
|
|
changeTemp = (MenuID, Template) => {
|
this.setState({
|
type: Template
|
})
|
}
|
|
render () {
|
const { loading, BID, MenuId, type } = this.state
|
|
return (
|
<div className="main-iframe">
|
<ConfigProvider locale={zhCN}>
|
{loading ? <Spin size="large" /> : null}
|
{!loading && type === 'CustomPage' ? <CustomPage MenuID={MenuId} param={{$BID: BID}} changeTemp={this.changeTemp}/> : null}
|
{!loading && type === 'BaseTable' ? <BaseTable MenuID={MenuId} param={{$BID: BID}} changeTemp={this.changeTemp}/> : null}
|
</ConfigProvider>
|
<ImgScale />
|
</div>
|
)
|
}
|
}
|
|
export default MkIframe
|