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 }, )