From f31ef4b79df757443202140910996c8becbd4e0d Mon Sep 17 00:00:00 2001 From: WindowBird <13870814+windows-bird@user.noreply.gitee.com> Date: Mon, 10 Nov 2025 16:34:34 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=87=E6=9C=9F=E8=B7=B3=E8=BD=AC=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/request/index.js | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/utils/request/index.js b/utils/request/index.js index 878b5dd..ebf26ac 100644 --- a/utils/request/index.js +++ b/utils/request/index.js @@ -4,6 +4,8 @@ import { useUserStore } from '@/store/user' * 初始化请求拦截器 * 使用 Pinia store 管理用户状态和 token */ +let isRedirectingToLogin = false + export const Request = () => { // 初始化请求配置 uni.$uv.http.setConfig((config) => { @@ -48,9 +50,15 @@ export const Request = () => { // token 过期或无效,清除登录状态 const userStore = useUserStore() userStore.logout() - - // 跳转到登录页面(根据实际路由调整) - // uni.reLaunch({ url: '/pages/login/index' }) + + if (!isRedirectingToLogin) { + isRedirectingToLogin = true + uni.$uv.toast('登录已过期,请重新登录') + setTimeout(() => { + uni.reLaunch({ url: '/pages/login/index' }) + isRedirectingToLogin = false + }, 200) + } } if (data.code !== 200) { @@ -83,7 +91,14 @@ export const Request = () => { if (response.statusCode === 401 || response.statusCode === 403) { const userStore = useUserStore() userStore.logout() - // uni.reLaunch({ url: '/pages/login/index' }) + if (!isRedirectingToLogin) { + isRedirectingToLogin = true + uni.$uv.toast('登录已过期,请重新登录') + setTimeout(() => { + uni.reLaunch({ url: '/pages/login/index' }) + isRedirectingToLogin = false + }, 200) + } } return Promise.reject(response) })