From 38ae671ea9b700678983cc30c3617cbb298711c2 Mon Sep 17 00:00:00 2001 From: Apcallover <1503963513@qq.com> Date: Fri, 28 Nov 2025 19:14:42 +0800 Subject: [PATCH] =?UTF-8?q?flat:=E6=9A=82=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app.tsx | 14 +++++++------- src/requestErrorConfig.ts | 5 +++++ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/app.tsx b/src/app.tsx index f793938..81a51e9 100644 --- a/src/app.tsx +++ b/src/app.tsx @@ -231,6 +231,13 @@ export const request = { const authHeader = headers['Authorization']; const isToken = headers['isToken']; + // 处理开发环境API路径 + if (process.env.NODE_ENV !== 'development') { + if (url.startsWith('/api')) { + url = url.replace(/^\/api/, ''); + } + } + // 处理认证token if (!authHeader && isToken !== false) { const expireTime = getTokenExpireTime(); @@ -295,13 +302,6 @@ export const request = { }; } - // 处理开发环境API路径 - if (process.env.NODE_ENV !== 'development') { - if (url.startsWith('/api')) { - url = url.replace(/^\/api/, ''); - } - } - return { url, options: { ...options, headers } }; }, ], diff --git a/src/requestErrorConfig.ts b/src/requestErrorConfig.ts index 04a6ccf..5dd000b 100644 --- a/src/requestErrorConfig.ts +++ b/src/requestErrorConfig.ts @@ -88,6 +88,11 @@ export const errorConfig: RequestConfig = { // 请求拦截器 requestInterceptors: [ + /** + * 拦截并修改请求配置,添加token参数 + * @param {RequestOptions} config - 原始请求配置对象 + * @returns {RequestOptions} 修改后的请求配置对象,包含添加的token参数 + */ (config: RequestOptions) => { // 拦截请求配置,进行个性化处理。 const url = config?.url?.concat('?token = 123');