Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Fedex
/
imac-vue
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
Elements-SY
2023-09-06 18:00:31 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
81681bf2d47b6736cf718dfccc10a34a11b27fbb
81681bf2
1 parent
3929145d
modify
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
6 deletions
src/utils/request.js
src/utils/request.js
View file @
81681bf
...
...
@@ -9,17 +9,18 @@ axios.defaults.headers["Content-Type"] = "application/json;charset=utf-8";
// 创建axios实例
const
service
=
axios
.
create
({
// axios中请求配置有baseURL选项,表示请求URL公共部分
baseURL
:
settings
.
baseURL
,
//接口地址
baseURL
:
settings
.
baseURL
,
// 超时
timeout
:
3
0000
,
timeout
:
9
0000
,
});
// request拦截器
service
.
interceptors
.
request
.
use
(
(
config
)
=>
{
// 是否需要设置 token
const
isToken
=
(
config
.
headers
||
{}).
isToken
===
false
;
if
(
getToken
()
&&
!
isToken
)
{
config
.
headers
[
"Authorization"
]
=
getToken
(
);
// 让每个请求携带自定义token 请根据实际情况自行修改
config
.
headers
[
"Authorization"
]
=
decodeURIComponent
(
getToken
()
);
// 让每个请求携带自定义token 请根据实际情况自行修改
}
// get请求映射params参数
if
(
config
.
method
===
"get"
&&
config
.
params
)
{
...
...
@@ -55,21 +56,22 @@ service.interceptors.request.use(
service
.
interceptors
.
response
.
use
(
(
res
)
=>
{
if
(
res
.
headers
[
"token"
])
{
setToken
(
decodeURI
(
res
.
headers
[
"token"
])
);
setToken
(
res
.
headers
[
"token"
]
);
}
// 未设置状态码则默认成功状态
const
code
=
res
.
data
.
code
||
200
;
// 获取错误信息
const
msg
=
errorCode
[
code
]
||
res
.
data
.
msg
||
errorCode
[
"default"
];
if
(
code
===
301
)
{
MessageBox
.
confirm
(
"登录状态已过期,需重新登录
"
,
"系统提示"
,
{
MessageBox
.
confirm
(
"登录状态已过期,需重新登录
!msg:"
+
msg
,
"系统提示"
,
{
closeOnClickModal
:
false
,
showCancelButton
:
false
,
confirmButtonText
:
"重新登录"
,
type
:
"warning"
,
}).
then
(()
=>
{
store
.
dispatch
(
"LogOut"
).
then
(()
=>
{
location
.
href
=
settings
.
routerBase
+
"/index"
;
// location.href = '/';
window
.
location
.
href
=
settings
.
loginURL
;
//wsso系统跳转
});
});
}
else
if
(
code
===
403
)
{
...
...
Please
register
or
login
to post a comment