Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
sys-sdk
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Jira
Jira
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ui
sys-sdk
Commits
4e3ba6a0
Commit
4e3ba6a0
authored
Sep 21, 2020
by
郝聪敏
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 优化cancel请求;添加loading控制header
parent
78245314
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
8 deletions
+12
-8
http.js
lib/http.js
+11
-7
package.json
package.json
+1
-1
No files found.
lib/http.js
View file @
4e3ba6a0
...
...
@@ -51,7 +51,8 @@ const refreshRequest = async options => {
return
promise
;
};
function
beforeRequest
(
model
)
{
function
beforeRequest
(
model
,
isLoading
=
true
)
{
if
(
!
isLoading
)
return
;
if
(
!
model
)
model
=
'
common
'
;
httpQueue
.
push
(
model
);
loadingTimeOut
=
setTimeout
(()
=>
{
...
...
@@ -63,7 +64,8 @@ function beforeRequest(model) {
Bus
.
$emit
(
`
${
model
}
HideLoading`
);
},
30
*
60
*
1000
);
}
function
afterRequest
(
model
)
{
function
afterRequest
(
model
,
isLoading
=
true
)
{
if
(
!
isLoading
)
return
;
if
(
!
model
)
model
=
'
common
'
;
clearTimeout
(
loadingTimeOut
);
var
index
=
httpQueue
.
indexOf
(
model
);
...
...
@@ -87,7 +89,7 @@ function clearRequest() {
// http request 拦截器
instance
.
interceptors
.
request
.
use
(
config
=>
{
beforeRequest
(
config
.
headers
.
_loading
);
beforeRequest
(
config
.
headers
.
_loading
,
config
.
headers
.
_isLoading
);
const
token
=
localStorage
.
get
(
'
token
'
);
const
user
=
localStorage
.
get
(
'
user
'
);
if
(
user
)
{
...
...
@@ -133,7 +135,7 @@ instance.interceptors.request.use(
instance
.
interceptors
.
response
.
use
(
response
=>
{
afterRequest
(
response
.
config
.
headers
.
_loading
);
afterRequest
(
response
.
config
.
headers
.
_loading
,
response
.
config
.
headers
.
_isLoading
);
if
(
response
.
headers
[
'
content-type
'
]
===
'
application/octet-stream
'
||
(
response
.
headers
[
'
content-type
'
]
===
'
application/vnd.ms-excel;charset=UTF-8
'
&&
response
.
data
.
byteLength
!==
'
undefied
'
))
{
return
response
.
data
;
}
...
...
@@ -179,11 +181,9 @@ instance.interceptors.response.use(
return
Promise
.
reject
(
response
.
data
);
},
error
=>
{
instance
.
_extend
.
notice
.
error
({
title
:
'
后端服务异常
'
,
});
if
(
axios
.
isCancel
(
error
)
||
error
.
message
.
indexOf
(
'
Network
'
)
>
-
1
)
{
clearRequest
();
return
Promise
.
reject
(
error
);
}
else
{
afterRequest
(
error
.
response
&&
error
.
response
.
config
.
headers
.
_loading
);
if
(
error
.
response
)
{
...
...
@@ -197,6 +197,10 @@ instance.interceptors.response.use(
}
}
}
instance
.
_extend
.
notice
.
error
({
title
:
error
.
message
||
'
后端服务异常
'
,
});
return
Promise
.
reject
(
error
);
}
);
...
...
package.json
View file @
4e3ba6a0
{
"name"
:
"@qg/sys-sdk"
,
"version"
:
"1.0.1
1
"
,
"version"
:
"1.0.1
4
"
,
"description"
:
""
,
"main"
:
"index.js"
,
"scripts"
:
{
...
...
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