Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
dcxy-system
Project
Overview
Details
Activity
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
姜雷
dcxy-system
Commits
08a0d137
Commit
08a0d137
authored
Apr 29, 2019
by
姜雷
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改基础请求过滤文件类型接口结果
parent
c3565225
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
3 additions
and
90 deletions
+3
-90
baseFetch.js
src/api/baseFetch.js
+0
-89
Api.js
src/lib/Api.js
+3
-1
No files found.
src/api/baseFetch.js
deleted
100644 → 0
View file @
c3565225
import
axios
from
'axios'
;
import
{
Message
,
MessageBox
}
from
'element-ui'
;
import
store
from
'@/store'
;
import
{
errorHandle
}
from
'./validate'
;
const
createBaseFetch
=
config
=>
{
const
service
=
axios
.
create
({
timeout
:
10000
,
...
config
,
});
let
logout
=
false
;
// request拦截器
service
.
interceptors
.
request
.
use
(
conf
=>
{
const
{
notLoading
}
=
conf
;
store
.
dispatch
(
'fetchStart'
,
notLoading
);
conf
.
headers
=
{
...
conf
.
headers
,
reqSource
:
'pc'
,
token
:
store
.
getters
.
token
?
store
.
getters
.
token
:
''
,
};
return
conf
;
},
error
=>
{
// Do something with request error
console
.
error
(
error
);
// for debug
Promise
.
reject
(
error
);
}
);
// respone拦截器
service
.
interceptors
.
response
.
use
(
response
=>
{
const
res
=
response
.
data
;
/**
* code为非 1000 是抛错
*/
setTimeout
(()
=>
{
const
{
notLoading
}
=
response
.
config
;
store
.
dispatch
(
'fetchDone'
,
notLoading
);
},
500
);
if
(
res
.
code
!==
1000
)
{
if
(
response
.
headers
&&
/application
\/
octet-stream/
.
test
(
response
.
headers
[
'content-type'
].
toLowerCase
()
)
)
{
return
response
;
}
Message
({
message
:
res
.
msg
||
'网络错误!'
,
type
:
'error'
,
duration
:
5
*
1000
,
});
// -2:其他客户端登录了;Token 过期了;
if
(
res
.
code
===
-
2
)
{
if
(
logout
)
return
;
logout
=
true
;
MessageBox
.
confirm
(
'你已被登出,可以取消继续留在该页面,或者重新登录'
,
'确定登出'
,
{
confirmButtonText
:
'重新登录'
,
cancelButtonText
:
'取消'
,
type
:
'warning'
,
}
)
.
then
(()
=>
{
store
.
dispatch
(
'FedLogOut'
).
then
(()
=>
{
location
.
reload
();
// 为了重新实例化vue-router对象 避免bug
});
})
.
catch
(
err
=>
{
console
.
error
(
err
);
logout
=
false
;
});
}
return
Promise
.
reject
(
response
.
data
);
}
else
{
return
response
.
data
;
}
},
errorHandle
);
return
service
;
};
export
default
createBaseFetch
;
src/lib/Api.js
View file @
08a0d137
...
...
@@ -57,7 +57,9 @@ const createBaseFetch = config => {
if
(
res
.
code
!==
SUCCESS_CODE
)
{
if
(
response
.
headers
&&
response
.
headers
[
'content-type'
]
===
'application/octet-stream'
/application
\/
octet-stream/
.
test
(
response
.
headers
[
'content-type'
].
toLowerCase
()
)
)
{
return
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