diff --git a/pages/index/index.vue b/pages/index/index.vue index a65ad23..ca54c16 100644 --- a/pages/index/index.vue +++ b/pages/index/index.vue @@ -46,7 +46,7 @@ }, onLoad() { this.winHeight = uni.getSystemInfoSync().screenHeight - uni.getSystemInfoSync().statusBarHeight * 2-20; - + }, onShow(){ this.isBd = uni.getStorageSync("userInfo_BD_token").token diff --git a/utils/util.js b/utils/util.js index 44396b9..5ec8a6d 100755 --- a/utils/util.js +++ b/utils/util.js @@ -212,7 +212,67 @@ const request = options => { } } else { 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) { // console.log("res",res.data.errmsg) options.utilFail(res.data.errmsg || '接口发生未知错误');