diff --git a/changelog.md b/changelog.md index 2a68080..dccc550 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,6 @@ ## v0.16.10 * U 登录界面优化 + * U 优化分享 ## v0.16.9 * A 管理界面浏览历史查看 diff --git a/miniprogram/account/pages/account/account.js b/miniprogram/account/pages/account/account.js index 63d4c71..196281d 100644 --- a/miniprogram/account/pages/account/account.js +++ b/miniprogram/account/pages/account/account.js @@ -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); } }) }, diff --git a/miniprogram/account/pages/account/account.wxml b/miniprogram/account/pages/account/account.wxml index 70f7e91..e4be6f6 100644 --- a/miniprogram/account/pages/account/account.wxml +++ b/miniprogram/account/pages/account/account.wxml @@ -7,7 +7,7 @@