当前位置:   article > 正文

LayUI入门,以及介绍

layui

                                            一.LayUI基本情况

1.LayUI介绍

Layui(流行于 layui.com)是一款轻量级的前端UI框架,专注于提供简洁、易用、灵活的界面组件和交互体验。它基于HTML5和CSS3技术,采用模块化开发的思想,提供了丰富的UI组件、常用的工具函数和灵活的扩展机制。

Layui的设计理念是“经典与创新的全面结合”,它提供了一套简洁、直观、易于上手的API,使得开发者能够快速搭建出美观、功能完善的前端界面。Layui的代码精简,文件体积小,加载速度快,非常适合开发响应式的Web应用程序。

Layui提供了丰富的组件,包括按钮、表单、表格、导航、选项卡、弹窗、富文本编辑器等等,这些组件具有一致的风格和交互体验,可以有效提高开发效率。同时,Layui还提供了丰富的工具函数和插件,如日期选择器、分页、上传组件等,方便开发者进行常见的操作和功能扩展。

除了提供基础的UI组件和工具函数,Layui还支持自定义主题和模块扩展。开发者可以根据自己的需求,自定义界面样式和交互效果。同时,Layui还支持模块化开发,开发者可以将自己的组件封装成模块,方便复用和扩展。

总之,Layui是一个功能强大、简单易用的前端UI框架,适用于各种类型的Web应用程序开发。它具有良好的兼容性和性能优势,可以帮助开发者快速构建出优秀的前端界面。

2. LayUI发展历史

Layui框架的诞生可以追溯到2016年。在这一年,一位名叫贤心的前端开发者提出了一种构想:希望能够通过一个简单、易用、高性能的前端框架来简化开发过程并提升开发效率。于是,他开始了Layui框架的开发。

贤心是一个热衷于前端开发的工程师,他在开发过程中积累了大量的经验和技巧。他希望通过将自己的经验整理归纳成一个前端框架,来帮助其他开发者快速开发出优秀的前端界面。

Layui在设计之初就坚持了一些原则,比如简洁易用、高效精简、模块化开发等。贤心精心设计了Layui的API和组件结构,使其能够提供一致的界面风格和交互效果,同时又具备灵活的扩展性。

Layui在发布后迅速获得了广泛的关注和认可。开发者们纷纷尝试使用Layui来开发自己的项目,并提供了大量的反馈和建议。贤心积极听取用户的意见,不断改进和完善框架,使其更加符合开发者的需求。

随着时间的推移,Layui逐渐成为了国内最受欢迎的前端框架之一。越来越多的开发者选择Layui来构建自己的项目,而Layui社区也迅速壮大起来。在社区的帮助下,Layui不断更新版本,提供越来越丰富和强大的功能。

至今,Layui已经发布了多个版本,每个版本都带来了新的特性和改进。Layui的成功离不开贤心的辛勤付出和广大开发者的支持。它不仅简化了前端开发的流程,还促进了前端开发者之间的交流和分享,成为了国内前端界的重要组成部分。(遗憾的是由于是开源的,在2021.10.13就停止更新了没有资金维护)


                       二.将Layui加入web项目中

1.搜索网址

    官方网站:https://www.layui.com/(已下线)
   参考地址:http://layui.org.cn/demo/index.html(已下线,非官网)

 2.下载文件,解压

 点击下载即可,不需要登陆账号

解压的文件就是这几个文件,我们需要的layui文件在layui包里

3.加入web项目

3.1导入layui包

 建立一个静态资源包,将我们的资源导入

3.2.在jsp中导入资源

  1. link rel="stylesheet" href="${pageContext.request.contextPath }/static/js/layui/css/layui.css">
  2. <!-- 引入 layui.js -->
  3. <script src="${pageContext.request.contextPath}/static/js/layui/layui.js"></script>

在其中pageContext.request.contextPath作用是适用于任何的js,css,img等等导入

 3.3效果图

  1. <%@ page language="java" contentType="text/html; charset=UTF-8"
  2. pageEncoding="UTF-8"%>
  3. <!DOCTYPE >
  4. <html>
  5. <head>
  6. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  7. <title>Insert title here</title>
  8. <%@ include file="common/header.jsp" %>
  9. </head>
  10. <body>
  11. <!-- 你的 HTML 代码 -->
  12. <script>
  13. layui.use(['layer', 'form'], function(){
  14. var layer = layui.layer
  15. ,form = layui.form;
  16. layer.msg('Hello World');
  17. });
  18. </script>
  19. </body>
  20. </html>

                                    三.利用LayUi实现登录注册

1.实现登录:

1.1首先编写jsp

  1. <%@ page language="java" contentType="text/html; charset=UTF-8"
  2. pageEncoding="UTF-8"%>
  3. <%@ include file="common/header.jsp"%>
  4. <html>
  5. <head>
  6. <meta name="viewport"
  7. content="width=device-width,initial-scale=1.33,minimum-scale=1.0,maximum-scale=1.0">
  8. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  9. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  10. <meta name="renderer" content="webkit">
  11. <title>会员登录-演示网站</title>
  12. <meta http-equiv="Content-Language" content="zh-CN">
  13. <link rel="stylesheet" rev="stylesheet"
  14. href="${pageContext.request.contextPath}/static/css/iconfont.css"
  15. type="text/css" media="all">
  16. <link rel="stylesheet" rev="stylesheet"
  17. href="${pageContext.request.contextPath}/static/css/login.css"
  18. type="text/css" media="all">
  19. <style>
  20. body {
  21. color: #;
  22. }
  23. a {
  24. color: #;
  25. }
  26. a:hover {
  27. color: #;
  28. }
  29. .bg-black {
  30. background-color: #;
  31. }
  32. .tx-login-bg {
  33. background: url(${pageContext.request.contextPath}/static/images/bg.jpg)
  34. no-repeat 0 0;
  35. }
  36. </style>
  37. </head>
  38. <body class="tx-login-bg">
  39. <div class="tx-login-box">
  40. <div class="login-avatar bg-black">
  41. <i class="iconfont icon-wode"></i>
  42. </div>
  43. <ul class="tx-form-li row">
  44. <li class="col-24 col-m-24"><p>
  45. <input type="text" id="username" placeholder="登录账号"
  46. class="tx-input">
  47. </p></li>
  48. <li class="col-24 col-m-24"><p>
  49. <input type="password" id="password" placeholder="登录密码"
  50. class="tx-input">
  51. </p></li>
  52. <li class="col-24 col-m-24"><p class="tx-input-full">
  53. <button id="login" class="tx-btn tx-btn-big bg-black">登录</button>
  54. </p></li>
  55. <li class="col-12 col-m-12"><p>
  56. <a href="#" class="f-12 f-gray">新用户注册</a>
  57. </p></li>
  58. <li class="col-12 col-m-12"><p class="ta-r">
  59. <a href="#" class="f-12 f-gray">忘记密码</a>
  60. </p></li>
  61. </ul>
  62. </div>
  63. <script>
  64. layui.use([ 'layer', 'jqurey' ], function() {
  65. var layer = layui.layer, $ = layui.jqurey;
  66. $("#login").click(function() {
  67. $.ajax({
  68. url:'${pageContext.request.contextPath}/user.action?methodName=login',
  69. dataType:'json',
  70. data:{
  71. loginName:$("#username").val(),
  72. password:$("#password").val()
  73. },
  74. method:'post',
  75. sucess:function (data){
  76. if (data) {
  77. layer.alert('恭喜'+data.name+'登录成功',{icon:6});
  78. }else {
  79. layer.alert('密码错误',{icon:6});
  80. }
  81. }
  82. });
  83. })
  84. });
  85. </script>
  86. </body>
  87. </html>

 1.2编写实体,dao方法、

1.2.1实体
  1. package com.lz.entity;
  2. public class User {
  3. private long id;
  4. private String name;
  5. private String loginName;
  6. private String pwd;
  7. private long rid;
  8. /* (non-Javadoc)
  9. * @see java.lang.Object#toString()
  10. */
  11. @Override
  12. public String toString() {
  13. return "User [id=" + id + ", name=" + name + ", loginName=" + loginName + ", pwd=" + pwd + ", rid=" + rid + "]";
  14. }
  15. /**
  16. * @return the id
  17. */
  18. public long getId() {
  19. return id;
  20. }
  21. /**
  22. * @param id the id to set
  23. */
  24. public void setId(long id) {
  25. this.id = id;
  26. }
  27. /**
  28. * @return the name
  29. */
  30. public String getName() {
  31. return name;
  32. }
  33. /**
  34. * @param name the name to set
  35. */
  36. public void setName(String name) {
  37. this.name = name;
  38. }
  39. /**
  40. * @return the loginName
  41. */
  42. public String getLoginName() {
  43. return loginName;
  44. }
  45. /**
  46. * @param loginName the loginName to set
  47. */
  48. public void setLoginName(String loginName) {
  49. this.loginName = loginName;
  50. }
  51. /**
  52. * @return the pwd
  53. */
  54. public String getPwd() {
  55. return pwd;
  56. }
  57. /**
  58. * @param pwd the pwd to set
  59. */
  60. public void setPwd(String pwd) {
  61. this.pwd = pwd;
  62. }
  63. /**
  64. * @return the rid
  65. */
  66. public long getRid() {
  67. return rid;
  68. }
  69. /**
  70. * @param rid the rid to set
  71. */
  72. public void setRid(long rid) {
  73. this.rid = rid;
  74. }
  75. public User() {
  76. super();
  77. }
  78. public User(long id, String name, String loginName, String pwd, long rid) {
  79. super();
  80. this.id = id;
  81. this.name = name;
  82. this.loginName = loginName;
  83. this.pwd = pwd;
  84. this.rid = rid;
  85. }
  86. }
1.2.2登录dao方法
  1. /**
  2. * 登录
  3. * @param user
  4. * @return
  5. * @throws Exception
  6. */
  7. public User login(User user ) throws Exception {
  8. String sql="select *from t_oa_user where loginName="+user.getLoginName()+"' and pwd='"+user.getPwd()+"' ";
  9. List<User> list = super.executeQuery(sql, User.class,null);
  10. if (list!=null&&list.size()==1) {
  11. return list.get(0);
  12. }
  13. return null;
  14. }

1.3实现登录,增加action

  1. package com.lz.web;
  2. import javax.servlet.http.HttpServletRequest;
  3. import javax.servlet.http.HttpServletResponse;
  4. import com.lz.dao.UserDao;
  5. import com.lz.entity.User;
  6. import com.zking.framework.ActionSupport;
  7. import com.zking.framework.ModelDriver;
  8. import com.zking.util.ResponseUtil;
  9. public class UserAction extends ActionSupport implements ModelDriver<User> {
  10. private User user = new User();
  11. private UserDao userdao = new UserDao();
  12. public void login(HttpServletRequest req, HttpServletResponse resp) {
  13. try {
  14. User u = userdao.login(user);
  15. ResponseUtil.writeJson(resp, u);
  16. } catch (Exception e) {
  17. // TODO Auto-generated catch block
  18. e.printStackTrace();
  19. }
  20. }
  21. // 增加 重定向 book.action
  22. public String add(HttpServletRequest req, HttpServletResponse resp) {
  23. try {
  24. int add = userdao.add(user);
  25. } catch (Exception e) {
  26. // TODO Auto-generated catch block
  27. e.printStackTrace();
  28. }
  29. return "toList";
  30. }
  31. @Override
  32. public User getModel() {
  33. // TODO Auto-generated method stub
  34. return user;
  35. }
  36. }

 1.4配置xml

  1. <action path="/user" type="UserAction">
  2. <forward name="toList" path="/user.action?methodName=list"
  3. redirect="true" />
  4. </action

2.注册

2.1编写jsp

  1. <%@ page language="java" contentType="text/html; charset=UTF-8"
  2. pageEncoding="UTF-8"%>
  3. <%@ include file="common/header.jsp"%>
  4. <html>
  5. <head>
  6. <meta name="viewport"
  7. content="width=device-width,initial-scale=1.33,minimum-scale=1.0,maximum-scale=1.0">
  8. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  9. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  10. <meta name="renderer" content="webkit">
  11. <title>会员注册-演示网站</title>
  12. <meta http-equiv="Content-Language" content="zh-CN">
  13. <link rel="stylesheet" rev="stylesheet"
  14. href="${pageContext.request.contextPath}/static/css/iconfont.css"
  15. type="text/css" media="all">
  16. <link rel="stylesheet" rev="stylesheet"
  17. href="${pageContext.request.contextPath}/static/css/login.css"
  18. type="text/css" media="all">
  19. <style>
  20. body {
  21. color: #;
  22. }
  23. a {
  24. color: #;
  25. }
  26. a:hover {
  27. color: #;
  28. }
  29. .bg-black {
  30. background-color: #;
  31. }
  32. .tx-login-bg {
  33. background: url(${pageContext.request.contextPath}/static/images/bg.jpg)
  34. no-repeat 0 0;
  35. }
  36. </style>
  37. </head>
  38. <body class="tx-login-bg">
  39. <div class="tx-login-box">
  40. <div class="login-avatar bg-black">
  41. <i class="iconfont icon-wode"></i>
  42. </div>
  43. <ul class="tx-form-li row">
  44. <li class="col-24 col-m-24"><p>
  45. <input type="password" id="name" placeholder="注册用户"
  46. class="tx-input">
  47. </p></li>
  48. <li class="col-24 col-m-24"><p>
  49. <input type="text" id="username" placeholder="注册账号"
  50. class="tx-input">
  51. </p></li>
  52. <li class="col-24 col-m-24"><p>
  53. <input type="password" id="password" placeholder="注册密码"
  54. class="tx-input">
  55. </p></li>
  56. <li class="col-24 col-m-24"><p>
  57. <input type="password" id="rid" placeholder="注册rid"
  58. class="tx-input">
  59. </p></li>
  60. <li class="col-24 col-m-24"><p class="tx-input-full">
  61. <button id="login" class="tx-btn tx-btn-big bg-black">注册</button>
  62. </p></li>
  63. </ul>
  64. </div>
  65. <script>
  66. layui.use([ 'layer', 'jqurey' ], function() {
  67. var layer = layui.layer, $ = layui.jqurey;
  68. $("#login").click(function() {
  69. $.ajax({
  70. url:'${pageContext.request.contextPath}/user.action?methodName=login',
  71. dataType:'json',
  72. data:{
  73. name:$("#name").val(),
  74. loginName:$("#username").val(),
  75. password:$("#password").val(),
  76. rid:$("#rid").val()
  77. },
  78. method:'post',
  79. sucess:function (data){
  80. if (data) {
  81. layer.alert('恭喜'+data.name+'注册成功',{icon:6});
  82. }else {
  83. layer.alert('密码错误',{icon:6});
  84. }
  85. }
  86. });
  87. })
  88. });
  89. </script>
  90. </body>
  91. </html>

2.2编写dao

  1. public int add(User user) throws Exception {
  2. String sql = "insert into t_oa_user values(?,?,?,?,?)";
  3. return super.executeUpdate(sql, user, new String[] {"id","name","loginName","pwd","rid"});
  4. }

3.

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小蓝xlanll/article/detail/446709
推荐阅读
相关标签
  

闽ICP备14008679号