From a94b0a4d15b26ecf8fe99f0a1c3e60d60b97766d Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期二, 15 八月 2023 14:22:03 +0800 Subject: [PATCH] 2023-08-15 --- src/views/mkiframe/index.jsx | 242 ++++++++++++++++++++++++++++++++++++++++------- 1 files changed, 203 insertions(+), 39 deletions(-) diff --git a/src/views/mkiframe/index.jsx b/src/views/mkiframe/index.jsx index 6cfd00d..3f11727 100644 --- a/src/views/mkiframe/index.jsx +++ b/src/views/mkiframe/index.jsx @@ -1,66 +1,230 @@ import React, {Component} from 'react' -import { Spin } from 'antd' +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 + loading: true, + BID: '', + MenuId: '', + type: 'CustomPage' } UNSAFE_componentWillMount() { - const { menuId, userId, loginUid, bid } = this.props.match.params + const { params, path } = this.props.match + const { menuId, loginUid, bid } = params - sessionStorage.setItem('LoginUID', '202306221645124938E53FE0520A64CE2B486') - // sessionStorage.setItem('LoginUID', loginUid) - console.log(userId) - Api.getTouristMsg('login_check', 'http://demo.mk9h.cn/erp_new/webapi/dostars').then(res => { - console.log(res) - if (res.status) { - - } else { - - } + 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 + }) }) } - componentDidMount() { - // sessionStorage.setItem('ThirdMenu', this.props.match.params.menuId) + closeTabView = () => { + let historys = sessionStorage.getItem('page_historys') + historys = historys ? JSON.parse(historys) : [] - // if (sessionStorage.getItem('UserID')) { - // this.props.history.replace('/main') - // } else { - // localStorage.setItem('getSessionStorage', window.GLOB.appkey) + if (historys.length === 0) return + + let tab = historys.shift() + + sessionStorage.setItem('page_historys', JSON.stringify(historys)) - // window.addEventListener('storage', function(event) { - // if (event.key === 'sessionStorage' && event.newValue && !sessionStorage.getItem('UserID')) { - // let values = event.newValue - // values = JSON.parse(values) + this.setState({ + MenuId: tab.MenuId, + BID: tab.BID, + loading: true + }, () => { + this.setState({ + loading: false + }) + }) + } - // Object.keys(values).forEach(key => { - // sessionStorage.setItem(key, values[key]) - // }) - // } - // }) + 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 + } - // setTimeout(() => { - // localStorage.removeItem('getSessionStorage') - // localStorage.removeItem('sessionStorage') + 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 - // if (sessionStorage.getItem('UserID')) { - // this.props.history.replace('/main') - // } else { - // this.props.history.replace('/login') - // } - // }, 20) - // } + this.setState({loading: false}) + }) + } + + changeTemp = (MenuID, Template) => { + this.setState({ + type: Template + }) } render () { + const { loading, BID, MenuId, type } = this.state + return ( <div className="main-iframe"> - <Spin size="large" /> + <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> ) } -- Gitblit v1.8.0