From 7e46c386be5c2cfc20af3936d26839ad3fce44b0 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期三, 16 八月 2023 17:40:32 +0800 Subject: [PATCH] Merge branch 'master' into positec --- src/components/header/index.jsx | 170 +++++++++++++++++++++++++------------------------------- 1 files changed, 75 insertions(+), 95 deletions(-) diff --git a/src/components/header/index.jsx b/src/components/header/index.jsx index c9d7275..032fd3d 100644 --- a/src/components/header/index.jsx +++ b/src/components/header/index.jsx @@ -1,16 +1,9 @@ import React, {Component} from 'react' import { withRouter } from 'react-router-dom' -import PropTypes from 'prop-types' -import {connect} from 'react-redux' import { is, fromJS } from 'immutable' import { Dropdown, Menu, Modal, notification, Switch, Input } from 'antd' import { SearchOutlined, DownOutlined, MenuFoldOutlined, MenuUnfoldOutlined } from '@ant-design/icons' -import { - toggleCollapse, - modifyMainMenu, - logout -} from '@/store/action' import asyncSpinComponent from '@/utils/asyncSpinComponent' import asyncComponent from '@/utils/asyncComponent' import Api from '@/api' @@ -26,9 +19,6 @@ const LoginForm = asyncSpinComponent(() => import('./loginform')) class Header extends Component { - static propTpyes = { - collapse: PropTypes.bool - } state = { menulist: null, // 涓�绾ц彍鍗� userName: '', @@ -40,13 +30,73 @@ systems: [], searchkey: '', thdMenuList: [], - debug: sessionStorage.getItem('debug') === 'true' + debug: sessionStorage.getItem('debug') === 'true', + collapse: sessionStorage.getItem('collapse') === 'true' + } + + UNSAFE_componentWillMount () { + window.GLOB.mainMenu = null + // 缁勪欢鍔犺浇鏃讹紝鑾峰彇鑿滃崟鏁版嵁 + this.getRolesMenu() + + let fullName = sessionStorage.getItem('Full_Name') || '' + let userName = sessionStorage.getItem('User_Name') || '' + + if (fullName.toLowerCase() === userName.toLowerCase()) { + userName = '' + } + + this.setState({fullName, userName}) + } + + componentDidMount () { + // 鑾峰彇绯荤粺鐨勭増鏈俊鎭紝寤舵椂鏌ヨ + setTimeout(() => { + Api.getAppVersion() + }, 1000) + + // sessionStorage 璺ㄩ〉闈㈠叡浜� + window.addEventListener('storage', (e) => { + if (e.key === 'getSessionStorage' && e.newValue === window.GLOB.appkey) { + localStorage.setItem('sessionStorage', JSON.stringify(sessionStorage)) + } else if (e.key === 'getSysPermission' && e.newValue === window.GLOB.appkey) { + localStorage.setItem('sysPermissions', JSON.stringify({mkThdMenus: window.GLOB.mkThdMenus, mkActions: window.GLOB.mkActions})) + } else if (e.key === 'menuUpdate') { + let vals = e.newValue.split(',') + let menuId = vals[1] + let position = vals[2] || '' + if (position === 'menu') { + MKEmitter.emit('reloadMenuView', menuId) + } else if (menuId) { + Api.getAppVersion(menuId).then(() => { + MKEmitter.emit('reloadMenuView', menuId) + }) + } + } + }) + } + + shouldComponentUpdate (nextProps, nextState) { + return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState)) + } + + /** + * @description 缁勪欢閿�姣侊紝娓呴櫎state鏇存柊 + */ + componentWillUnmount () { + this.setState = () => { + return + } } handleCollapse = () => { - // 灞曞紑銆佹敹璧峰乏渚ц彍鍗曟爮 - this.props.toggleCollapse(!this.props.collapse) - localStorage.setItem('collapse', !this.props.collapse) + const { collapse } = this.state + + sessionStorage.setItem('collapse', !collapse) + + this.setState({collapse: !collapse}) + + MKEmitter.emit('toggleCollapse', !collapse) } changePassword = () => { @@ -54,7 +104,6 @@ MKEmitter.emit('resetpassword', () => { setTimeout(() => { sessionStorage.clear() - this.props.logout() this.props.history.replace('/login') }, 2000) }) @@ -70,7 +119,6 @@ cancelText: '鍙栨秷', onOk() { sessionStorage.clear() - _this.props.logout() _this.props.history.replace('/login') }, onCancel() {} @@ -84,7 +132,8 @@ } else if (value.OpenType === 'newtab') { MKEmitter.emit('modifyTabs', value) } else if (value.OpenType === 'menu') { - this.props.modifyMainMenu(value) + window.GLOB.mainMenu = value + MKEmitter.emit('mainMenuChange') } } @@ -130,9 +179,10 @@ sessionStorage.removeItem('ThirdMenu') } - this.props.modifyMainMenu(mainMenu) - + window.GLOB.mainMenu = mainMenu window.GLOB.mkThdMenus = [...thdMenuList, {MenuID: 'home_page_id', EasyCode: '', MenuName: 'home', type: 'CustomPage'}] + + MKEmitter.emit('mainMenuChange') if (_menu) { this.openTab(_menu, 0) @@ -313,8 +363,7 @@ loginVisible: true }) } else { - this.props.modifyMainMenu(null) - + window.GLOB.mainMenu = null this.props.history.replace('/design') } } @@ -360,7 +409,8 @@ localStorage.setItem(_url, window.btoa(window.encodeURIComponent(JSON.stringify({time: new Date().getTime(), username: param.username, password: ''})))) } - this.props.modifyMainMenu(null) + window.GLOB.mainMenu = null + this.props.history.replace('/design') } else { if (res.message.indexOf('瀵嗙爜閿欒') > -1) { @@ -441,60 +491,6 @@ }, 500) } }) - } - - UNSAFE_componentWillMount () { - // 缁勪欢鍔犺浇鏃讹紝鑾峰彇鑿滃崟鏁版嵁 - this.getRolesMenu() - - let fullName = sessionStorage.getItem('Full_Name') || '' - let userName = sessionStorage.getItem('User_Name') || '' - - if (fullName.toLowerCase() === userName.toLowerCase()) { - userName = '' - } - - this.setState({fullName, userName}) - } - - componentDidMount () { - // 鑾峰彇绯荤粺鐨勭増鏈俊鎭紝寤舵椂鏌ヨ - setTimeout(() => { - Api.getAppVersion() - }, 1000) - - // sessionStorage 璺ㄩ〉闈㈠叡浜� - window.addEventListener('storage', (e) => { - if (e.key === 'getSessionStorage' && e.newValue === window.GLOB.appkey) { - localStorage.setItem('sessionStorage', JSON.stringify(sessionStorage)) - } else if (e.key === 'getSysPermission' && e.newValue === window.GLOB.appkey) { - localStorage.setItem('sysPermissions', JSON.stringify({mkThdMenus: window.GLOB.mkThdMenus, mkActions: window.GLOB.mkActions})) - } else if (e.key === 'menuUpdate') { - let vals = e.newValue.split(',') - let menuId = vals[1] - let position = vals[2] || '' - if (position === 'menu') { - MKEmitter.emit('reloadMenuView', menuId) - } else if (menuId) { - Api.getAppVersion(menuId).then(() => { - MKEmitter.emit('reloadMenuView', menuId) - }) - } - } - }) - } - - shouldComponentUpdate (nextProps, nextState) { - return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState)) - } - - /** - * @description 缁勪欢閿�姣侊紝娓呴櫎state鏇存柊 - */ - componentWillUnmount () { - this.setState = () => { - return - } } gotoDoc = () => { @@ -579,8 +575,7 @@ } render () { - const { mainMenu, collapse } = this.props - const { thdMenuList, searchkey, debug, menulist } = this.state + const { thdMenuList, searchkey, debug, menulist, collapse } = this.state const navBar = window.GLOB.navBar const menu = ( @@ -622,7 +617,7 @@ <ul className="header-menu">{ menulist.map(item => { return ( - <li key={item.MenuID} onClick={() => {this.changeMenu(item)}} className={mainMenu && mainMenu.MenuID === item.MenuID ? 'active' : ''}> + <li key={item.MenuID} onClick={() => {this.changeMenu(item)}} className={window.GLOB.mainMenu && window.GLOB.mainMenu.MenuID === item.MenuID ? 'active' : ''}> <span>{item.MenuName}</span> </li> ) @@ -777,19 +772,4 @@ } } -const mapStateToProps = (state) => { - return { - collapse: state.collapse, - mainMenu: state.mainMenu - } -} - -const mapDispatchToProps = (dispatch) => { - return { - toggleCollapse: (collapse) => dispatch(toggleCollapse(collapse)), - modifyMainMenu: (mainMenu) => dispatch(modifyMainMenu(mainMenu)), - logout: () => dispatch(logout()) - } -} - -export default withRouter(connect(mapStateToProps, mapDispatchToProps)(Header)) \ No newline at end of file +export default withRouter(Header) \ No newline at end of file -- Gitblit v1.8.0