diff --git a/miniprogram/account/pages/account/account.js b/miniprogram/account/pages/account/account.js index 42d5fdb..63d4c71 100644 --- a/miniprogram/account/pages/account/account.js +++ b/miniprogram/account/pages/account/account.js @@ -6,11 +6,29 @@ Page({ data: { attachDir: global.config.attachDir, action:"login", + msgType: "info", code_button_text:"获取验证码", action_text:{login:"登录",register:"注册", reset:"找回密码"}, pos:{login:1, register:2, reset:3} }, cache:{}, + showMsg({message, type="info", duration=2000}){ + if(!message) return; + this.setData({ + message, + msgType: type, + msgDuration: duration, + showMsg: true + }) + }, + hideMsg(){ + this.setData({showMsg: false}); + }, + showError({message, duration}){ + if(!message) + return + this.showMsg({message, duration, type:"error"}); + }, onLogoLoad(){ this.setData({ logoLoaded: 1}); }, @@ -22,9 +40,12 @@ Page({ return this.setData({showtip:0}); } let {action} = this.data; - if(action=="login") + if(action=="login"){ // some use login to login, this case judge can be wrong - return this.setData({hasError:0}); + this.cache.type = type; + this.cache.login = login; + return this.setData({hasError:0, showMsg:0}); + } let type = action=="register"?1:2; if(this.cache.login==login&&this.cache.type==type) return; app.api("accounts.valid_email_and_phone")({ @@ -36,10 +57,12 @@ Page({ }) .then(res=>{ this.setData({hasError:0}); + this.hideMsg(); }) .catch(e=>{ var hasError = e.message.indexOf("网络")!=-1?2:1; - this.setData({ hasError, error: e.message.replace(/\n/g," ") }); + this.setData({ hasError}); + this.showError({message: e.message.replace(/\n/g," "), duration: 0}); }) }, login_test(){ @@ -54,7 +77,7 @@ Page({ .then(res=>{ res.message="登录成功"; if (showToast) - app.showMsg(res); + this.showMsg(res); let account = { ...res, login, password, save_password }; if(this.data.addaccount) accountManager.addAccount(account,0); @@ -62,29 +85,34 @@ Page({ this.navBack(); }) .catch(e=>{ - if (showToast) - app.showError(e); + if (showToast){ + app.api("accounts.valid_email_and_phone")({login, type:2}) + .then(res=>{ + this.showError(e); + }) + .catch(this.showError); + } }) }, register({login, password, code}){ app.api("accounts.register")({login, password, code}) .then(res=>{ - app.showMsg(res); + this.showMsg(res); this.navBack(); }).catch(e=>{ - app.showError(e); + this.showError(e); }) }, reset({ login, password: new_password, password_confirmation: new_password_confirmation, save_password ,code, no_login}){ app.api("accounts.reset_password")({login, new_password, new_password_confirmation, code}) .then(res=>{ res.message = "重置成功"; - app.showMsg(res); + this.showMsg(res); if(!no_login) this.login({ login, password: new_password, save_password, showToast:0}); }) .catch(e=>{ - app.showError(e); + this.showError(e); }) }, getCode({login}){ @@ -99,9 +127,9 @@ Page({ .then(res=>{ res.message = "发送成功"; this.countDown(); - app.showMsg(res); + this.showMsg(res); }).catch(e=>{ - app.showError(e); + this.showError(e); this.setData({code_status:0, code_button_text:"获取验证码"}) }) }, @@ -136,19 +164,19 @@ Page({ if(action!=this.data.action && action!="code") return true; if (!value.login) - return wx.showToast({title: '请输入邮箱或手机号', icon: "none"}) && false; + return this.showError({message: '请输入邮箱或手机号'}) && false; if(action=="code") return true; if (!value.password) - return wx.showToast({title: '请输入密码', icon: "none"}) && false; + return this.showError({message: '请输入密码'}) && false; if(action=="login") return true; if(!value.code) - return wx.showToast({ title: '请输入验证码', icon: "none" }) && false; + return this.showError({message: '请输入验证码' }) && false; if(action=="register") return true; if(!value.password_confirmation) - return wx.showToast({title: '请再次输入密码',icon:"none"}) && false; + return this.showError({message: '请再次输入密码'}) && false; return true; }, setAction(action){ diff --git a/miniprogram/account/pages/account/account.wxml b/miniprogram/account/pages/account/account.wxml index 856f334..70f7e91 100644 --- a/miniprogram/account/pages/account/account.wxml +++ b/miniprogram/account/pages/account/account.wxml @@ -1,7 +1,7 @@ - +