From a4f102defd2c7918617717f3307b6a3ef63859ff Mon Sep 17 00:00:00 2001
From: Mr Ke <kelq@hugeinfo.com.cn>
Date: Fri, 29 May 2020 18:03:17 +0800
Subject: [PATCH] 绩效总览 (列表、详情)、绩效指标 (配置)

---
 src/index.js |   28 +++++++++++++++++++++++++---
 1 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/src/index.js b/src/index.js
index 642bba7..167584b 100644
--- a/src/index.js
+++ b/src/index.js
@@ -22,6 +22,7 @@
 // oa路由映射
 import OaRouteDom from './routeDom/oaRouteDom';
 import UserRouteDom from './routeDom/userRouteDom';
+import { oaMenus, userMenus } from './menu';
 
 export const Context = React.createContext();
 
@@ -42,9 +43,12 @@
 
   componentDidMount() {
     let pathname = history.location.pathname;
+    console.log(history, pathname);
     let menusListByRole = window.localStorage.getItem('menusListByRole')
       ? JSON.parse(window.localStorage.getItem('menusListByRole'))
       : [];
+
+    // let menuMap = { oa: { menus: oaMenus }, user: { menus: userMenus } };
 
     let role = Object.keys(menusListByRole)
       .reduce((p, n) => {
@@ -73,6 +77,18 @@
         role,
       },
     });
+
+    if (!role && menusListByRole.length == 0) {
+      history.push('/login');
+    }
+    if (!role && window.localStorage.getItem('role')) {
+      this.setState({
+        context: {
+          ...this.state.context,
+          role: window.localStorage.getItem('role'),
+        },
+      });
+    }
   }
 
   setContext = (data) => {
@@ -83,6 +99,7 @@
         ...data,
       }, //更新context
     });
+    window.localStorage.setItem('role', data.role || '');
   };
 
   render() {
@@ -109,9 +126,14 @@
                 </Switch>
                 <Layout>
                   <Content>
-                    <Route path="/login" component={()=>( <Login setContext={this.setContext}/>)} />
-                    {context.role == 'oa' && <OaRouteDom />}
-                    {context.role == 'user' && <UserRouteDom />}
+                    <Switch>
+                      <Route
+                        path="/login"
+                        component={() => <Login setContext={this.setContext} />}
+                      />
+                      {context.role == 'oa' && <OaRouteDom />}
+                      {context.role == 'user' && <UserRouteDom />}
+                    </Switch>
                   </Content>
                 </Layout>
               </Layout>

--
Gitblit v1.8.0