From c99cf5e53f057cdc332ab6c0635adf9c2d27de29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=97=A0=E6=9C=A8?= Date: Tue, 29 Jun 2021 17:31:30 +0800 Subject: [PATCH] feat(axios): add `withToken` option MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加withToken配置,用于控制request是否提交token --- CHANGELOG.zh_CN.md | 6 ++++++ src/utils/http/axios/index.ts | 4 +++- types/axios.d.ts | 2 ++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.zh_CN.md b/CHANGELOG.zh_CN.md index ebaa298f5..386c1a1e0 100644 --- a/CHANGELOG.zh_CN.md +++ b/CHANGELOG.zh_CN.md @@ -1,3 +1,7 @@ +### ✨ Features + +- **Axios** 新增`withToken`配置,用于控制请求是否携带 token + ### 🐛 Bug Fixes - **Modal** 修复点击遮罩不能关闭 @@ -5,6 +9,8 @@ - **Modal** 修复 `setModalProps` 不支持设置 `defaultFullscreen` - **Sider** 修复侧边菜单底部的折叠按钮点击无效 - **SvgIcon** 修复图标样式问题 +- **Table** 修复为 table 提供 rowSelection.onChange 时,无法手动变更 table 的选中项的问题 +- **Icon** 修复 SvgIcon 缺少部分样式的问题 ## 2.5.2(2021-06-27) diff --git a/src/utils/http/axios/index.ts b/src/utils/http/axios/index.ts index ac52c33e3..dd2587e29 100644 --- a/src/utils/http/axios/index.ts +++ b/src/utils/http/axios/index.ts @@ -122,7 +122,7 @@ const transform: AxiosTransform = { requestInterceptors: (config, options) => { // 请求之前处理config const token = getToken(); - if (token) { + if (token && options?.requestOptions?.withToken !== false) { // jwt token config.headers.Authorization = options.authenticationScheme ? `${options.authenticationScheme} ${token}` @@ -214,6 +214,8 @@ function createAxios(opt?: Partial) { joinTime: true, // 忽略重复请求 ignoreCancelToken: true, + // 是否携带token + withToken: true, }, }, opt || {} diff --git a/types/axios.d.ts b/types/axios.d.ts index aebbc9fed..e325b65b0 100644 --- a/types/axios.d.ts +++ b/types/axios.d.ts @@ -19,6 +19,8 @@ export interface RequestOptions { // Whether to add a timestamp joinTime?: boolean; ignoreCancelToken?: boolean; + // Whether to send token in header + withToken?: boolean; } export interface Result {