登录修改

static-project
chen 2022-06-10 11:26:10 +08:00
parent 8f0859622d
commit f4d80df8ca
4 changed files with 40 additions and 58 deletions

View File

@ -115,13 +115,12 @@
choosefoot(index){
if(index==0){
uni.reLaunch({url:'/pages/tabbar/pagehome/pagehome'})
} else {
}else if(index==1){
uni.reLaunch({url:'/pages/tabbar/cate/cate'})
}else {
if(this.$toolAll.tools.judgeAuth()) {
//
switch (index){
case 1:
uni.reLaunch({url:'/pages/tabbar/cate/cate'})
break;
case 2:
uni.reLaunch({url:'/pages/tabbar/cart/cart'})
break;

View File

@ -8,67 +8,48 @@ const goLogin = () => {
let flag = true;
// 刷新token并跳转到当前页面
const refreshTokenPage = () => {
uni.login({
provider: 'weixin',
success: (result)=> {
uni.request({
url: `${getApp().globalData.hostapi}user/login`,
method: 'post',
data: {code:result.code},
success: res => {
if(res.data.data.token!=''){
flag = true;
uni.setStorageSync('token',res.data.data.token); // 缓存token
uni.setStorageSync('openid',res.data.data.openid)//缓存openid
uni.setStorageSync('expire',res.data.data.expire); // 缓存失效时间(时间戳格式)
uni.reLaunch({ // 重新进入当前页面
url:uni.getStorageSync('page-path-options')
})
}
}
})
},
});
}
// 请求错误处理
const checkError = (e) => {
console.log('500接口错误');
// console.error("----接口错误----", e)
if (e.data) {
if (e.data.code) {
switch (Number(e.data.code)) {
case 500:
// 接口错误
console.log('500接口错误');
// 接口错误
console.log('500接口错误');
case 4003:
// 参数错误
console.log('4003参数错误');
// 参数错误
console.log('4003参数错误');
break;
case 4004:
// 记录不存在
console.log('4004记录不存在');
// 记录不存在
console.log('4004记录不存在');
break;
case 5001:
// xxx错误
console.log('5001xxx错误');
// xxx错误
console.log('5001xxx错误');
break;
case 5050:
// 服务器错误,请稍后重试
console.log('5050服务器错误请稍后重试');
// 调用到登录页
goLogin();
// 服务器错误,请稍后重试
console.log('5050服务器错误请稍后重试');
// 调用到登录页
goLogin();
break;
case 5051:
// 未知错误
console.log('5051未知错误');
// 未知错误
console.log('5051未知错误');
break;
case 6001:
// token验证失败或已失效
console.log('6001token验证失败或已失效');
if(flag) {
flag = false;
// 调用刷新token事件并跳转到当前页面
refreshTokenPage();
}
// token验证失败或已失效
console.log('6001token验证失败或已失效');
if(flag) {
flag = false;
// 调用刷新token事件并跳转到当前页面
refreshTokenPage();
}
break;
}
}
@ -112,6 +93,10 @@ const request = (method, url, options) => {
console.log(`${url}返的结果===>`,res);
if (res.statusCode == 200) {
resolve(res.data);
if(res.data.code !== 0){
// 接口返回错误信息
checkError(res);
}
} else {
// 接口返回错误信息
checkError(res);

View File

@ -117,17 +117,15 @@
},
//
chooseGe(obj) {
if(this.$toolAll.tools.judgeAuth()) {
let exist = obj.url.slice(0,18);
if(exist=='/pages/tabbar/cate') {
uni.reLaunch({
url:obj.url
})
} else {
uni.navigateTo({
url:obj.url
})
}
let exist = obj.url.slice(0,18);
if(exist=='/pages/tabbar/cate') {
uni.reLaunch({
url:obj.url
})
} else {
uni.navigateTo({
url:obj.url
})
}
},
//

View File

@ -55,7 +55,6 @@
//
submit(){
if(this.checkEmpty() && this.flag){
console.log(121231222)
this.flag = false;
let params = {
sku_list: uni.getStorageSync('buyList'),
@ -71,6 +70,7 @@
url:`/pagesB/finish/finish?id=${res.data.id}`
})
}else{
console.log(res.msg,'提示信息')
this.$toolAll.tools.showToast(res.msg);
this.flag = true;
}