微信小程序?qū)崿F(xiàn)注冊(cè)登錄功能(表單校驗(yàn)、錯(cuò)誤提示)
口說(shuō)無(wú)憑,實(shí)現(xiàn)效果如下

前端 部分
注冊(cè)功能
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">
用戶(hù)名
</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="請(qǐng)輸入用戶(hù)名" 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">
手機(jī)號(hào)碼
</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="請(qǐng)輸入手機(jī)號(hào)碼" 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="設(shè)置密碼" 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">
確認(rèn)密碼
</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="設(shè)置密碼" 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">注冊(cè)</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">用戶(hù)登錄</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">教師注冊(cè)</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: "錯(cuò)誤",
content: "用戶(hù)名不能為空"
});
that.isname = false;
} else {
that.isname = true;
}
if (that.data.pass != that.data.rpass || that.data.pass == "" || that.data.rpass == "") {
wx.showModal({
title: "錯(cuò)誤",
content: "兩次密碼輸入不一致"
});
that.ispass = false;
} else {
that.ispass = true;
}
if (that.data.tell.length != 11) {
wx.showModal({
title: "錯(cuò)誤",
content: "手機(jī)格式有誤"
});
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) {
//頁(yè)面跳轉(zhuǎn)
wx.navigateTo({
url: "./../tlogin/tlogin"
});
//頁(yè)面跳轉(zhuǎn)
}
});
// 提交
}
}
});
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">
用戶(hù)名
</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="請(qǐng)輸入用戶(hù)名" 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="設(shè)置密碼" 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">用戶(hù)注冊(cè)</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: "錯(cuò)誤",
content: "用戶(hù)名不能為空"
});
that.isname = false;
} else {
that.isname = true;
}
if (that.data.pass == "") {
wx.showModal({
title: "錯(cuò)誤",
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: "錯(cuò)誤",
content: "用戶(hù)名或者密碼輸入不正確"
});
} else {
//存儲(chǔ)數(shù)據(jù)
// 同步接口立即寫(xiě)入
wx.setStorageSync("uname", that.data.name + "");
wx.setStorageSync("indentity", "user");
//頁(yè)面跳轉(zhuǎn)
//頁(yè)面跳轉(zhuǎn)
wx.switchTab({
url: "/pages/center/center"
});
console.log("頁(yè)面跳轉(zhuǎn)111");
}
}
});
// 提交
}
}
});
3、wxss文件
.frm {
margin-top: 200rpx;
}
我的后端是用java的ssh框架實(shí)現(xiàn)的
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;
// 注冊(cè)功能
@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=? and password=?";
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;
}
}
總結(jié)
以上所述是小編給大家介紹的微信小程序?qū)崿F(xiàn)注冊(cè)登錄功能(表單校驗(yàn)、錯(cuò)誤提示),希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
如果你覺(jué)得本文對(duì)你有幫助,歡迎轉(zhuǎn)載,煩請(qǐng)注明出處,謝謝!
- 微信小程序登錄與注冊(cè)功能的實(shí)現(xiàn)詳解
- 微信小程序?qū)崿F(xiàn)登錄注冊(cè)功能
- 詳解微信小程序入門(mén)從這里出發(fā)(登錄注冊(cè)、開(kāi)發(fā)工具、文件及結(jié)構(gòu)介紹)
- 微信小程序+云開(kāi)發(fā)實(shí)現(xiàn)歡迎登錄注冊(cè)
- 微信小程序登錄態(tài)和檢驗(yàn)注冊(cè)過(guò)沒(méi)的app.js寫(xiě)法
- 微信小程序?qū)崿F(xiàn)登錄注冊(cè)tab切換效果
- 微信小程序?qū)崿F(xiàn)登錄界面示例
- 微信小程序?qū)崿F(xiàn)登錄界面
- 微信小程序?qū)崿F(xiàn)登錄注冊(cè)界面
相關(guān)文章
layer.msg()去掉默認(rèn)時(shí)間,實(shí)現(xiàn)手動(dòng)關(guān)閉的方法
今天小編就為大家分享一篇layer.msg()去掉默認(rèn)時(shí)間,實(shí)現(xiàn)手動(dòng)關(guān)閉的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-09-09
ES6入門(mén)教程之Iterator與for...of循環(huán)詳解
最近在學(xué)習(xí)ES6,剛剛看到Iterator和for...of循環(huán)這一章,所以想要跟大家略微分享一下,下面這篇文章主要給大家介紹了關(guān)于ES6入門(mén)學(xué)習(xí)中Iterator與for...of循環(huán)的相關(guān)資料,不足之處還望大家多多指正,需要的朋友們可以參考學(xué)習(xí)。2017-05-05
關(guān)于JavaScript中parseInt()的一個(gè)怪異行為解決
parseInt()是內(nèi)置的?JS?函數(shù),用于解析數(shù)字字符串中的整數(shù),下面這篇文章主要給大家介紹了關(guān)于JavaScript中parseInt()的一個(gè)怪異行為解決,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-12-12
JavaScript學(xué)習(xí)筆記之惰性函數(shù)示例詳解
函數(shù)是js世界的一等公民,js的動(dòng)態(tài)性、易變性在函數(shù)的應(yīng)用上,體現(xiàn)的淋漓盡致。下面這篇文章主要給大家介紹了關(guān)于JavaScript學(xué)習(xí)筆記之惰性函數(shù)的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),需要的朋友可以參考下。2017-08-08
JS冷知識(shí)之不起眼但有用的String.raw方法
String.raw是JavaScript中模板字符串的一個(gè)標(biāo)簽函數(shù),它的作用是將模板字符串不轉(zhuǎn)義的原始字符串內(nèi)容返回,接下來(lái)通過(guò)本文給大家介紹JS冷知識(shí)之不起眼但有用的String.raw方法,需要的朋友可以參考下2022-06-06
通過(guò)js實(shí)現(xiàn)壓縮圖片上傳功能
這篇文章主要介紹了通過(guò)js實(shí)現(xiàn)壓縮圖片上傳功能,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-02-02
10個(gè)很少使用的JavaScript?Console方法分享
你一定聽(tīng)說(shuō)過(guò)?console.log()?,而且可能一直在使用它,在本文中,我們將探討一些最有用的控制臺(tái)方法,以及它們?cè)跀?shù)據(jù)可視化、調(diào)試等方面的用途,感興趣的小伙伴可以學(xué)習(xí)一下2023-09-09
JavaScript:Div層拖動(dòng)效果實(shí)例代碼
這篇文章介紹了JavaScript:Div層拖動(dòng)效果實(shí)例代碼,有需要的朋友可以參考一下2013-08-08

