Commit c99cf5e53f057cdc332ab6c0635adf9c2d27de29
1 parent
df0f0008
feat(axios): add `withToken` option
添加withToken配置,用于控制request是否提交token
Showing
3 changed files
with
11 additions
and
1 deletions
CHANGELOG.zh_CN.md
1 | +### ✨ Features | ||
2 | + | ||
3 | +- **Axios** 新增`withToken`配置,用于控制请求是否携带 token | ||
4 | + | ||
1 | ### 🐛 Bug Fixes | 5 | ### 🐛 Bug Fixes |
2 | 6 | ||
3 | - **Modal** 修复点击遮罩不能关闭 | 7 | - **Modal** 修复点击遮罩不能关闭 |
@@ -5,6 +9,8 @@ | @@ -5,6 +9,8 @@ | ||
5 | - **Modal** 修复 `setModalProps` 不支持设置 `defaultFullscreen` | 9 | - **Modal** 修复 `setModalProps` 不支持设置 `defaultFullscreen` |
6 | - **Sider** 修复侧边菜单底部的折叠按钮点击无效 | 10 | - **Sider** 修复侧边菜单底部的折叠按钮点击无效 |
7 | - **SvgIcon** 修复图标样式问题 | 11 | - **SvgIcon** 修复图标样式问题 |
12 | +- **Table** 修复为 table 提供 rowSelection.onChange 时,无法手动变更 table 的选中项的问题 | ||
13 | +- **Icon** 修复 SvgIcon 缺少部分样式的问题 | ||
8 | 14 | ||
9 | ## 2.5.2(2021-06-27) | 15 | ## 2.5.2(2021-06-27) |
10 | 16 |
src/utils/http/axios/index.ts
@@ -122,7 +122,7 @@ const transform: AxiosTransform = { | @@ -122,7 +122,7 @@ const transform: AxiosTransform = { | ||
122 | requestInterceptors: (config, options) => { | 122 | requestInterceptors: (config, options) => { |
123 | // 请求之前处理config | 123 | // 请求之前处理config |
124 | const token = getToken(); | 124 | const token = getToken(); |
125 | - if (token) { | 125 | + if (token && options?.requestOptions?.withToken !== false) { |
126 | // jwt token | 126 | // jwt token |
127 | config.headers.Authorization = options.authenticationScheme | 127 | config.headers.Authorization = options.authenticationScheme |
128 | ? `${options.authenticationScheme} ${token}` | 128 | ? `${options.authenticationScheme} ${token}` |
@@ -214,6 +214,8 @@ function createAxios(opt?: Partial<CreateAxiosOptions>) { | @@ -214,6 +214,8 @@ function createAxios(opt?: Partial<CreateAxiosOptions>) { | ||
214 | joinTime: true, | 214 | joinTime: true, |
215 | // 忽略重复请求 | 215 | // 忽略重复请求 |
216 | ignoreCancelToken: true, | 216 | ignoreCancelToken: true, |
217 | + // 是否携带token | ||
218 | + withToken: true, | ||
217 | }, | 219 | }, |
218 | }, | 220 | }, |
219 | opt || {} | 221 | opt || {} |
types/axios.d.ts
@@ -19,6 +19,8 @@ export interface RequestOptions { | @@ -19,6 +19,8 @@ export interface RequestOptions { | ||
19 | // Whether to add a timestamp | 19 | // Whether to add a timestamp |
20 | joinTime?: boolean; | 20 | joinTime?: boolean; |
21 | ignoreCancelToken?: boolean; | 21 | ignoreCancelToken?: boolean; |
22 | + // Whether to send token in header | ||
23 | + withToken?: boolean; | ||
22 | } | 24 | } |
23 | 25 | ||
24 | export interface Result<T = any> { | 26 | export interface Result<T = any> { |