登录页面

  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. sqllocaldb 的使用记录

    sql脚本是一个文件大约也就几MB,要是有一种文件存储数据就好了,后来了解到了sqllocaldb,但是没有深入研究大概知道有这么一个东西.这次翻出来还是自家小姑姑要做winfrom但是苦于sqlse ...

  2. maven-jar-plugin 使用maven生成可执行的jar包install a test-jar in maven

    <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> ...

  3. Batch the files in the directory

    #!/bin/bash #sourceFolder = /home/bigdatagfts/pl62716/refdata #targetFolder = /home/bigdatagfts/pl62 ...

  4. springboot 参数校验详解

    https://www.jianshu.com/p/89a675b7c900 在日常开发写rest接口时,接口参数校验这一部分是必须的,但是如果全部用代码去做,显得十分麻烦,spring也提供了这部分 ...

  5. py---------socketserver

    同时两个客户端连接, server 不能有input server端根据client端的要求去执行固定的代码 server.py #-*- coding:utf-8 -*- import time i ...

  6. windows下显示隐藏的文件

    文件--文件夹选项---查看---高级设置----隐藏文件和文件夹----显示隐藏的文件.文件夹和驱动器

  7. Linux Shell 中数组的语法及应用

    #!/bin/sh## 数组的声明与初始化方法# 先声明后赋值:declare -a arrayarray=(one two three) # 声明并初始化:array_1=(1 2 3 four) ...

  8. ubuntu 无法应用原保存的显示器配置

    打开ubuntu之后的开启页面出现: 所选模式均不匹配可能的模式: 为 CRTC 63 尝试模式 CRTC 63:尝试 800x600@60Hz 模式输出在 1366x768@60Hz (通过 0) ...

  9. UICollectionView笔记2

    WWDC 2012 Session笔记——219 Advanced Collection Views and Building Custom Layouts 这是博主的WWDC2012笔记系列中的一篇 ...

  10. redhat配置dns服务器bind

    配置Oracle11g的RAC需要使用DNS服务器来解析SCAN IP,本文就是以此为例介绍bind服务器的使用.首先科普一下bind服务器,属于企业级产品了,还是开源的: Bind是Berkeley ...