登录页面

  1. <div className="col-md-4 col-md-offset-4">
  2.                <div className="panel panel-default login-panel">
  3.                    <div className="panel-heading">欢迎登录 - MMALL管理系统</div>
  4.                    <div className="panel-body">
  5.                        <div>
  6.                            <div className="form-group">
  7.                                <input type="text"
  8.                                    name="username"
  9.                                    className="form-control"
  10.                                    placeholder="请输入用户名"
  11.                                    onKeyUp={e => this.onInputKeyUp(e)}
  12.                                    onChange={e => this.onInputChange(e)}/>
  13.                            </div>
  14.                            <div className="form-group">
  15.                                <input type="password"
  16.                                    name="password"
  17.                                    className="form-control"
  18.                                    placeholder="请输入密码"
  19.                                    onKeyUp={e => this.onInputKeyUp(e)}
  20.                                    onChange={e => this.onInputChange(e)}/>
  21.                            </div>
  22.                            <button className="btn btn-lg btn-primary btn-block"
  23.                                onClick={e => {this.onSubmit(e)}}>登录</button>
  24.                        </div>
  25.                    </div>
  26.                </div>
  27.            </div>

当用户名和密码发生改变的时候,设置onChange事件,重新设置state里边username和password的值

  1. this.state = {
  2.            username: '',
  3.            password: '',
  4.            redirect: _mm.getUrlParam('redirect') || '/'
  5.        }
  6. // 当用户名发生改变
  7.   onInputChange(e){
  8.       let inputValue = e.target.value,
  9.           inputName = e.target.name;
  10.       this.setState({
  11.           [inputName] : inputValue
  12.       });
  13.   }

给输入框设置onKeyUp事件,监听输入框按下enter键的时候,提交登录数据

  1. onInputKeyUp(e){
  2.        if(e.keyCode === 13){
  3.            this.onSubmit();
  4.        }
  5.    }

提交表单数据,提交之前先验证表单数据,

  1. // 检查登录接口的数据是不是合法
  2.     checkLoginInfo(loginInfo){
  3.         let username = $.trim(loginInfo.username),
  4.             password = $.trim(loginInfo.password);
  5.         // 判断用户名为空
  6.         if(typeof username !== 'string' || username.length ===0){
  7.             return {
  8.                 status: false,
  9.                 msg: '用户名不能为空!'
  10.             }
  11.         }
  12.         // 判断密码为空
  13.         if(typeof password !== 'string' || password.length ===0){
  14.             return {
  15.                 status: false,
  16.                 msg: '密码不能为空!'
  17.             }
  18.         }
  19.         return {
  20.             status : true,
  21.             msg : '验证通过'
  22.         }
  23.     }
  1. onSubmit(){
  2.        let loginInfo = {
  3.                username : this.state.username,
  4.                password : this.state.password
  5.            },
  6.            //验证表单
  7.            checkResult = _user.checkLoginInfo(loginInfo);
  8.        // 验证通过
  9.        if(checkResult.status){
  10.            _user.login(loginInfo).then((res) => {
  11.                _mm.setStorage('userInfo', res);
  12.                //console.log(this.state.redirect);
  13.                this.props.history.push(this.state.redirect);
  14.            }, (errMsg) => {
  15.                _mm.errorTips(errMsg);
  16.            });
  17.        }
  18.        // 验证不通过
  19.        else{
  20.            _mm.errorTips(checkResult.msg);
  21.        }
  22.  
  23.    }

登录之后跳转地址this.sate.redirect= _mm.getUrlParam('redirect') || '/' , this.props.history.push(this.state.redirect);

  1. // 跳转登录
  2.    doLogin(){
  3.        //window.location.pathname url路径部分,端口后边,问号前边
  4.        //例如 redirect="/user/index"
  5.        window.location.href = '/login?redirect=' + window.location.pathname;
  6.       // window.location.href = '/login?redirect=' + encodeURIComponent(window.location.pathname);
  7.    }
  8.    // 获取URL参数
  9.    getUrlParam(name){
  10.        //http://localhost:8086/login?redirect=/product/index
  11.        // param=123&param1=456
  12.  
  13.        let queryString = window.location.search.split('?')[1] || '',
  14.            reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"),
  15.            result = queryString.match(reg);
  16.        console.log(result);
  17.        return result ? decodeURIComponent(result[2]) : null;
  18.    }

React后台管理系统-登录页面的更多相关文章

  1. 我的第一个python web开发框架(14)——后台管理系统登录功能

    接下来正式进入网站的功能开发.要完成后台管理系统登录功能,通过查看登录页面,我们可以了解到,我们需要编写验证码图片获取接口和登录处理接口,然后在登录页面的HTML上编写AJAX. 在进行接口开发之前, ...

  2. 《React后台管理系统实战 :一》:目录结构、引入antd、引入路由、写login页面、使用antd的form登录组件、form前台验证、高阶函数/组件

    实战 上接,笔记:https://blog.csdn.net/u010132177/article/details/104150177 https://gitee.com/pasaulis/react ...

  3. 《React后台管理系统实战 :三》header组件:页面排版、天气请求接口及页面调用、时间格式化及使用定时器、退出函数

    一.布局及排版 1.布局src/pages/admin/header/index.jsx import React,{Component} from 'react' import './header. ...

  4. 《React后台管理系统实战 :二》antd左导航:cmd批量创建子/目录、用antd进行页面布局、分离左导航为单独组件、子路由、动态写左导航、css样式相对陷阱

    一.admin页面布局及路由创建 0)cmd批量创建目录及子目录 //创建各个目录,及charts和子目录bar md home category product role user charts\b ...

  5. 【共享单车】—— React后台管理系统开发手记:主页面架构设计

    前言:以下内容基于React全家桶+AntD实战课程的学习实践过程记录.最终成果github地址:https://github.com/66Web/react-antd-manager,欢迎star. ...

  6. react后台管理系统路由方案及react-router原理解析

        最近做了一个后台管理系统主体框架是基于React进行开发的,因此系统的路由管理,选用了react-router(4.3.1)插件进行路由页面的管理配置. 实现原理剖析 1.hash的方式   ...

  7. AntDesign(React)学习-4 登录页面提交数据简单实现

    github代码:https://github.com/zhaogaojian/jgdemo 全国肺炎,过节期间没地方去在家学习antd. 一.感觉antd pro项目太庞大了,可以学习下结构和代码风 ...

  8. 【共享单车】—— React后台管理系统开发手记:AntD Form基础组件

    前言:以下内容基于React全家桶+AntD实战课程的学习实践过程记录.最终成果github地址:https://github.com/66Web/react-antd-manager,欢迎star. ...

  9. React后台管理系统-用户列表页面

    1.页面的结构 //遍历list, 返回数据       let listBody= this.state.list.map((user,index)=> {           return ...

随机推荐

  1. Task :rn-splash-screen:verifyReleaseResources FAILED

    Execution failed for task ':rn-splash-screen:verifyReleaseResources'. > java.util.concurrent.Exec ...

  2. 入侵检测系统 - ossec

    http://www.cnblogs.com/zlslch/p/8512757.html

  3. thinkphp5.1控制器初始化函数initialize与构造函数__construct区别

    构造函数中子类的构造方法会覆盖父类的构造方法,如果要继承父类的构造方法可以加入parent::__construct(); 例子: //另一种方法,使用构造函数初始化 public function ...

  4. thinkphp5使用QueryList实现采集功能

    QueryList是基于phpQuery的 1.下载`QueryList.php`和`phpQuery.php`这两个文件. 2.在`extend`下新建`QL`目录. 3.将下载好的`QueryLi ...

  5. 什么是obj文件?

    百度百科: 程序编译时生成的中间代码文件.目标文件,一般是程序编译后的二进制文件,再通过链接器(LINK.EXE)和资源文件链接就成可执行文件了.OBJ只给出了程序的相对地址,而可执行文件是绝对地址. ...

  6. jdb应用

    场景: 外网可以登录远程主机,但是因为安全限制,不能在外网直接访问docker应用的端口,因此不能远程调试.远程主机shell内部可以连接docker应用,也没有图形界面,没有log,考虑使用原始的j ...

  7. 安装pywin32出现--Python version 3.x required, which was not found in the registry

    这两天安装pywin32时出现了这个问题 双击.exe文件进入安装界面,然后点击下一步,它会自动定位你的python安装在什么地方,但是我的安装过程中未自动定位到python安装位置,并显示显示: 安 ...

  8. JD孔_20160920

    1. 2. 3.

  9. springcloud中常用的注解@

    @SpringBootApplication是springboot启动类,包括三个注解,他们的作用分别是: @Configuration:表示将该类作用springboot配置文件类 @EnableA ...

  10. spring运用的设计模式

    1.代理模式(典型的aop) 2.工厂模式(beanFactory) 3.观察者模式(ApplicationContextEvent && ApplicationContextList ...