This commit is contained in:
2026-03-23 09:46:34 +08:00
parent 1134e64415
commit e7704df90e
4 changed files with 22 additions and 11 deletions
-2
View File
@@ -2,8 +2,6 @@ import { api } from '@/utils/request'
import type { PaginatedData, OrderItemFilters } from '@/types/api'
import type { OrderItemRecord } from '@/stores/order'
export type { OrderItemRecord }
/** 名称映射用的查找表 */
interface LookupItem {
id: number
+7 -1
View File
@@ -13,7 +13,10 @@ interface RequestOptions extends RequestInit {
timeout?: number
}
const API_BASE_URL = import.meta.env.VITE_API_BASE_URL || ''
async function request<T = unknown>(url: string, options: RequestOptions = {}): Promise<T> {
url = `${API_BASE_URL}${url}`
const token = tokenGetter?.() ?? localStorage.getItem('access_token')
const headers: Record<string, string> = {
@@ -50,8 +53,10 @@ async function request<T = unknown>(url: string, options: RequestOptions = {}):
signal: controller.signal,
})
// 401 未授权:保留当前路径作为 redirect 参数
// 401 未授权:跳过登录/注册接口(由页面自行处理错误提示),其余接口重定向到登录页
if (response.status === 401) {
const isAuthEndpoint = /\/api\/v1\/(login|register)$/.test(url)
if (!isAuthEndpoint) {
localStorage.removeItem('access_token')
localStorage.removeItem('refresh_token')
localStorage.removeItem('user')
@@ -59,6 +64,7 @@ async function request<T = unknown>(url: string, options: RequestOptions = {}):
window.location.pathname + window.location.search,
)
window.location.href = `/login?redirect=${redirect}`
}
throw new ApiError('登录已过期,请重新登录', 401)
}
+8
View File
@@ -64,4 +64,12 @@ export default defineConfig({
'@': fileURLToPath(new URL('./src', import.meta.url))
},
},
server: {
proxy: {
'/api': {
target: 'http://127.0.0.1:9501',
changeOrigin: true,
},
},
},
})
@@ -1 +0,0 @@
{"version":"4.1.0","results":[[":frontend/src/pages/failed-messages/__tests__/index.spec.ts",{"duration":0,"failed":true}]]}