From 4f9247834feecd0efc5b122273d265623e4bb283 Mon Sep 17 00:00:00 2001 From: lion <120344285@qq.com> Date: Mon, 4 Mar 2024 11:33:26 +0800 Subject: [PATCH] =?UTF-8?q?tokentoken=E9=89=B4=E6=9D=83=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/index/index.vue | 2 +- utils/util.js | 62 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 62 insertions(+), 2 deletions(-) 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 || '接口发生未知错误');