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

master
educoder_weapp 5 years ago
parent 2b2bebf70a
commit 7c07e356a3

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

@ -18,7 +18,10 @@ Page({
message, message,
msgType: type, msgType: type,
msgDuration: duration, msgDuration: duration,
showMsg: true showMsg: false
});
wx.nextTick(()=>{
this.setData({showMsg: true});
}) })
}, },
hideMsg(){ hideMsg(){
@ -35,23 +38,53 @@ Page({
onLoginBlur({detail:{value:login}}){ onLoginBlur({detail:{value:login}}){
this.validLogin(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){ validLogin(login){
if(!login) { if(!login) {
return this.setData({showtip:0}); return this.setData({showMsg:0, hasError:0});
} }
let {action} = this.data; let {action} = this.data;
if(this.cache.login==login&&this.cache.action==action)
return;
if(action=="login"){ if(action=="login"){
// some use login to login, this case judge can be wrong // some use login to login, this case judge can be wrong
this.cache.type = type; this.cache.action = action;
this.cache.login = login; 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; app.api(api_name)({
if(this.cache.login==login&&this.cache.type==type) return;
app.api("accounts.valid_email_and_phone")({
login, type, login, type,
complete: res => { complete: res => {
this.cache.type = type; this.cache.action = action;
this.cache.login = login; this.cache.login = login;
} }
}) })
@ -61,8 +94,15 @@ Page({
}) })
.catch(e=>{ .catch(e=>{
var hasError = e.message.indexOf("网络")!=-1?2:1; var hasError = e.message.indexOf("网络")!=-1?2:1;
if(action=='login'){
hasError = e.message == '该账号尚未注册'?1:0;
}
this.setData({ hasError}); 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(){ login_test(){
@ -86,11 +126,7 @@ Page({
}) })
.catch(e=>{ .catch(e=>{
if (showToast){ if (showToast){
app.api("accounts.valid_email_and_phone")({login, type:2}) this.showError(e);
.then(res=>{
this.showError(e);
})
.catch(this.showError);
} }
}) })
}, },

@ -7,7 +7,7 @@
<form class="account-form" bindsubmit="onSubmit"> <form class="account-form" bindsubmit="onSubmit">
<view class="inputs"> <view class="inputs">
<view class="input-wrap"> <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> </input>
</view> </view>
<view class="input-wrap {{action!='login'?'':'hidden'}}"> <view class="input-wrap {{action!='login'?'':'hidden'}}">
@ -45,6 +45,6 @@
</view> </view>
<view class="foot"> <view class="foot">
<navigator class="agreement" hover-class="none" url="/markdown/account/agreement/agreement"> <navigator class="agreement" hover-class="none" url="/markdown/account/agreement/agreement">
登录即代表您同意 <text class="color-main agreement">用户协议</text> 登录或注册即代表您同意 <text class="color-main agreement">用户协议</text>
</navigator> </navigator>
</view> </view>

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

@ -191,7 +191,8 @@ Page({
}, },
initCanvas(src="") { initCanvas(src="") {
const { cropperOpt } = this.data; const { cropperOpt } = this.data;
Object.assign(cropperOpt, { src }); if(src)
Object.assign(cropperOpt, { src });
this.mycropper = new WeCropper(cropperOpt); this.mycropper = new WeCropper(cropperOpt);
this.mycropper this.mycropper
.on('beforeImageLoad', (ctx) => { .on('beforeImageLoad', (ctx) => {
@ -214,6 +215,10 @@ Page({
zoom: 8, zoom: 8,
width, width,
height, height,
boundStyle:{
color:"#0080f0",
lineWidth: 1.2
},
cut: { cut: {
x: (width - 300) / 2, x: (width - 300) / 2,
y: (height - 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", "pathName": "markdown/shixun/shixun/shixun",
"query": "identifier=tb7hw62n", "query": "identifier=tb7hw62n",
"scene": null "scene": null
},
{
"id": -1,
"name": "account",
"pathName": "account/pages/account/account",
"query": "course_id=7813",
"scene": null
} }
] ]
} }

Loading…
Cancel
Save