Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
confucius
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
罗超
confucius
Commits
cf6de52e
Commit
cf6de52e
authored
Oct 24, 2020
by
黄奎
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
页面修改
parent
b7b238e1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
77 additions
and
72 deletions
+77
-72
request.js
src/utils/request.js
+77
-72
No files found.
src/utils/request.js
View file @
cf6de52e
import
axios
from
"axios"
;
import
{
removeAuth
}
from
"../utils/auth"
;
import
{
removeAuth
}
from
"../utils/auth"
;
import
qs
from
"qs"
;
import
{
Dialog
,
Notify
}
from
'quasar'
import
{
Dialog
,
Notify
}
from
'quasar'
var
showLoginMessageBox
=
false
;
axios
.
defaults
.
headers
[
"Content-Type"
]
=
"application/json;charset=UTF-8"
;
//application/x-www-form-urlencoded;charset=UTF-8
const
service
=
axios
.
create
({
baseURL
:
process
.
env
.
API
,
timeout
:
15000
baseURL
:
process
.
env
.
API
,
timeout
:
15000
});
// request拦截器
service
.
interceptors
.
request
.
use
(
config
=>
{
const
flag
=
config
.
headers
[
"Content-Type"
]
&&
config
.
headers
[
"Content-Type"
].
indexOf
(
"application/json"
)
!==
-
1
;
if
(
!
flag
)
{
const
mult
=
config
.
headers
[
"Content-Type"
]
&&
config
.
headers
[
"Content-Type"
].
indexOf
(
"multipart/form-data"
)
!==
-
1
;
if
(
mult
)
{
config
.
data
=
config
.
data
;
}
else
{
config
.
data
=
qs
.
stringify
(
config
.
data
);
}
}
else
{
config
.
data
=
{
"Msg"
:
config
.
data
}
}
return
config
;
},
error
=>
{
//TODO 新增网络请求异常处理业务
return
Promise
.
reject
(
error
);
config
=>
{
const
flag
=
config
.
headers
[
"Content-Type"
]
&&
config
.
headers
[
"Content-Type"
].
indexOf
(
"application/json"
)
!==
-
1
;
if
(
!
flag
)
{
const
mult
=
config
.
headers
[
"Content-Type"
]
&&
config
.
headers
[
"Content-Type"
].
indexOf
(
"multipart/form-data"
)
!==
-
1
;
if
(
mult
)
{
config
.
data
=
config
.
data
;
}
else
{
config
.
data
=
qs
.
stringify
(
config
.
data
);
}
}
else
{
config
.
data
=
{
"Msg"
:
config
.
data
}
}
return
config
;
},
error
=>
{
//TODO 新增网络请求异常处理业务
return
Promise
.
reject
(
error
);
}
);
// response 拦截器
service
.
interceptors
.
response
.
use
(
response
=>
{
const
res
=
response
.
data
;
// TODO 确定后台的CODE码
if
(
response
.
status
===
200
&&
response
.
config
.
responseType
===
"blob"
)
{
// 文件类型特殊处理
return
response
;
}
else
if
(
res
.
Code
!=
1
)
{
// TODO 确定后台的CODE码
if
(
res
.
Code
==
302
)
{
if
(
!
showLoginMessageBox
)
{
showLoginMessageBox
=
true
;
Dialog
.
create
({
title
:
"登出"
,
message
:
"抱歉,你的账户信息已失效,你需要重新登录使用"
,
persistent
:
true
}).
onOk
(()
=>
{
removeAuth
()
.
then
(()
=>
{
location
.
reload
();
// 为了重新实例化vue-router对象 避免bug
})
.
catch
(()
=>
{
location
.
reload
();
});
});
}
}
else
{
if
(
res
.
Message
)
{
Notify
.
create
({
icon
:
"error"
,
color
:
"negative"
,
message
:
res
.
Message
,
position
:
"top"
});
}
}
return
Promise
.
reject
(
res
);
}
else
{
return
res
;
response
=>
{
const
res
=
response
.
data
;
// TODO 确定后台的CODE码
if
(
response
.
status
===
200
&&
response
.
config
.
responseType
===
"blob"
)
{
// 文件类型特殊处理
return
response
;
}
else
if
(
res
.
Code
!=
1
)
{
// TODO 确定后台的CODE码
if
(
res
.
Code
==
10000
)
{
if
(
!
showLoginMessageBox
)
{
showLoginMessageBox
=
true
;
Dialog
.
create
({
title
:
"登出"
,
message
:
"抱歉,你的账户信息已失效,你需要重新登录使用"
,
persistent
:
true
}).
onOk
(()
=>
{
removeAuth
()
.
then
(()
=>
{
location
.
reload
();
// 为了重新实例化vue-router对象 避免bug
})
.
catch
(()
=>
{
location
.
reload
();
});
});
}
},
error
=>
{
Notify
.
create
({
}
else
{
if
(
res
.
Message
)
{
Notify
.
create
({
icon
:
"error"
,
color
:
"negative"
,
message
:
"网络请求失败,请稍候再试"
,
message
:
res
.
Message
,
position
:
"top"
});
return
Promise
.
reject
(
error
);
});
}
}
return
Promise
.
reject
(
res
);
}
else
{
return
res
;
}
},
error
=>
{
Notify
.
create
({
icon
:
"error"
,
color
:
"negative"
,
message
:
"网络请求失败,请稍候再试"
,
position
:
"top"
});
return
Promise
.
reject
(
error
);
}
);
export
default
service
;
\ No newline at end of file
export
default
service
;
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