Browse Source

有效期设置

zhuth 7 years ago
parent
commit
d6bcb55825
3 changed files with 15 additions and 4 deletions
  1. 1 0
      src/components/common/login.jsx
  2. 3 3
      src/routes/mainLayout.js
  3. 11 1
      src/routes/router.js

+ 1 - 0
src/components/common/login.jsx

@@ -8,6 +8,7 @@ const { Tab, UserName, Password, Mobile, Captcha, Submit } = Login;
 
 
 function authenticate(cb) {
 function authenticate(cb) {
     window.localStorage.setItem("isAuthenticated", "true");
     window.localStorage.setItem("isAuthenticated", "true");
+    window.localStorage.setItem("expireTime", (new Date().getTime()+ 24 * 60 * 60 * 1000 ) + '');
     setTimeout(cb, 100); // fake async
     setTimeout(cb, 100); // fake async
 }
 }
 
 

+ 3 - 3
src/routes/mainLayout.js

@@ -21,9 +21,9 @@ const MainLayout = (history) => {
             </Header>
             </Header>
             <Content className='main-content'>
             <Content className='main-content'>
                 <Switch>
                 <Switch>
-                    <Route path='/demo' component={Demo}/>
-                    <Route path='/home' component={Welcome}/>
-                    <Route path='/datasource/:type/:code/:tab' component={DataSourceDetail}/>
+                    <Route sensitive path='/demo' component={Demo}/>
+                    <Route sensitive path='/home' component={Welcome}/>
+                    <Route sensitive path='/datasource/:type/:code/:tab' component={DataSourceDetail}/>
                     <Route sensitive path='/datasource' component={DataSource}/>
                     <Route sensitive path='/datasource' component={DataSource}/>
                     <Route sensitive path='/dashboard' component={Dashboard} />
                     <Route sensitive path='/dashboard' component={Dashboard} />
                     <Route sensitive path='/chart' component={Chart} />
                     <Route sensitive path='/chart' component={Chart} />

+ 11 - 1
src/routes/router.js

@@ -10,7 +10,17 @@ import DashboardDesigner from '../components/dashboardDesigner/layout'
 import zhCN from 'antd/lib/locale-provider/zh_CN'
 import zhCN from 'antd/lib/locale-provider/zh_CN'
 import Demo from '../demo';
 import Demo from '../demo';
 
 
-localStorage.setItem("isAuthenticated", "false");
+if (!window.localStorage.getItem("isAuthenticated")) {
+    window.localStorage.setItem("isAuthenticated", "false");
+}else {
+    /**
+     * 是否过期
+     * 1.是-----设置isAuthenticated为false
+     */
+    if(new Date(+window.localStorage.getItem("expireTime")) < new Date()) {
+        window.localStorage.setItem("isAuthenticated", "false");
+    }
+}
 
 
 function RouterConfig({ history }) {
 function RouterConfig({ history }) {
   return (
   return (