React后台管理系统-登录页面

登录页面

  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.    }

登录之后跳转地址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.        let queryString = window.location.search.split('?')[1] || '',
  13.            reg = new RegExp("(^|&)" name "=([^&]*)(&|$)"),
  14.            result = queryString.match(reg);
  15.        console.log(result);
  16.        return result ? decodeURIComponent(result[2]) : null;
  17.    }

 


更多专业前端知识,请上 【猿2048】www.mk2048.com

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/363095.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

识别JVM –比预期的要复杂

在Plumbr&#xff0c;我们花了最后一个月的时间来为将来的重大改进奠定基础。 此类构件之一是为JVM添加唯一标识符&#xff0c;以便将来自同一JVM的所有会话链接在一起。 虽然一开始看起来似乎很琐碎的任务&#xff0c;但是当查看JVM捆绑的jps命令的输出时&#xff0c;围绕该问…

随记3

查看本机ip&#xff1a;ifconfig | grep "inet " | grep -v 127.0.0.1去两端空格&#xff1a;rowrow.strip(\t)替换\n \r \t 为空&#xff1a;row row.replace(\r,).replace(\n,).replace(\t,’)字符串长度&#xff1a;aa ‘afebb’ print(len(aa))列表 List列表…

求一架构 : 保留历史数据

最近做一个学校管理系统&#xff0c;当中遇到一个比较麻烦的问题“保留历史数据”&#xff0c;很疑惑&#xff0c;说出来大家讨论下&#xff0c;相信很多人也遇到同样的问题。校方提出需求如下&#xff1a;1.要保留学期留历史数据比如&#xff1a;●  一年级一班2008-2009上学…

React后台管理系统-品类的增加、修改和查看

1.页面 2.品类列表展示 let listBody this.state.list.map((category, index) > { return ( <tr key{index}> <td>{category.id}</td> <td>{category.name}</td> <td> <a className"opear" onClick{(e) > this.onUpda…

hdu5111 树链剖分,主席树

hdu5111 链接 hdu 思路 先考虑序列上如何解决。 1 3 2 5 4 1 2 4 5 3 这个序列变成 1 2 3 4 5 1 3 5 5 2 是对答案没有影响的(显然)。 然后查询操作\(l,r,L,R\)就是&#xff0c; 一段连续的区间\([L,R]\)内包含几个值在\([l,r]\)的数字个数. 主席树就可以做了。\(query(rt[L-1]…

使用log4j监视和筛选应用程序日志到邮件

在今天的帖子中&#xff0c;我将向您展示如何将日志语句过滤为警告电子邮件。 这是出于监视我正在处理的一个应用程序的一些关键点的需要。 您可以使用一些工具来执行应用程序监视。 我不会详细介绍这些工具&#xff0c;但有时让应用程序发送警告电子邮件会更容易。 我主要将l…

FF

ietab :IE 内核tab mix plus &#xff1a;管理TABfirebug live http headersminimizeToTray安装插件方法&#xff1a;file-open file - select "*.xpi"https://addons.mozilla.org/en-US/firefox/https://addons.mozilla.org/en-US/firefox/addon/1419http://l…

Vue node.js商城-购物车模块

一、渲染购物车列表页面 新建src/views/Cart.vue获取cartList购物车列表数据就可以在页面中渲染出该用户的购物车列表数据 data(){ return { cartList:[] // 购物车商品列表 } }, mounted:function(){ this.init(); }, methods:{ init(){ // 初始化商品数据 axios.get(/users/…

RxJava + Java8 + Java EE 7 + Arquillian =幸福

微服务是一种体系结构样式&#xff0c;其中每个服务都实现为一个独立的系统。 他们可以使用自己的持久性系统&#xff08;尽管不是强制性的&#xff09;&#xff0c;部署&#xff0c;语言等。 由于系统由一个以上的服务组成&#xff0c;因此每个服务将与其他服务通信&#xff…

C# -- RSA加密与解密

1. RSA加密与解密 -- 使用公钥加密、私钥解密 public class RSATool{public string Encrypt(string strText, string strPublicKey){RSACryptoServiceProvider rsa new RSACryptoServiceProvider();rsa.FromXmlString(strPublicKey);byte[] byteText Encoding.UTF8.GetByt…

React后台管理系统-file-uploader组件

1.React文件上传组件github地址: https://github.com/SoAanyip/React-FileUpload 2.Util里边新建file-uploader文件夹&#xff0c;里边新建index.jsx import React from react; import FileUpload from ./react-fileupload.jsx; class FileUploader extends React.Component{…

经典代码收藏

1. οncοntextmenu"window.event.returnvaluefalse" 将彻底屏蔽鼠标右键 <table border οncοntextmenureturn(false)><td>no</table> 可用于Table 2. <body onselectstart"return false"> 取…

js 实现文件导出、文件下载

1、通过创建a标签&#xff0c;实现下载功能 function downLoad(content,fileName){var aEle document.createElement("a");// 创建a标签// blob new Blob([content]); aEle.download fileName;// 设置下载文件的文件名//aEle.href URL.createObjectUrl(blob);aEl…

VMware Station NAT上网模式配置

转载于:https://www.cnblogs.com/MimiSnowing/p/10718235.html

JavaFX技巧10:自定义复合控件

用JavaFX编写自定义控件是一个简单直接的过程。 需要一个控件类来控制控件的状态&#xff08;因此命名&#xff09;。 外观需要控件的外观。 而且通常不是用于自定义外观CSS文件。 控件的常用方法是将其使用的节点隐藏在其外观类中。 例如&#xff0c; TextField控件使用javaf…

dell服务器安装系统注意之二.(2003/xp 的sn)

刚找回笔记,以前写的东西记了下来,是关于dell服务器上安装系统的.列表如下1、开机看画面提示&#xff0c;提示有“ctrm”--->当然入到去就要看提示“clean”磁盘的资料啦。&#xff08;除非你不清除&#xff09;---》根据提示进入-》easy setup----》提示f10保存---》ok了。…

React后台管理系统-首页Home组件

1.Home组件要显示用户总数、商品总数和订单总数&#xff0c;数据请求后端的 /manage/statistic/base_count.do接口&#xff0c;返回的是 this.state { userCount : -, productCount : -, orderCount : - } //页面挂载之后请求数据componentDidMount(){ this.loadCount(); } lo…

js 实现简单的轮询

在实际开发中&#xff0c;经常会有轮询的效果。 1、js实现轮询效果》使用setTimeout&#xff0c;clearTimeout方法 function setTimer () {let timeraxios.post(url, params).then(function (res) {if(res){console.log(res);timer setTimeout(() > {this.setTimer()}, 500…

MyBatis第一天课上笔记

[今日课程大纲]高级软件介绍(部分)MySql 数据库建库建表语句强调命名规范强调基于MVC 开发模式完成单表查询和新增Eclipse 中项目默认发布路径高级课程大纲介绍框架是什么MyBatis 简介MyBatis 搭建流程数据库连接池和JNDI 复习搭建流程详解( 全局配置文件,resultType 原理及Aut…

JAX-RS 2.0的新功能– @BeanParam批注

至少可以说JAX-RS很棒&#xff0c;也是我的最爱之一&#xff01; 为什么&#xff1f; 功能丰富 直观&#xff08;因此学习曲线不那么陡峭&#xff09; 易于使用和开发 具有出色的RI – Jersey &#xff0c; RestEasy等 有足够的JAX-RS粉丝可以添加此内容&#xff01; JAX…