fix: 商品详情页未登录时不触发登录跳转
- request.ts: 增加 silent 选项支持静默请求 - request.ts: 公开接口 401 不显示消息也不跳转 - ProductDetail.vue: fetchUserCredits 先检查 token,未登录直接跳过请求
This commit is contained in:
@@ -93,10 +93,16 @@ function hasEnoughCredit(): boolean {
|
||||
|
||||
// 获取用户资格信息
|
||||
async function fetchUserCredits() {
|
||||
// 未登录时静默跳过,不发起请求
|
||||
const token = localStorage.getItem('token')
|
||||
if (!token) return
|
||||
|
||||
try {
|
||||
const res: any = await userApi.getProfile()
|
||||
userCredits.value = res.data?.purchase_credits || 0
|
||||
} catch {}
|
||||
} catch {
|
||||
// 静默处理错误
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
|
||||
Reference in New Issue
Block a user