From d3dc775bd314d8c23bba43f9e9de80e767cb32c9 Mon Sep 17 00:00:00 2001 From: XingQue Date: Mon, 6 Jul 2026 19:35:24 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=AE=A2=E5=8D=95=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E8=AF=B7=E6=B1=82=E5=8E=BB=E6=8E=89=20phone=EF=BC=8C=E5=8C=BA?= =?UTF-8?q?=E5=88=86=20JWT=20401=20=E4=B8=8E=E4=B8=9A=E5=8A=A1=E9=94=99?= =?UTF-8?q?=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit kfhqptddlx 只带 JWT;响应拦截器仅在 token 失效时清登录态。 Co-authored-by: Cursor --- src/utils/request.js | 16 +++++++++++++--- src/views/cross-platform/Order.vue | 3 +-- src/views/order/MerchantOrder.vue | 4 +--- src/views/order/PlatformOrder.vue | 4 +--- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/utils/request.js b/src/utils/request.js index 099299d..bc8e3e5 100644 --- a/src/utils/request.js +++ b/src/utils/request.js @@ -35,9 +35,19 @@ service.interceptors.response.use( if (error.response) { const status = error.response.status if (status === 401) { - localStorage.removeItem('token') - router.push('/login') - ElMessage.error('登录已过期,请重新登录') + const data = error.response.data + const isJwtAuthFailure = + !data || + data.detail !== undefined || + data.code === 'token_not_valid' || + data.code === 'authentication_failed' + if (isJwtAuthFailure && !error.config?.skipAuthRedirect) { + localStorage.removeItem('token') + router.push('/login') + ElMessage.error('登录已过期,请重新登录') + } else if (!error.config?.skipErrorToast) { + ElMessage.error(data?.msg || '认证失败') + } } else if (status === 403) { if (!error.config?.skipErrorToast) { ElMessage.error('没有权限') diff --git a/src/views/cross-platform/Order.vue b/src/views/cross-platform/Order.vue index bf61667..193d155 100644 --- a/src/views/cross-platform/Order.vue +++ b/src/views/cross-platform/Order.vue @@ -282,8 +282,7 @@ const fetchClubs = async () => { // ---------- 2. 获取订单类型 ---------- const fetchOrderTypes = async () => { try { - const username = localStorage.getItem('username') - const res = await request.post('/yonghu/kfhqptddlx', { phone: username }) + const res = await request.post('/yonghu/kfhqptddlx', {}, { skipErrorToast: true }) if (res.code === 0) { orderTypes.value = res.data || [] // 默认选中全部(空字符串) diff --git a/src/views/order/MerchantOrder.vue b/src/views/order/MerchantOrder.vue index fa90d7f..e765708 100644 --- a/src/views/order/MerchantOrder.vue +++ b/src/views/order/MerchantOrder.vue @@ -203,9 +203,7 @@ const getFullImageUrl = (relativeUrl) => { // 订单类型接口(未改动) const fetchOrderTypes = async () => { try { - const res = await request.post('/yonghu/kfhqptddlx', { - phone: localStorage.getItem('username') - }) + const res = await request.post('/yonghu/kfhqptddlx', {}, { skipErrorToast: true }) if (res.code === 0) { orderTypes.value = res.data || [] if (!currentType.value) currentType.value = '' diff --git a/src/views/order/PlatformOrder.vue b/src/views/order/PlatformOrder.vue index 04a2232..41dc334 100644 --- a/src/views/order/PlatformOrder.vue +++ b/src/views/order/PlatformOrder.vue @@ -207,9 +207,7 @@ const getFullImageUrl = (relativeUrl) => { // 获取订单类型(未改动,仍用 phone) const fetchOrderTypes = async () => { try { - const res = await request.post('/yonghu/kfhqptddlx', { - phone: localStorage.getItem('username') - }) + const res = await request.post('/yonghu/kfhqptddlx', {}, { skipErrorToast: true }) if (res.code === 0) { orderTypes.value = res.data || [] if (!currentType.value) currentType.value = ''