极乐门资源网 Design By www.ioogu.com
口说无凭,实现效果如下
前端 部分
注册功能
1、wxml文件
<view> <view class="frm"> <view class="ui-row ui-row-border-top ui-row-border-bottom" style="margin-bottom: 20px;height:40px;"> <view class="ui-col ui-col-border-right ui-col-align-center align-center valign-middle" style="flex:0 0 60px;"> <view class="ui-col-content align-center valign-middle"> </view> </view> <view class="ui-col" style=""> <view class="ui-col-content"> <view class="ui-row" style="height:40px;"> <view class="ui-col ui-col-4 ui-col-border-right ui-col-align-center align-center valign-middle" style="flex: 0 0 33.33333333333333%;"> <view class="ui-col-content align-center valign-middle"> 用户名 </view> </view> <view class="ui-col ui-col-8 ui-col-align-center align-center valign-middle" style="flex: 0 0 66.66666666666666%;"> <view class="ui-col-content align-center valign-middle"> <input name="input" placeholder="请输入用户名" bindinput="username"></input> </view> </view> </view> </view> </view> </view> <view class="ui-row ui-row-border-top ui-row-border-bottom" style="margin-bottom: 20px;height:40px;"> <view class="ui-col ui-col-border-right ui-col-align-center align-center valign-middle" style="flex:0 0 60px;"> <view class="ui-col-content align-center valign-middle"> </view> </view> <view class="ui-col" style=""> <view class="ui-col-content"> <view class="ui-row" style="height:40px;"> <view class="ui-col ui-col-4 ui-col-border-right ui-col-align-center align-center valign-middle" style="flex: 0 0 33.33333333333333%;"> <view class="ui-col-content align-center valign-middle"> 手机号码 </view> </view> <view class="ui-col ui-col-8 ui-col-align-center align-center valign-middle" style="flex: 0 0 66.66666666666666%;"> <view class="ui-col-content align-center valign-middle"> <input name="input" placeholder="请输入手机号码" bindinput="tell"></input> </view> </view> </view> </view> </view> </view> <view class="ui-row ui-row-border-top ui-row-border-bottom" style="margin-bottom: 20px;height:40px;"> <view class="ui-col ui-col-border-right ui-col-align-center align-center valign-middle" style="flex:0 0 60px;"> <view class="ui-col-content align-center valign-middle"> </view> </view> <view class="ui-col" style=""> <view class="ui-col-content"> <view class="ui-row" style="height:40px;"> <view class="ui-col ui-col-4 ui-col-border-right ui-col-align-center align-center valign-middle" style="flex: 0 0 33.33333333333333%;"> <view class="ui-col-content align-center valign-middle"> 密码 </view> </view> <view class="ui-col ui-col-8 ui-col-align-center align-center valign-middle" style="flex: 0 0 66.66666666666666%;"> <view class="ui-col-content align-center valign-middle"> <input placeholder="设置密码" password="true" bindinput="password"></input> </view> </view> </view> </view> </view> </view> <view class="ui-row ui-row-border-top ui-row-border-bottom" style="margin-bottom: 20px;height:40px;"> <view class="ui-col ui-col-border-right ui-col-align-center align-center valign-middle" style="flex:0 0 60px;"> <view class="ui-col-content align-center valign-middle"> </view> </view> <view class="ui-col" style=""> <view class="ui-col-content"> <view class="ui-row" style="height:40px;"> <view class="ui-col ui-col-4 ui-col-border-right ui-col-align-center align-center valign-middle" style="flex: 0 0 33.33333333333333%;"> <view class="ui-col-content align-center valign-middle"> 确认密码 </view> </view> <view class="ui-col ui-col-8 ui-col-align-center align-center valign-middle" style="flex: 0 0 66.66666666666666%;"> <view class="ui-col-content align-center valign-middle"> <input placeholder="设置密码" password="true" bindinput="rpassword"></input> </view> </view> </view> </view> </view> </view> <view class="ui-row ui-row-border-top ui-row-border-bottom" style="margin-bottom: 20px;height:40px;"> <view class="ui-col ui-col-border-right ui-col-align-center align-center valign-middle" style="flex:0 0 60px;"> <view class="ui-col-content align-center valign-middle"> </view> </view> <view class="ui-col" style=""> <view class="ui-col-content"> <view class="ui-row" style="height:40px;"> <view class="ui-col ui-col-4 ui-col-border-right ui-col-align-center align-center valign-middle" style="flex: 0 0 33.33333333333333%;"> <view class="ui-col-content align-center valign-middle"> <button type="primary" bindtap="submitHandler">注册</button> </view> </view> <view class="ui-col ui-col-4 ui-col-border-right ui-col-align-center align-center valign-middle" style="flex: 0 0 33.33333333333333%;"> <view class="ui-col-content align-center valign-middle"> <button bindtap="ureg">用户登录</button> </view> </view> <view class="ui-col ui-col-4 ui-col-border-right ui-col-align-center align-center valign-middle" style="flex: 0 0 33.33333333333333%;"> <view class="ui-col-content align-center valign-middle"> <button bindtap="treg">教师注册</button> </view> </view> </view> </view> </view> </view> </view> </view>
2、js文件
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = Page({ data: { name: "", pass: "", rpass: "", tell: "", isname: false, istell: false, ispass: false }, treg: function treg() { wx.navigateTo({ url: "./../teacher/tregdit" }); }, ureg: function ureg() { wx.navigateTo({ url: "./../ulogin/ulogin" }); }, tell: function tell(e) { this.setData({ tell: e.detail.value }); }, username: function username(e) { this.setData({ name: e.detail.value }); }, password: function password(e) { this.setData({ pass: e.detail.value }); }, rpassword: function rpassword(e) { this.setData({ rpass: e.detail.value }); }, submitHandler: function submitHandler() { var that = this; if (that.data.name == "") { wx.showModal({ title: "错误", content: "用户名不能为空" }); that.isname = false; } else { that.isname = true; } if (that.data.pass != that.data.rpass || that.data.pass == "" || that.data.rpass == "") { wx.showModal({ title: "错误", content: "两次密码输入不一致" }); that.ispass = false; } else { that.ispass = true; } if (that.data.tell.length != 11) { wx.showModal({ title: "错误", content: "手机格式有误" }); that.istell = false; } else { that.istell = true; } if (that.istell && that.ispass && that.isname) { // 提交 wx.request({ url: "http://localhost:8080/Teacher/uregedit.action", //接口地址 data: { username: that.data.name, password: that.data.pass, tell: that.data.tell }, method: "get", header: { "content-type": "application/json" }, success: function success(res) { //页面跳转 wx.navigateTo({ url: "./../tlogin/tlogin" }); //页面跳转 } }); // 提交 } } });
3、wxss文件
.frm { margin-top: 200rpx; }
登录功能
1、wxml文件
<view> <view class="frm"> <view class="ui-row ui-row-border-top ui-row-border-bottom" style="margin-bottom: 20px;height:40px;"> <view class="ui-col ui-col-border-right ui-col-align-center align-center valign-middle" style="flex:0 0 60px;"> <view class="ui-col-content align-center valign-middle"> </view> </view> <view class="ui-col" style=""> <view class="ui-col-content"> <view class="ui-row" style="height:40px;"> <view class="ui-col ui-col-4 ui-col-border-right ui-col-align-center align-center valign-middle" style="flex: 0 0 33.33333333333333%;"> <view class="ui-col-content align-center valign-middle"> 用户名 </view> </view> <view class="ui-col ui-col-8 ui-col-align-center align-center valign-middle" style="flex: 0 0 66.66666666666666%;"> <view class="ui-col-content align-center valign-middle"> <input name="input" placeholder="请输入用户名" bindinput="username"></input> </view> </view> </view> </view> </view> </view> <view class="ui-row ui-row-border-top ui-row-border-bottom" style="margin-bottom: 20px;height:40px;"> <view class="ui-col ui-col-border-right ui-col-align-center align-center valign-middle" style="flex:0 0 60px;"> <view class="ui-col-content align-center valign-middle"> </view> </view> <view class="ui-col" style=""> <view class="ui-col-content"> <view class="ui-row" style="height:40px;"> <view class="ui-col ui-col-4 ui-col-border-right ui-col-align-center align-center valign-middle" style="flex: 0 0 33.33333333333333%;"> <view class="ui-col-content align-center valign-middle"> 密码 </view> </view> <view class="ui-col ui-col-8 ui-col-align-center align-center valign-middle" style="flex: 0 0 66.66666666666666%;"> <view class="ui-col-content align-center valign-middle"> <input placeholder="设置密码" password="true" bindinput="password"></input> </view> </view> </view> </view> </view> </view> <view class="ui-row ui-row-border-top ui-row-border-bottom" style="margin-bottom: 20px;height:40px;"> <view class="ui-col ui-col-border-right ui-col-align-center align-center valign-middle" style="flex:0 0 60px;"> <view class="ui-col-content align-center valign-middle"> </view> </view> <view class="ui-col" style=""> <view class="ui-col-content"> <view class="ui-row" style="height:40px;"> <view class="ui-col ui-col-4 ui-col-border-right ui-col-align-center align-center valign-middle" style="flex: 0 0 33.33333333333333%;"> <view class="ui-col-content align-center valign-middle"> <button type="primary" bindtap="submitHandler">登录</button> </view> </view> <view class="ui-col ui-col-4 ui-col-border-right ui-col-align-center align-center valign-middle" style="flex: 0 0 33.33333333333333%;"> <view class="ui-col-content align-center valign-middle"> <button bindtap="ureg">用户注册</button> </view> </view> <view class="ui-col ui-col-4 ui-col-border-right ui-col-align-center align-center valign-middle" style="flex: 0 0 33.33333333333333%;"> <view class="ui-col-content align-center valign-middle"> <button bindtap="tlogin">老师登录</button> </view> </view> </view> </view> </view> </view> </view> </view>
2、js文件
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = Page({ data: { name: "", pass: "", isname: false, ispass: false }, ureg: function ureg() { wx.navigateTo({ url: "./../user/reg" }); }, tlogin: function tlogin() { wx.navigateTo({ url: "./../tlogin/tlogin" }); }, username: function username(e) { this.setData({ name: e.detail.value }); }, password: function password(e) { this.setData({ pass: e.detail.value }); }, submitHandler: function submitHandler() { var that = this; if (that.data.name == "") { wx.showModal({ title: "错误", content: "用户名不能为空" }); that.isname = false; } else { that.isname = true; } if (that.data.pass == "") { wx.showModal({ title: "错误", content: "密码不能为空" }); that.ispass = false; } else { that.ispass = true; } if (that.ispass && that.isname) { // 提交 wx.request({ url: "http://localhost:8080/Teacher/ulogin.action", //接口地址 data: { username: that.data.name, password: that.data.pass }, method: "get", header: { "content-type": "application/json" }, success: function success(res) { var info = res.data; if (info == "fail") { wx.showModal({ title: "错误", content: "用户名或者密码输入不正确" }); } else { //存储数据 // 同步接口立即写入 wx.setStorageSync("uname", that.data.name + ""); wx.setStorageSync("indentity", "user"); //页面跳转 //页面跳转 wx.switchTab({ url: "/pages/center/center" }); console.log("页面跳转111"); } } }); // 提交 } } });
3、wxss文件
.frm { margin-top: 200rpx; }
我的后端是用java的ssh框架实现的
package cn.com.service; import java.io.IOException; import java.util.List; import javax.servlet.http.HttpServletResponse; import net.sf.json.JSONArray; import org.apache.struts2.ServletActionContext; import org.hibernate.Query; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; import com.opensymphony.xwork2.ModelDriven; import cn.com.bean.User; @Repository(value = "ulogin") @Scope("prototype") public class Ulogin implements ModelDriven<User> { @Autowired private SessionFactory sf; @Autowired private User u; // 注册功能 @Transactional public String regedit() { Session session = sf.getCurrentSession(); session.save(u); return null; } // 登录功能 @Transactional public String login() { Session session = sf.getCurrentSession(); String sql = "from User where username="; Query query = session.createQuery(sql); query.setString(0, u.getUsername()); query.setString(1, u.getPassword()); User uu = (User) query.uniqueResult(); String info = null; if (uu != null) { info = "success"; } else { info = "fail"; } HttpServletResponse response = ServletActionContext.getResponse(); response.setCharacterEncoding("utf-8"); try { response.getWriter().write(info); } catch (IOException e) { e.printStackTrace(); } return null; } @Override public User getModel() { // TODO Auto-generated method stub return u; } }
总结
以上所述是小编给大家介绍的微信小程序实现注册登录功能(表单校验、错误提示),希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!
极乐门资源网 Design By www.ioogu.com
极乐门资源网
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
极乐门资源网 Design By www.ioogu.com
暂无微信小程序实现注册登录功能(表单校验、错误提示)的评论...
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。
更新日志
2024年11月16日
2024年11月16日
- 第五街的士高《印度激情版》3CD [WAV+CUE][2.4G]
- 三国志8重制版哪个武将智力高 三国志8重制版智力武将排行一览
- 三国志8重制版哪个武将好 三国志8重制版武将排行一览
- 三国志8重制版武将图像怎么保存 三国志8重制版武将图像设置方法
- 何方.1990-我不是那种人【林杰唱片】【WAV+CUE】
- 张惠妹.1999-妹力新世纪2CD【丰华】【WAV+CUE】
- 邓丽欣.2006-FANTASY【金牌大风】【WAV+CUE】
- 饭制《黑神话》蜘蛛四妹手办
- 《燕云十六声》回应跑路:年内公测版本完成95%
- 网友发现国内版《双城之战》第二季有删减:亲亲环节没了!
- 邓丽君2024-《漫步人生路》头版限量编号MQA-UHQCD[WAV+CUE]
- SergeProkofievplaysProkofiev[Dutton][FLAC+CUE]
- 永恒英文金曲精选4《TheBestOfEverlastingFavouritesVol.4》[WAV+CUE]
- 群星《国风超有戏 第9期》[320K/MP3][13.63MB]
- 群星《国风超有戏 第9期》[FLAC/分轨][72.56MB]