|
|
|
@ -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);
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|