Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
ems3.3
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wuhao
ems3.3
Commits
7fc08338
Commit
7fc08338
authored
Aug 30, 2023
by
左玲玲
😬
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1654
parent
394bf9ae
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
17 deletions
+19
-17
request.js
src/utils/request.js
+19
-17
No files found.
src/utils/request.js
View file @
7fc08338
...
...
@@ -6,7 +6,7 @@ import { extend } from 'umi-request';
import
{
message
,
notification
,
Modal
}
from
'antd'
;
import
{
history
}
from
'@umijs/max'
;
import
qs
from
'query-string'
;
const
{
NODE_ENV
}
=
process
.
env
;
//development production
const
codeMessage
=
{
200
:
'服务器成功返回请求的数据。'
,
201
:
'新建或修改数据成功。'
,
...
...
@@ -55,23 +55,25 @@ const request = extend({
// request拦截器, 改变url 或 options.
request
.
interceptors
.
request
.
use
(
async
(
url
,
options
)
=>
{
let
token
=
localStorage
.
getItem
(
'TOKENES'
);
if
(
token
)
{
const
headers
=
options
.
type
==
'form'
?
{
Authorization
:
'Bearer '
+
token
,
}
:
{
let
token
=
localStorage
.
getItem
(
'TOKENES'
)
??
""
,
headers
=
{};
if
(
NODE_ENV
==
"development"
&&
url
.
indexOf
(
"token"
)
==
-
1
&&
token
)
{
headers
=
options
.
type
==
'form'
?
{
Authorization
:
"Bearer "
+
token
}
:
{
'Content-Type'
:
'application/json'
,
Accept
:
'application/json'
,
Authorization
:
'Bearer '
+
token
,
};
Authorization
:
"Bearer "
+
token
}
}
else
{
headers
=
options
.
type
==
'form'
?
{}
:
{
'Content-Type'
:
'application/json'
,
Accept
:
'application/json'
}
}
return
{
url
:
url
,
options
:
{
...
options
,
headers
:
headers
,
useCache
:
true
,
ttl
:
2000
},
};
}
});
// response拦截器, 处理response
...
...
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