This commit is contained in:
weiwei committed 2025-02-25 09:47:16 +08:00
1 parent 5a7a66bd9f
commit 91ecc48fdd
1 file changed
+49 -1
+49 -1
View File
@@ -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
},
)