From 4991bc08e414f371c624151f671236fcfed0bf01 Mon Sep 17 00:00:00 2001 From: Mr Ke <kelq@hugeinfo.com.cn> Date: Wed, 27 May 2020 14:41:24 +0800 Subject: [PATCH] 修改报错问题 --- src/index.js | 41 +++++++++++--------- src/module/login/login.jsx | 11 +++-- src/components/common/HeadView/index.jsx | 9 ++-- src/module/menu/menu.jsx | 2 4 files changed, 35 insertions(+), 28 deletions(-) diff --git a/src/components/common/HeadView/index.jsx b/src/components/common/HeadView/index.jsx index 899d80b..9927dd1 100644 --- a/src/components/common/HeadView/index.jsx +++ b/src/components/common/HeadView/index.jsx @@ -17,21 +17,22 @@ const history = createHashHistory(); const { Option } = Select; -const menu = ( - <Menu> +const menu = (fun) => { + return <Menu> <Menu.Item> <a onClick={() => { // 清空用户相关信息 window.localStorage.setItem('menu', ''); window.localStorage.setItem('token', ''); message.success('退出成功!'); + fun({ role: '' }); window.location.href = window.location.origin + '/#/login'; }}> 退出 </a> </Menu.Item> </Menu> -); +}; export default function HeadView({ props }) { var loginUser = window.localStorage.getItem('loginUser') || '{}'; @@ -81,7 +82,7 @@ </Col> <Col style={{ marginRight: 40 }}> {loginUser.trueName} - <Dropdown overlay={menu}> + <Dropdown overlay={menu(setContext)}> <a className="ant-dropdown-link" onClick={e => e.preventDefault()}> [{loginUser.dept} | {loginUser.post}]<Icon type="caret-down" /> </a> diff --git a/src/index.js b/src/index.js index aa04fd0..642bba7 100644 --- a/src/index.js +++ b/src/index.js @@ -33,7 +33,7 @@ super(props); this.state = { context: { - role: 'oa', + role: '', roleMenuList: [], setContext: this.setContext, }, @@ -46,23 +46,26 @@ ? JSON.parse(window.localStorage.getItem('menusListByRole')) : []; - let role = Object.keys(menusListByRole).reduce((p, n) => { - if ( - menusListByRole[n].menus - .reduce((p, n) => { - if (n.children) { - return p.concat(n.children); - } else { - return p.concat(n); - } - }, []) - .find(({ path }) => path == pathname) - ) { - return p.concat(n); - } else { - return p; - } - }, []); + let role = Object.keys(menusListByRole) + .reduce((p, n) => { + if ( + menusListByRole[n].menus + .reduce((p, n) => { + if (n.children) { + return p.concat(n.children); + } else { + return p.concat(n); + } + }, []) + .find(({ path }) => path == pathname) + ) { + return p.concat(n); + } else { + return p; + } + }, []) + .join(''); + console.log('role', role); this.setState({ context: { @@ -106,9 +109,9 @@ </Switch> <Layout> <Content> + <Route path="/login" component={()=>( <Login setContext={this.setContext}/>)} /> {context.role == 'oa' && <OaRouteDom />} {context.role == 'user' && <UserRouteDom />} - <Route path="/login" component={Login} /> </Content> </Layout> </Layout> diff --git a/src/module/login/login.jsx b/src/module/login/login.jsx index 30856a9..591d4c7 100644 --- a/src/module/login/login.jsx +++ b/src/module/login/login.jsx @@ -12,6 +12,9 @@ import logo from '../../img/logo.png'; import fetch from '../../api/request'; import { oaMenus, userMenus, getMenuListByPermission } from '../../menu'; +import { Context } from '../../index'; +import { createHashHistory } from 'history'; +const history = createHashHistory(); class NormalLoginForm extends React.Component { constructor(props) { @@ -79,9 +82,10 @@ } }));//所有模块菜单 message.success('登录成功'); - setTimeout(() => { - this.props.history.push({ pathname: "/index" }); - }, 1500);//延时跳转 + console.log('this props', this.props); + history.push({ pathname: "/index" }); + + this.props.setContext && this.props.setContext({ role: 'oa' }) } }) } @@ -139,7 +143,6 @@ </div> <div className="login-div-bottom">2011 10215489广州恒巨信息科技有限公司 版权所有 - 粤ICP备10215489号</div> </div> - </div> ); } diff --git a/src/module/menu/menu.jsx b/src/module/menu/menu.jsx index 8f486c1..ccff58d 100644 --- a/src/module/menu/menu.jsx +++ b/src/module/menu/menu.jsx @@ -64,7 +64,7 @@ collapsible={true} > { - menusListByRole && + menusListByRole && menusListByRole[role] && <MenView history={this.props.history} pathname={selected(menusListByRole[role].menus, this.props.location.pathname)} -- Gitblit v1.8.0