tokentoken鉴权失败处理

master
lion 2 years ago
parent 330eff0823
commit 4f9247834f

@ -46,7 +46,7 @@
}, },
onLoad() { onLoad() {
this.winHeight = uni.getSystemInfoSync().screenHeight - uni.getSystemInfoSync().statusBarHeight * 2-20; this.winHeight = uni.getSystemInfoSync().screenHeight - uni.getSystemInfoSync().statusBarHeight * 2-20;
}, },
onShow(){ onShow(){
this.isBd = uni.getStorageSync("userInfo_BD_token").token this.isBd = uni.getStorageSync("userInfo_BD_token").token

@ -212,7 +212,67 @@ const request = options => {
} }
} else { } else {
if (res.data.hasOwnProperty("errcode")) { if (res.data.hasOwnProperty("errcode")) {
// token鉴权失败
if (res.data?.errcode === 40001) {
if(options.requestType=='bd'){
uni.showModal({
title:'用户信息已失效',
confirmText:'重新登陆',
success:function(res){
if(res.confirm){
uni.removeStorageSync(userInfo_BD_token)
uni.redirectTo({
url:'/pages/index/login'
})
}
}
})
return
}else{
uni.showModal({
title:'用户信息已失效',
confirmText:'重新获取',
success:function(res){
if(res.confirm){
uni.removeStorageSync(user_info_key)
uni.login({
provider: 'weixin',
success: (res) => {
let url = HOST + '/api/mobile/user/login?code=' + res.code;
uni.request({
url: url,
method: 'GET',
success: result => {
let user_info = result.data
uni.setStorageSync(user_info_key, user_info)
const currentPage = getCurrentPages()[getCurrentPages().length - 1];
const currentPagePath ="/" + currentPage.route;
const currentPageOptions = currentPage.options;
const queryString = Object.keys(currentPageOptions)
.map(key => `${key}=${currentPageOptions[key]}`)
.join('&');
// 使用uni.reLaunch方法刷新当前页面
uni.reLaunch({
url: `${currentPagePath}?${queryString}`
});
console.log("reLaunch",`${currentPagePath}?${queryString}`)
}
});
}
});
// login end
}
}
}) // showConfirm end
return
}
}
if (options.utilFail != undefined) { if (options.utilFail != undefined) {
// console.log("res",res.data.errmsg) // console.log("res",res.data.errmsg)
options.utilFail(res.data.errmsg || '接口发生未知错误'); options.utilFail(res.data.errmsg || '接口发生未知错误');

Loading…
Cancel
Save