U 优化登录注册的信息校验

master
educoder_weapp 5 years ago
parent 2b2bebf70a
commit 7c07e356a3

@ -1,5 +1,6 @@
## v0.16.10
* U 登录界面优化
* U 优化分享
## v0.16.9
* A 管理界面浏览历史查看

@ -18,7 +18,10 @@ Page({
message,
msgType: type,
msgDuration: duration,
showMsg: true
showMsg: false
});
wx.nextTick(()=>{
this.setData({showMsg: true});
})
},
hideMsg(){
@ -35,23 +38,53 @@ Page({
onLoginBlur({detail:{value:login}}){
this.validLogin(login);
},
validPhoneEmail: function ({login}) {
// a simple pre-check for input
let phoneReg = /^[1][0-9]{10}$/;
let emailReg = /.+@.+\..+/;
if(!phoneReg.test(login)&&!emailReg.test(login)){
return false;
}else
return true;
},
validLogin(login){
if(!login) {
return this.setData({showtip:0});
return this.setData({showMsg:0, hasError:0});
}
let {action} = this.data;
if(this.cache.login==login&&this.cache.action==action)
return;
if(action=="login"){
// some use login to login, this case judge can be wrong
this.cache.type = type;
this.cache.action = action;
this.cache.login = login;
return this.setData({hasError:0, showMsg:0});
var api_name = 'weapps.check_account';
var type = 'login';
}else if(action=='register'){
var api_name = "weapps.check_account";
var type = "register";
if(!this.validPhoneEmail({login})){
this.cache.action = action;
this.cache.login = login;
this.showError({message:"请输入正确的邮箱或手机号", duration:0});
this.setData({hasError:0});
return;
}
}else if(action=='reset'){
var api_name = "accounts.valid_email_and_phone";
var type = 2;
if(!this.validPhoneEmail({login})){
this.cache.action = action;
this.cache.login = login;
this.showError({message:"请输入正确的手机号或邮箱", duration:0});
this.setData({hasError:0});
return;
}
}
let type = action=="register"?1:2;
if(this.cache.login==login&&this.cache.type==type) return;
app.api("accounts.valid_email_and_phone")({
app.api(api_name)({
login, type,
complete: res => {
this.cache.type = type;
this.cache.action = action;
this.cache.login = login;
}
})
@ -61,8 +94,15 @@ Page({
})
.catch(e=>{
var hasError = e.message.indexOf("网络")!=-1?2:1;
if(action=='login'){
hasError = e.message == '该账号尚未注册'?1:0;
}
this.setData({ hasError});
this.showError({message: e.message.replace(/\n/g," "), duration: 0});
if(hasError){
this.showError({message: e.message.replace(/\n/g," "), duration: 0});
}else{
this.hideMsg();
}
})
},
login_test(){
@ -86,11 +126,7 @@ Page({
})
.catch(e=>{
if (showToast){
app.api("accounts.valid_email_and_phone")({login, type:2})
.then(res=>{
this.showError(e);
})
.catch(this.showError);
this.showError(e);
}
})
},

@ -7,7 +7,7 @@
<form class="account-form" bindsubmit="onSubmit">
<view class="inputs">
<view class="input-wrap">
<input name="login" bindblur="onLoginBlur" disabled="{{login_disabled}}" value="{{login}}" placeholder="邮箱或手机号">
<input name="login" bindblur="onLoginBlur" disabled="{{login_disabled}}" value="{{login}}" placeholder="{{action=='login'?'邮箱、手机号或用户名':'邮箱或手机号'}}">
</input>
</view>
<view class="input-wrap {{action!='login'?'':'hidden'}}">
@ -45,6 +45,6 @@
</view>
<view class="foot">
<navigator class="agreement" hover-class="none" url="/markdown/account/agreement/agreement">
登录即代表您同意 <text class="color-main agreement">用户协议</text>
登录或注册即代表您同意 <text class="color-main agreement">用户协议</text>
</navigator>
</view>

@ -110,7 +110,9 @@ navigator.agreement{
margin: 10px auto;
font-size: 14px;
text-align: center;
color: dimgray;
}
text.agreement{
text-decoration: underline;
font-weight: bold;
}

@ -191,7 +191,8 @@ Page({
},
initCanvas(src="") {
const { cropperOpt } = this.data;
Object.assign(cropperOpt, { src });
if(src)
Object.assign(cropperOpt, { src });
this.mycropper = new WeCropper(cropperOpt);
this.mycropper
.on('beforeImageLoad', (ctx) => {
@ -214,6 +215,10 @@ Page({
zoom: 8,
width,
height,
boundStyle:{
color:"#0080f0",
lineWidth: 1.2
},
cut: {
x: (width - 300) / 2,
y: (height - 300) / 2,

File diff suppressed because one or more lines are too long

@ -241,6 +241,13 @@
"pathName": "markdown/shixun/shixun/shixun",
"query": "identifier=tb7hw62n",
"scene": null
},
{
"id": -1,
"name": "account",
"pathName": "account/pages/account/account",
"query": "course_id=7813",
"scene": null
}
]
}

Loading…
Cancel
Save