### 登录方法
```
login() {
// console.log(md5(this.password + 'app'));return;
if (this.mobile.length != 11) {
uni.showToast({
icon: 'none',
title: '手机号不正确'
});
return;
}
if (this.password.length < 6) {
uni.showToast({
icon: 'none',
title: '密码不正确'
});
return;
}
// uni.switchTab({
// url:'./user/index'
// })
uni.request({
url: this.$url +'/api/v1.login/index',
data: {
mobile:this.mobile,
password:md5(this.password)
},
method: 'POST',
dataType:'json',
success: (res) => {
// console.log(res.data.data.token);
if(res.data.code!=1){
uni.showToast({title:res.data.msg,icon:'none'});
}else{
uni.setStorageSync('token', res.data.data.token);
// var token =uni.getStorageSync('token');
// console.log(token);
// this.login();
// uni.navigateBack();
uni.switchTab({
url:'./index/index'
})
}
}
});
}
```
### 注册方法
```
reg() {
if (this.username == "" || this.username == null || this.username == undefined) {
uni.showToast({
icon: 'none',
title: '昵称不能为空'
});
return;
}
if (this.xieyi == false) {
uni.showToast({
icon: 'none',
title: '请先阅读《软件用户协议》'
});
return;
}
if (this.mobile.length != 11) {
uni.showToast({
icon: 'none',
title: '手机号不正确'
});
return;
}
if (this.password.length < 6) {
uni.showToast({
icon: 'none',
title: '密码长度必须6-20位'
});
return;
}
if (this.username == "" || this.username == null || this.username == undefined) {
uni.showToast({
icon: 'none',
title: '请输入验证码'
});
return;
}
uni.request({
url: global.host +'/api/v1.login/reg',
data: {
username: this.username,
mobile: this.mobile,
password: md5(this.password),
repassword: md5(this.repassword),
pay_pwd: md5(this.pay_pwd),
repay_pwd: md5(this.repay_pwd),
code: this.code,
p_mobile: this.p_mobile
},
method: 'POST',
dataType: 'json',
success: (res) => {
console.log(res);
if (res.data.code != 1) {
uni.showToast({
title: res.data.msg,
icon: 'none'
});
} else {
uni.showToast({
title: res.data.msg
});
setTimeout(function() {
uni.navigateBack();
}, 1500)
}
}
});
}
}
```