U 登录界面优化

master
educoder_weapp 5 years ago
parent f3cb7b10ed
commit 0995346d72

@ -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){

@ -1,7 +1,7 @@
<page-meta>
<navigation-bar title="{{action_text[action]}}" />
</page-meta>
<mp-toptips msg="{{error}}" type="error" show="{{hasError}}" delay="0"/>
<mp-toptips msg="{{message}}" type="{{msgType}}" show="{{showMsg}}" delay="{{msgDuration}}"/>
<view class="container">
<image class="logo {{logoLoaded?'':'hidden'}}" bindlongpress="login_test" src="{{attachDir}}751571" mode="aspectFit" bindload="onLogoLoad"></image>
<form class="account-form" bindsubmit="onSubmit">
@ -13,7 +13,7 @@
<view class="input-wrap {{action!='login'?'':'hidden'}}">
<input name="code" placeholder="验证码">
</input>
<button id="code" type="secondary" size="mini" form-type="submit" loading="{{code_status==2}}" disabled="{{code_status||hasError}}" class="obtain-code">
<button id="code" type="secondary" size="mini" form-type="submit" loading="{{code_status==2}}" disabled="{{code_status||hasError==1}}" class="obtain-code">
{{code_button_text}}
</button>
</view>

@ -23,6 +23,7 @@ page{
margin: 0px 20px;
display: flex;
justify-content: space-between;
align-items: center;
}
.checkbox-wrap switch{
transform: scale(0.82);

@ -111,7 +111,7 @@ Page({
}
let account = this.accounts.filter(i=>i.user_id == user_id) [0];
if(!account.save_password){
wx.navigateTo({ url: "../account/account?nostorage=1&error=账号过期,需重新登录; 密码将加密保存至本地&save_password=1&addaccount=1&login_disabled=1&login="+account.login});
this.navToAccount({login:account.login, message:"账号过期,需重新登录",login_disabled:1, msgType:"error"});
}else{
app.api("accounts.login")(account)
.then(res=>{
@ -121,18 +121,23 @@ Page({
accountManager.setCurrentAccount(account);
this.refresh();
}).catch(e=>{
wx.navigateTo({ url: "../account/account?nostorage=1&error=账号过期,需重新登录;密码将加密保存至本地&save_password=1&addaccount=1&login_disabled=1&login=" + account.login });
this.navToAccount({login:account.login, message:"账号过期,需重新登录",login_disabled:1, msgType:"error"});
})
}
},
navToAccount({login="", message="", msgType="info", login_disabled=""}={}){
wx.navigateTo({
url:`../account/account?nostorage=1&showMsg=1&message=${message}&msgType=${msgType}&msgDuration=0&&save_password=1&addaccount=1&login=${login}&login_disabled=${login_disabled}`
});
},
addAccount(){
this.oldNum = accountManager.getAccounts().length
if(this.oldNum>=5)
return wx.showToast({
title: '已达数量上限,无法添加',icon:"none"
})
wx.navigateTo({ url:"../account/account?nostorage=1&error=密码将加密保存至本地&save_password=1&addaccount=1"});
this.navToAccount({message:"密码将在本地加密保存"});
},
showMsg({message,duration=800}){
if(this.timeoutId)

@ -29,7 +29,7 @@
border-radius: 50%;
height: 40px;
width: 40px;
margin: 0 12px 0 8px;
margin: 0 12px 0 4px;
}
.info{

@ -108,7 +108,7 @@ Page({
this.setData({conditions});
this.refresh({refresh:1}).then(res=>{
wx.showToast({
title: '去除成功'
title: '删除筛选成功'
})
})
},
@ -129,8 +129,12 @@ Page({
},
onPullDownRefresh: function () {
this.conditions = null;
this.refresh({refresh:1});
this.setData({conditions:""});
this.refresh({refresh:1}).then(res=>{
wx.showToast({
title: '刷新成功'
})
})
},
onReachBottom: function () {

@ -17,7 +17,6 @@ Page({
eduImgDir:global.config.eduImgDir
},
onImgLoad(e){
;
this.setData({code_loaded:1});
},
onImgError(e){
@ -50,11 +49,16 @@ Page({
})
},
joinCourse: function(event) {
if(this.data.status==404){
return wx.showToast({
title: '该课堂已被删除了',icon:"none"
})
}
if (this.data.course.code_halt||!this.data.course.invite_code)
return wx.showToast({
title: '>︿<\n邀请码已经停用了',
icon:"none"
});
title: '>︿<\n邀请码已经停用了',
icon:"none"
});
this.setData({show_join_modal:1});
},
getPageUrl(){
@ -70,13 +74,23 @@ Page({
.then(({ course }) => {
this.setData({ course, status: 200 });
}).catch(e => {
if(e.code==404){
let course = {
name:"该课堂已被删除",
teacher_name:" ",
teacher_school:" ",
invite_code:"",
code_halt:1
};
e.message = "该课堂已被删除";
this.setData({course});
}
app.showError(e);
this.setData({ status: -1 })
this.setData({ status: e.code })
});
})
},
onLoad: function (options) {
;
var course_id;
if(options.course_id)
course_id= options.course_id;

@ -1,7 +1,10 @@
<view class="my-course">
<require-login/>
<nav-bar list="{{categories}}" current="{{current_cate}}" bindchange="onCategoryChange"/>
<scroll-view scroll-y="1" refresher-enabled="1" bindrefresherrefresh="onPullDownRefresh" bindscrolltolower="onReachBottom" lower-threshold="120" bindrefresh="onPullDownRefresh" class="body">
<scroll-view scroll-y="1" refresher-enabled="1"
bindrefresherrefresh="onPullDownRefresh"
bindscrolltolower="onReachBottom" lower-threshold="120"
bindrefresh="onPullDownRefresh" class="body">
<view class="nav-wrap">
<nav-bar list="{{statuses}}" width="300" itemWidth="140" cancellable="1" current="-1" type="plain" bg='' bindchange="onStatusChange"/>
</view>

@ -12,7 +12,6 @@
display: flex;
justify-content: flex-end;
text-align: end;
margin: 1px 10px 1px 0;
}
.course-wrap{

@ -222,10 +222,10 @@
"scene": null
},
{
"id": -1,
"id": 22,
"name": "course/pages/course_invite/course_invite",
"pathName": "course/pages/course_invite/course_invite",
"query": "course_id=7582",
"query": "course_id=7813",
"scene": null
},
{

Loading…
Cancel
Save