Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
bdc
/
bdcsjsb-web
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
50d4471c
authored
2023-06-26 09:24:06 +0800
by
yangwei
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
token修改
1 parent
640a4a57
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
17 deletions
src/utils/request.js
src/utils/request.js
View file @
50d4471
/*
* @Description: 此文件主要创建 axios 实例,然后添加请求拦截器和响应拦截器
* @Autor: renchao
* @LastEditTime: 2023-06-
08 09:02:53
* @LastEditTime: 2023-06-
26 09:24:00
*/
import
Vue
from
'vue'
import
axios
from
'axios'
import
Router
from
'@/router'
import
Cookies
from
'js-cookie'
import
{
Message
}
from
'element-ui'
import
{
endLoadingSubCount
}
from
'./requestLoading'
import
{
getToken
,
setToken
}
from
"@/utils/util"
;
// create an axios instance
const
service
=
axios
.
create
({
...
...
@@ -27,15 +27,7 @@ const service = axios.create({
service
.
interceptors
.
request
.
use
(
config
=>
{
if
(
process
.
env
.
NODE_ENV
===
'development'
)
{
const
token
=
localStorage
.
getItem
(
'token'
)
// 添加请求头
if
(
token
)
{
config
.
headers
[
'Authorization'
]
=
'Bearer '
+
token
}
else
{
config
.
headers
.
delete
(
'Authorization'
)
}
}
else
{
const
token
=
Cookies
.
get
(
'token'
)
const
token
=
getToken
()
// 添加请求头
if
(
token
)
{
config
.
headers
[
'Authorization'
]
=
'Bearer '
+
token
...
...
@@ -75,12 +67,8 @@ service.interceptors.response.use(
window
.
__isNeedLogin
=
false
Message
.
error
(
'token失效,请重新登录'
);
let
locationUrl
=
window
.
location
.
protocol
+
'//'
+
window
.
location
.
host
+
window
.
location
.
pathname
;
if
(
process
.
env
.
NODE_ENV
===
'development'
)
{
localStorage
.
removeItem
(
'token'
)
}
else
{
Cookies
.
remove
(
'token'
)
}
setToken
(
undefined
)
sessionStorage
.
removeItem
(
'token'
)
if
(
window
.
_config
.
casEnable
)
{
window
.
location
.
href
=
window
.
_config
.
casBaseURL
+
'/logout?service='
+
encodeURIComponent
(
locationUrl
);
}
else
{
...
...
Please
register
or
sign in
to post a comment