React后台管理系统-登录页面
登录页面
- <div className="col-md-4 col-md-offset-4">
- <div className="panel panel-default login-panel">
- <div className="panel-heading">欢迎登录 - MMALL管理系统</div>
- <div className="panel-body">
- <div>
- <div className="form-group">
- <input type="text"
- name="username"
- className="form-control"
- placeholder="请输入用户名"
- onKeyUp={e => this.onInputKeyUp(e)}
- onChange={e => this.onInputChange(e)}/>
- </div>
- <div className="form-group">
- <input type="password"
- name="password"
- className="form-control"
- placeholder="请输入密码"
- onKeyUp={e => this.onInputKeyUp(e)}
- onChange={e => this.onInputChange(e)}/>
- </div>
- <button className="btn btn-lg btn-primary btn-block"
- onClick={e => {this.onSubmit(e)}}>登录</button>
- </div>
- </div>
- </div>
- </div>
当用户名和密码发生改变的时候,设置onChange事件,重新设置state里边username和password的值
- this.state = {
- username: '',
- password: '',
- redirect: _mm.getUrlParam('redirect') || '/'
- }
- // 当用户名发生改变
- onInputChange(e){
- let inputValue = e.target.value,
- inputName = e.target.name;
- this.setState({
- [inputName] : inputValue
- });
- }
给输入框设置onKeyUp事件,监听输入框按下enter键的时候,提交登录数据
- onInputKeyUp(e){
- if(e.keyCode === 13){
- this.onSubmit();
- }
- }
提交表单数据,提交之前先验证表单数据,
- // 检查登录接口的数据是不是合法
- checkLoginInfo(loginInfo){
- let username = $.trim(loginInfo.username),
- password = $.trim(loginInfo.password);
- // 判断用户名为空
- if(typeof username !== 'string' || username.length ===0){
- return {
- status: false,
- msg: '用户名不能为空!'
- }
- }
- // 判断密码为空
- if(typeof password !== 'string' || password.length ===0){
- return {
- status: false,
- msg: '密码不能为空!'
- }
- }
- return {
- status : true,
- msg : '验证通过'
- }
- }
- onSubmit(){
- let loginInfo = {
- username : this.state.username,
- password : this.state.password
- },
- //验证表单
- checkResult = _user.checkLoginInfo(loginInfo);
- // 验证通过
- if(checkResult.status){
- _user.login(loginInfo).then((res) => {
- _mm.setStorage('userInfo', res);
- //console.log(this.state.redirect);
- this.props.history.push(this.state.redirect);
- }, (errMsg) => {
- _mm.errorTips(errMsg);
- });
- }
- // 验证不通过
- else{
- _mm.errorTips(checkResult.msg);
- }
- }
登录之后跳转地址this.sate.redirect= _mm.getUrlParam('redirect') || '/' , this.props.history.push(this.state.redirect);
- // 跳转登录
- doLogin(){
- //window.location.pathname url路径部分,端口后边,问号前边
- //例如 redirect="/user/index"
- window.location.href = '/login?redirect=' + window.location.pathname;
- // window.location.href = '/login?redirect=' + encodeURIComponent(window.location.pathname);
- }
- // 获取URL参数
- getUrlParam(name){
- //http://localhost:8086/login?redirect=/product/index
- // param=123¶m1=456
- let queryString = window.location.search.split('?')[1] || '',
- reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"),
- result = queryString.match(reg);
- console.log(result);
- return result ? decodeURIComponent(result[2]) : null;
- }
React后台管理系统-登录页面的更多相关文章
- 我的第一个python web开发框架(14)——后台管理系统登录功能
接下来正式进入网站的功能开发.要完成后台管理系统登录功能,通过查看登录页面,我们可以了解到,我们需要编写验证码图片获取接口和登录处理接口,然后在登录页面的HTML上编写AJAX. 在进行接口开发之前, ...
- 《React后台管理系统实战 :一》:目录结构、引入antd、引入路由、写login页面、使用antd的form登录组件、form前台验证、高阶函数/组件
实战 上接,笔记:https://blog.csdn.net/u010132177/article/details/104150177 https://gitee.com/pasaulis/react ...
- 《React后台管理系统实战 :三》header组件:页面排版、天气请求接口及页面调用、时间格式化及使用定时器、退出函数
一.布局及排版 1.布局src/pages/admin/header/index.jsx import React,{Component} from 'react' import './header. ...
- 《React后台管理系统实战 :二》antd左导航:cmd批量创建子/目录、用antd进行页面布局、分离左导航为单独组件、子路由、动态写左导航、css样式相对陷阱
一.admin页面布局及路由创建 0)cmd批量创建目录及子目录 //创建各个目录,及charts和子目录bar md home category product role user charts\b ...
- 【共享单车】—— React后台管理系统开发手记:主页面架构设计
前言:以下内容基于React全家桶+AntD实战课程的学习实践过程记录.最终成果github地址:https://github.com/66Web/react-antd-manager,欢迎star. ...
- react后台管理系统路由方案及react-router原理解析
最近做了一个后台管理系统主体框架是基于React进行开发的,因此系统的路由管理,选用了react-router(4.3.1)插件进行路由页面的管理配置. 实现原理剖析 1.hash的方式 ...
- AntDesign(React)学习-4 登录页面提交数据简单实现
github代码:https://github.com/zhaogaojian/jgdemo 全国肺炎,过节期间没地方去在家学习antd. 一.感觉antd pro项目太庞大了,可以学习下结构和代码风 ...
- 【共享单车】—— React后台管理系统开发手记:AntD Form基础组件
前言:以下内容基于React全家桶+AntD实战课程的学习实践过程记录.最终成果github地址:https://github.com/66Web/react-antd-manager,欢迎star. ...
- React后台管理系统-用户列表页面
1.页面的结构 //遍历list, 返回数据 let listBody= this.state.list.map((user,index)=> { return ...
随机推荐
- Task :rn-splash-screen:verifyReleaseResources FAILED
Execution failed for task ':rn-splash-screen:verifyReleaseResources'. > java.util.concurrent.Exec ...
- 入侵检测系统 - ossec
http://www.cnblogs.com/zlslch/p/8512757.html
- thinkphp5.1控制器初始化函数initialize与构造函数__construct区别
构造函数中子类的构造方法会覆盖父类的构造方法,如果要继承父类的构造方法可以加入parent::__construct(); 例子: //另一种方法,使用构造函数初始化 public function ...
- thinkphp5使用QueryList实现采集功能
QueryList是基于phpQuery的 1.下载`QueryList.php`和`phpQuery.php`这两个文件. 2.在`extend`下新建`QL`目录. 3.将下载好的`QueryLi ...
- 什么是obj文件?
百度百科: 程序编译时生成的中间代码文件.目标文件,一般是程序编译后的二进制文件,再通过链接器(LINK.EXE)和资源文件链接就成可执行文件了.OBJ只给出了程序的相对地址,而可执行文件是绝对地址. ...
- jdb应用
场景: 外网可以登录远程主机,但是因为安全限制,不能在外网直接访问docker应用的端口,因此不能远程调试.远程主机shell内部可以连接docker应用,也没有图形界面,没有log,考虑使用原始的j ...
- 安装pywin32出现--Python version 3.x required, which was not found in the registry
这两天安装pywin32时出现了这个问题 双击.exe文件进入安装界面,然后点击下一步,它会自动定位你的python安装在什么地方,但是我的安装过程中未自动定位到python安装位置,并显示显示: 安 ...
- JD孔_20160920
1. 2. 3.
- springcloud中常用的注解@
@SpringBootApplication是springboot启动类,包括三个注解,他们的作用分别是: @Configuration:表示将该类作用springboot配置文件类 @EnableA ...
- spring运用的设计模式
1.代理模式(典型的aop) 2.工厂模式(beanFactory) 3.观察者模式(ApplicationContextEvent && ApplicationContextList ...