Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
T
topology
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
姜立玮
topology
Commits
25b114aa
提交
25b114aa
authored
5月 18, 2020
作者:
RuoYi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
支持是否需要设置token属性,自定义返回码消息。
上级
5434ceb1
变更
3
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
28 行增加
和
12 行删除
+28
-12
errorCode.js
ruoyi-ui/src/utils/errorCode.js
+6
-0
request.js
ruoyi-ui/src/utils/request.js
+21
-12
BaseController.java
...va/com/ruoyi/framework/web/controller/BaseController.java
+1
-0
没有找到文件。
ruoyi-ui/src/utils/errorCode.js
0 → 100644
浏览文件 @
25b114aa
export
default
{
'401'
:
'认证失败,无法访问系统资源'
,
'403'
:
'当前操作没有权限'
,
'404'
:
'访问资源不存在'
,
'default'
:
'系统未知错误,请反馈给管理员'
}
ruoyi-ui/src/utils/request.js
浏览文件 @
25b114aa
...
@@ -2,6 +2,7 @@ import axios from 'axios'
...
@@ -2,6 +2,7 @@ import axios from 'axios'
import
{
Notification
,
MessageBox
,
Message
}
from
'element-ui'
import
{
Notification
,
MessageBox
,
Message
}
from
'element-ui'
import
store
from
'@/store'
import
store
from
'@/store'
import
{
getToken
}
from
'@/utils/auth'
import
{
getToken
}
from
'@/utils/auth'
import
errorCode
from
'@/utils/errorCode'
axios
.
defaults
.
headers
[
'Content-Type'
]
=
'application/json;charset=utf-8'
axios
.
defaults
.
headers
[
'Content-Type'
]
=
'application/json;charset=utf-8'
// 创建axios实例
// 创建axios实例
...
@@ -12,22 +13,24 @@ const service = axios.create({
...
@@ -12,22 +13,24 @@ const service = axios.create({
timeout
:
10000
timeout
:
10000
})
})
// request拦截器
// request拦截器
service
.
interceptors
.
request
.
use
(
service
.
interceptors
.
request
.
use
(
config
=>
{
config
=>
{
// 是否需要设置 token
if
(
getToken
())
{
const
isToken
=
(
config
.
headers
||
{}).
isToken
===
false
config
.
headers
[
'Authorization'
]
=
'Bearer '
+
getToken
()
// 让每个请求携带自定义token 请根据实际情况自行修改
if
(
getToken
()
&&
!
isToken
)
{
}
config
.
headers
[
'Authorization'
]
=
'Bearer '
+
getToken
()
// 让每个请求携带自定义token 请根据实际情况自行修改
return
config
}
},
return
config
error
=>
{
},
error
=>
{
console
.
log
(
error
)
console
.
log
(
error
)
Promise
.
reject
(
error
)
Promise
.
reject
(
error
)
}
})
)
// 响应拦截器
// 响应拦截器
service
.
interceptors
.
response
.
use
(
res
=>
{
service
.
interceptors
.
response
.
use
(
res
=>
{
const
code
=
res
.
data
.
code
// 未设置状态码则默认成功状态
const
code
=
res
.
data
.
code
||
200
;
// 获取错误信息
const
message
=
errorCode
[
code
]
||
res
.
data
.
msg
||
errorCode
[
'default'
]
if
(
code
===
401
)
{
if
(
code
===
401
)
{
MessageBox
.
confirm
(
MessageBox
.
confirm
(
'登录状态已过期,您可以继续留在该页面,或者重新登录'
,
'登录状态已过期,您可以继续留在该页面,或者重新登录'
,
...
@@ -42,9 +45,15 @@ service.interceptors.response.use(res => {
...
@@ -42,9 +45,15 @@ service.interceptors.response.use(res => {
location
.
reload
()
// 为了重新实例化vue-router对象 避免bug
location
.
reload
()
// 为了重新实例化vue-router对象 避免bug
})
})
})
})
}
else
if
(
code
===
500
)
{
Message
({
message
:
message
,
type
:
'error'
})
return
Promise
.
reject
(
new
Error
(
message
))
}
else
if
(
code
!==
200
)
{
}
else
if
(
code
!==
200
)
{
Notification
.
error
({
Notification
.
error
({
title
:
res
.
data
.
msg
title
:
message
})
})
return
Promise
.
reject
(
'error'
)
return
Promise
.
reject
(
'error'
)
}
else
{
}
else
{
...
...
ruoyi/src/main/java/com/ruoyi/framework/web/controller/BaseController.java
浏览文件 @
25b114aa
...
@@ -67,6 +67,7 @@ public class BaseController
...
@@ -67,6 +67,7 @@ public class BaseController
{
{
TableDataInfo
rspData
=
new
TableDataInfo
();
TableDataInfo
rspData
=
new
TableDataInfo
();
rspData
.
setCode
(
HttpStatus
.
SUCCESS
);
rspData
.
setCode
(
HttpStatus
.
SUCCESS
);
rspData
.
setMsg
(
"查询成功"
);
rspData
.
setRows
(
list
);
rspData
.
setRows
(
list
);
rspData
.
setTotal
(
new
PageInfo
(
list
).
getTotal
());
rspData
.
setTotal
(
new
PageInfo
(
list
).
getTotal
());
return
rspData
;
return
rspData
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论