Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录
切换导航
S
shop-new
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
王天霸
shop-new
Commits
6a1747fb
提交
6a1747fb
authored
6月 30, 2021
作者:
huaxinzhu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
拦截优化
上级
a3d0f82c
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
17 行增加
和
36 行删除
+17
-36
request.js
src/utils/request.js
+17
-36
没有找到文件。
src/utils/request.js
浏览文件 @
6a1747fb
...
...
@@ -19,7 +19,7 @@ service.interceptors.request.use(config => {
if
(
getToken
()
&&
!
isToken
)
{
config
.
headers
[
'Authorization'
]
=
'Bearer '
+
getToken
()
// 让每个请求携带自定义token 请根据实际情况自行修改
}
//config.hea
ders['Authorization'] = 'Bearer ' + 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJsb2dpbk5hbWUiOiIxNTcxMTEzOTg5NSIsInVpZCI6NTI4MjgsImN
oYW5uZWxJZCI6MCwiZXhwIjoxNjE5ODMzMzk3LCJpc3MiOiJnaW4tYmxvZyJ9.rh-WXSaFqgqY611Tm5dhba532OYEZvm06vUmgZknoy4'
//config.heaoYW5uZWxJZCI6MCwiZXhwIjoxNjE5ODMzMzk3LCJpc3MiOiJnaW4tYmxvZyJ9.rh-WXSaFqgqY611Tm5dhba532OYEZvm06vUmgZknoy4'
return
config
},
error
=>
{
console
.
log
(
"25reject"
);
...
...
@@ -28,33 +28,28 @@ service.interceptors.request.use(config => {
// 响应拦截器
service
.
interceptors
.
response
.
use
(
res
=>
{
// 未设置状态码则默认成功状态
const
code
=
res
.
data
.
code
||
200
;
// debugger
let
code
=
res
.
data
.
code
if
(
res
.
data
.
code
!==
0
)
{
code
=
res
.
data
.
code
||
200
;
}
else
{
code
=
0
;
}
// 返回所有数据的统一处理
const
data
=
res
.
data
;
// 获取错误信息
const
message
=
errorCode
[
code
]
||
res
.
data
.
msg
||
errorCode
[
'default'
];
// 200,1意味着成功返回数据
if
(
code
===
200
||
code
===
1
)
{
if
(
res
.
data
)
{
return
res
.
data
}
else
{
if
(
message
)
{
Message
({
message
:
message
,
type
:
'error'
});
}
else
{
Message
({
message
:
'后台数据出错啦!'
,
type
:
'error'
});
}
return
Promise
.
reject
(
'error'
);
}
}
else
if
(
code
===
500
)
{
const
message
=
errorCode
[
code
]
||
res
.
data
.
message
||
errorCode
[
'default'
];
if
(
code
===
1
||
code
===
200
)
{
return
res
.
data
}
else
if
(
code
===
500
||
code
===
0
)
{
Message
({
message
:
message
,
type
:
'error'
})
return
Promise
.
reject
(
new
Error
(
message
));
}
else
if
(
code
===
401
||
code
==
99999
)
{
}
else
if
(
code
===
401
||
code
==
99999
)
{
MessageBox
.
confirm
(
'登录状态已过期,您可以继续留在该页面,或者重新登录'
,
'系统提示'
,
{
confirmButtonText
:
'重新登录'
,
cancelButtonText
:
'取消'
,
...
...
@@ -64,30 +59,21 @@ service.interceptors.response.use(res => {
location
.
reload
()
// 为了重新实例化vue-router对象 避免bug
})
})
}
else
if
(
code
===
500
)
{
Message
({
message
:
message
,
type
:
'error'
})
return
Promise
.
reject
(
new
Error
(
message
))
}
else
if
(
code
!==
200
&&
code
!==
1
)
{
}
else
{
Notification
.
error
({
title
:
message
})
return
Promise
.
reject
(
'error'
)
store
.
dispatch
(
'LogOut'
).
then
(()
=>
{
var
ssa
=
window
.
location
.
host
;
// setTimeout(function (){
if
(
ssa
==
'localhost:1024'
)
{
window
.
location
.
href
=
'http://sso.jxhh.com/logout?redirect=http://'
+
ssa
}
else
{
window
.
location
.
href
=
'http://sso.jxhh.com/logout?redirect=http://'
+
ssa
}
// }, 1000)
// location.reload() // 为了重新实例化vue-router对象 避免bug
})
}
else
if
(
code
===
200
||
code
===
1
)
{
return
res
.
data
}
},
error
=>
{
// --- start ---- 开发时候用这段,把错误彻底抛出来 --- start ---
...
...
@@ -103,11 +89,8 @@ service.interceptors.response.use(res => {
message
:
message
,
type
:
"error"
});
// console.log(message);
// --- end ---- 开发时候用这段,把错误彻底抛出来 --- end ---
// --- start --- 正式上线,隐藏报错信息 ----- start ----
// let ssa = window.location.host;
// setTimeout(function () {
// if (ssa == 'localhost:1024') {
...
...
@@ -116,9 +99,7 @@ service.interceptors.response.use(res => {
// window.location.href = 'http://sso.jxhh.com/logout?redirect=http://' + ssa
// }
// }, 1000);
// --- end --- 正式上线,隐藏报错信息 ----- end ----
return
Promise
.
reject
(
error
)
}
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论