Browse Source

登录组件登录跳转逻辑调整

zhuth 7 years ago
parent
commit
5394cbd3cc
2 changed files with 25 additions and 27 deletions
  1. 6 4
      src/components/common/login.jsx
  2. 19 23
      src/routes/router.js

+ 6 - 4
src/components/common/login.jsx

@@ -16,7 +16,7 @@ function signout(cb) {
     setTimeout(cb, 100); // fake async
 }
 
-class LoginDemo extends React.Component {
+class LoginComponent extends React.Component {
     state = {
         notice: '',
         autoLogin: true,
@@ -28,12 +28,14 @@ class LoginDemo extends React.Component {
         this.setState({
             notice: '',
         }, () => {
-            if (!err && (values.username !== 'admin' || values.password !== '888888')) {
+            if (err && (values.username !== 'admin' || values.password !== '888888')) {
                 setTimeout(() => {
                     this.setState({
                         notice: '账号名或密码错误!',
                     });
                 }, 500);
+            }else {
+                this.login();
             }
         });
     }
@@ -79,7 +81,7 @@ class LoginDemo extends React.Component {
                             <Submit>登录</Submit>
                             <div>
                                 <Link to="/register">
-                                    <a style={{ float: 'right' }} href="">注册</a>
+                                    <span style={{ float: 'right' }} href="">注册</span>
                                 </Link>
                             </div>
                         </Login>
@@ -90,4 +92,4 @@ class LoginDemo extends React.Component {
     }
 }
 
-export default LoginDemo;
+export default LoginComponent;

+ 19 - 23
src/routes/router.js

@@ -9,30 +9,8 @@ import DashboardDesigner from '../components/dashboardDesigner/layout'
 // 由于 antd 组件的默认文案是英文,所以需要修改为中文
 import zhCN from 'antd/lib/locale-provider/zh_CN'
 import Demo from '../demo';
-import Login from '../components/common/login';
 
-window.localStorage.setItem("isAuthenticated", "false");
-
-
-
-
-const PrivateRoute = ({ component: Component, ...rest }) => (
-    <Route
-        {...rest}
-        render={props =>
-            (window.localStorage.getItem("isAuthenticated") === "true"? true: false)  ? (
-                <Component {...props} />
-            ) : (
-                    <Redirect
-                        to={{
-                            pathname: "/login",
-                            state: { from: props.location }
-                        }}
-                    />
-                )
-        }
-    />
-);
+localStorage.setItem("isAuthenticated", "false");
 
 function RouterConfig({ history }) {
   return (
@@ -51,3 +29,21 @@ function RouterConfig({ history }) {
 }
 
 export default RouterConfig;
+
+const PrivateRoute = ({ component: Component, ...rest }) => (
+  <Route
+      {...rest}
+      render={props =>
+          (window.localStorage.getItem("isAuthenticated") === "true"? true: false)  ? (
+              <Component {...props} />
+          ) : (
+                  <Redirect
+                      to={{
+                          pathname: "/login",
+                          state: { from: props.location }
+                      }}
+                  />
+              )
+      }
+  />
+);