Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
admin
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Unverified
Commit
056684e2
authored
Nov 20, 2024
by
芋道源码
Committed by
Gitee
Nov 20, 2024
Browse files
Options
Browse Files
Download
Plain Diff
!588 【修复】恢复 axios 自定义参数序列化函数,并支持所有请求的 params 自定义序列化,修复刷新 token 后二次请求参数丢失问题。
Merge pull request !588 from 半栈幼儿员/hotfix/axios
parents
ba2cdcc3
6cd64291
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
1 deletions
+21
-1
src/config/axios/service.ts
+21
-1
No files found.
src/config/axios/service.ts
View file @
056684e2
import
axios
,
{
AxiosError
,
AxiosInstance
,
AxiosResponse
,
InternalAxiosRequestConfig
}
from
'axios'
import
{
ElMessage
,
ElMessageBox
,
ElNotification
}
from
'element-plus'
import
qs
from
'qs'
import
{
config
}
from
'@/config/axios/config'
import
{
getAccessToken
,
getRefreshToken
,
getTenantId
,
removeToken
,
setToken
}
from
'@/utils/auth'
import
errorCode
from
'./errorCode'
...
...
@@ -30,7 +31,11 @@ const whiteList: string[] = ['/login', '/refresh-token']
const
service
:
AxiosInstance
=
axios
.
create
({
baseURL
:
base_url
,
// api 的 base_url
timeout
:
request_timeout
,
// 请求超时时间
withCredentials
:
false
// 禁用 Cookie 等信息
withCredentials
:
false
,
// 禁用 Cookie 等信息
// 自定义参数序列化函数
paramsSerializer
:
(
params
)
=>
{
return
qs
.
stringify
(
params
,
{
allowDots
:
true
})
}
})
// request拦截器
...
...
@@ -52,6 +57,21 @@ service.interceptors.request.use(
const
tenantId
=
getTenantId
()
if
(
tenantId
)
config
.
headers
[
'tenant-id'
]
=
tenantId
}
const
method
=
config
.
method
?.
toUpperCase
()
// 防止 GET 请求缓存
if
(
method
===
'GET'
)
{
config
.
headers
[
'Cache-Control'
]
=
'no-cache'
config
.
headers
[
'Pragma'
]
=
'no-cache'
}
// 自定义参数序列化函数
else
if
(
method
===
'POST'
)
{
const
contentType
=
config
.
headers
[
'Content-Type'
]
||
config
.
headers
[
'content-type'
]
if
(
contentType
===
'application/x-www-form-urlencoded'
)
{
if
(
config
.
data
&&
typeof
config
.
data
!==
'string'
)
{
config
.
data
=
qs
.
stringify
(
config
.
data
)
}
}
}
return
config
},
(
error
:
AxiosError
)
=>
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment