From 91ecc48fdd7a3407875d5068c1dfc6f63497be6f Mon Sep 17 00:00:00 2001 From: weiwei Date: Tue, 25 Feb 2025 09:47:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/sheep/utils/request.ts | 50 +++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/src/sheep/utils/request.ts b/src/sheep/utils/request.ts index ce9ed7e..37c1547 100644 --- a/src/sheep/utils/request.ts +++ b/src/sheep/utils/request.ts @@ -99,6 +99,31 @@ const responseHelpers = { case 401: this.handleUnauthorized() break + case 424: + try { + const params = new URL(window.location.href).searchParams + const token = params.get("uabaseToken") + if (token) { + userApi.auth(token).then((res) => { + if (res?.code === 0) { + uni.setStorageSync(TOKEN_KEY, res.data) + } else { + uni.removeStorageSync(TOKEN_KEY) + uni.removeStorageSync(USER_INFO_KEY) + // uni.showToast({ title: "登录已过期", icon: "none" }) + return Promise.resolve({ + code: 1, + data: "登录已过期", + msg: "登录已过期", + }) + } + }) + } + } catch (error) { + uni.hideLoading() + uni.showToast({ title: "错误", icon: "none" }) + } + break default: uni.showToast({ title: response.data.msg || "服务器开小差啦,请稍后再试~", @@ -248,6 +273,30 @@ http.interceptors.response.use( uni.showToast({ title: "登录已过期,请重新登录", icon: "none" }) router.jump("/pages/test/login") return false + } else { + try { + const params = new URL(window.location.href).searchParams + const token = params.get("uabaseToken") + if (token) { + userApi.auth(token).then((res) => { + if (res?.code === 0) { + uni.setStorageSync(TOKEN_KEY, res.data) + } else { + uni.removeStorageSync(TOKEN_KEY) + uni.removeStorageSync(USER_INFO_KEY) + // uni.showToast({ title: "登录已过期", icon: "none" }) + return Promise.resolve({ + code: 1, + data: "登录已过期", + msg: "登录已过期", + }) + } + }) + } + } catch (error) { + uni.hideLoading() + uni.showToast({ title: "错误", icon: "none" }) + } } } @@ -259,7 +308,6 @@ http.interceptors.response.use( mask: true, }) } - return false }, )