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
ba2cdcc3
authored
Nov 19, 2024
by
芋道源码
Committed by
Gitee
Nov 19, 2024
Browse files
Options
Browse Files
Download
Plain Diff
!587 【修复】修复对 axios 的处理
Merge pull request !587 from 半栈幼儿员/hoxfix/axios
parents
1c23298d
c119e910
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
8 additions
and
36 deletions
+8
-36
src/api/login/oauth2/index.ts
+1
-1
src/config/axios/index.ts
+4
-8
src/config/axios/service.ts
+3
-27
No files found.
src/api/login/oauth2/index.ts
View file @
ba2cdcc3
...
@@ -27,7 +27,7 @@ export const authorize = (
...
@@ -27,7 +27,7 @@ export const authorize = (
return
request
.
post
({
return
request
.
post
({
url
:
'/system/oauth2/authorize'
,
url
:
'/system/oauth2/authorize'
,
headers
:
{
headers
:
{
'Content-
t
ype'
:
'application/x-www-form-urlencoded'
'Content-
T
ype'
:
'application/x-www-form-urlencoded'
},
},
params
:
{
params
:
{
response_type
:
responseType
,
response_type
:
responseType
,
...
...
src/config/axios/index.ts
View file @
ba2cdcc3
...
@@ -5,16 +5,12 @@ import { config } from './config'
...
@@ -5,16 +5,12 @@ import { config } from './config'
const
{
default_headers
}
=
config
const
{
default_headers
}
=
config
const
request
=
(
option
:
any
)
=>
{
const
request
=
(
option
:
any
)
=>
{
const
{
url
,
method
,
params
,
data
,
headersType
,
responseType
,
...
config
}
=
option
const
{
headersType
,
headers
,
...
otherOption
}
=
option
return
service
({
return
service
({
url
:
url
,
...
otherOption
,
method
,
params
,
data
,
...
config
,
responseType
:
responseType
,
headers
:
{
headers
:
{
'Content-Type'
:
headersType
||
default_headers
'Content-Type'
:
headersType
||
default_headers
,
...
headers
}
}
})
})
}
}
...
...
src/config/axios/service.ts
View file @
ba2cdcc3
import
axios
,
{
import
axios
,
{
AxiosError
,
AxiosInstance
,
AxiosResponse
,
InternalAxiosRequestConfig
}
from
'axios'
AxiosError
,
AxiosInstance
,
AxiosRequestHeaders
,
AxiosResponse
,
InternalAxiosRequestConfig
}
from
'axios'
import
{
ElMessage
,
ElMessageBox
,
ElNotification
}
from
'element-plus'
import
{
ElMessage
,
ElMessageBox
,
ElNotification
}
from
'element-plus'
import
qs
from
'qs'
import
{
config
}
from
'@/config/axios/config'
import
{
config
}
from
'@/config/axios/config'
import
{
getAccessToken
,
getRefreshToken
,
getTenantId
,
removeToken
,
setToken
}
from
'@/utils/auth'
import
{
getAccessToken
,
getRefreshToken
,
getTenantId
,
removeToken
,
setToken
}
from
'@/utils/auth'
import
errorCode
from
'./errorCode'
import
errorCode
from
'./errorCode'
...
@@ -52,29 +45,12 @@ service.interceptors.request.use(
...
@@ -52,29 +45,12 @@ service.interceptors.request.use(
}
}
})
})
if
(
getAccessToken
()
&&
!
isToken
)
{
if
(
getAccessToken
()
&&
!
isToken
)
{
;(
config
as
Recordable
)
.
headers
.
Authorization
=
'Bearer '
+
getAccessToken
()
// 让每个请求携带自定义token
config
.
headers
.
Authorization
=
'Bearer '
+
getAccessToken
()
// 让每个请求携带自定义token
}
}
// 设置租户
// 设置租户
if
(
tenantEnable
&&
tenantEnable
===
'true'
)
{
if
(
tenantEnable
&&
tenantEnable
===
'true'
)
{
const
tenantId
=
getTenantId
()
const
tenantId
=
getTenantId
()
if
(
tenantId
)
(
config
as
Recordable
).
headers
[
'tenant-id'
]
=
tenantId
if
(
tenantId
)
config
.
headers
[
'tenant-id'
]
=
tenantId
}
const
params
=
config
.
params
||
{}
const
data
=
config
.
data
||
false
if
(
config
.
method
?.
toUpperCase
()
===
'POST'
&&
(
config
.
headers
as
AxiosRequestHeaders
)[
'Content-Type'
]
===
'application/x-www-form-urlencoded'
)
{
config
.
data
=
qs
.
stringify
(
data
)
}
// get参数编码
if
(
config
.
method
?.
toUpperCase
()
===
'GET'
&&
params
)
{
config
.
params
=
{}
const
paramsStr
=
qs
.
stringify
(
params
,
{
allowDots
:
true
})
if
(
paramsStr
)
{
config
.
url
=
config
.
url
+
'?'
+
paramsStr
}
}
}
return
config
return
config
},
},
...
...
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