Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
C
cocktail-party-server
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
cocktail-party
cocktail-party-server
Commits
e5647793
提交
e5647793
authored
12月 18, 2021
作者:
RuoYi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
路由支持单独配置菜单或角色权限
上级
903b5aeb
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
33 行增加
和
2 行删除
+33
-2
index.js
ruoyi-ui/src/router/index.js
+12
-1
permission.js
ruoyi-ui/src/store/modules/permission.js
+21
-1
没有找到文件。
ruoyi-ui/src/router/index.js
浏览文件 @
e5647793
...
...
@@ -17,6 +17,8 @@ import Layout from '@/layout'
* redirect: noRedirect // 当设置 noRedirect 的时候该路由在面包屑导航中不可被点击
* name:'router-name' // 设定路由的名字,一定要填写不然使用<keep-alive>时会出现各种问题
* query: '{"id": 1, "name": "ry"}' // 访问路由的默认传递参数
* roles: ['admin', 'common'] // 访问路由的角色权限
* permissions: ['a:a:a', 'b:b:b'] // 访问路由的菜单权限
* meta : {
noCache: true // 如果设置为true,则不会被 <keep-alive> 缓存(默认 false)
title: 'title' // 设置该路由在侧边栏和面包屑中展示的名字
...
...
@@ -85,11 +87,16 @@ export const constantRoutes = [
meta
:
{
title
:
'个人中心'
,
icon
:
'user'
}
}
]
},
}
]
// 动态路由,基于用户权限动态去加载
export
const
dynamicRoutes
=
[
{
path
:
'/system/user-auth'
,
component
:
Layout
,
hidden
:
true
,
permissions
:
[
'system:user:edit'
],
children
:
[
{
path
:
'role/:userId(
\\
d+)'
,
...
...
@@ -103,6 +110,7 @@ export const constantRoutes = [
path
:
'/system/role-auth'
,
component
:
Layout
,
hidden
:
true
,
permissions
:
[
'system:role:edit'
],
children
:
[
{
path
:
'user/:roleId(
\\
d+)'
,
...
...
@@ -116,6 +124,7 @@ export const constantRoutes = [
path
:
'/system/dict-data'
,
component
:
Layout
,
hidden
:
true
,
permissions
:
[
'system:dict:list'
],
children
:
[
{
path
:
'index/:dictId(
\\
d+)'
,
...
...
@@ -129,6 +138,7 @@ export const constantRoutes = [
path
:
'/monitor/job-log'
,
component
:
Layout
,
hidden
:
true
,
permissions
:
[
'monitor:job:list'
],
children
:
[
{
path
:
'index'
,
...
...
@@ -142,6 +152,7 @@ export const constantRoutes = [
path
:
'/tool/gen-edit'
,
component
:
Layout
,
hidden
:
true
,
permissions
:
[
'tool:gen:edit'
],
children
:
[
{
path
:
'index'
,
...
...
ruoyi-ui/src/store/modules/permission.js
浏览文件 @
e5647793
import
{
constantRoutes
}
from
'@/router'
import
auth
from
'@/plugins/auth'
import
router
,
{
constantRoutes
,
dynamicRoutes
}
from
'@/router'
import
{
getRouters
}
from
'@/api/menu'
import
Layout
from
'@/layout/index'
import
ParentView
from
'@/components/ParentView'
...
...
@@ -42,7 +43,9 @@ const permission = {
const
rdata
=
JSON
.
parse
(
JSON
.
stringify
(
res
.
data
))
const
sidebarRoutes
=
filterAsyncRouter
(
sdata
)
const
rewriteRoutes
=
filterAsyncRouter
(
rdata
,
false
,
true
)
const
asyncRoutes
=
filterDynamicRoutes
(
dynamicRoutes
);
rewriteRoutes
.
push
({
path
:
'*'
,
redirect
:
'/404'
,
hidden
:
true
})
router
.
addRoutes
(
asyncRoutes
);
commit
(
'SET_ROUTES'
,
rewriteRoutes
)
commit
(
'SET_SIDEBAR_ROUTERS'
,
constantRoutes
.
concat
(
sidebarRoutes
))
commit
(
'SET_DEFAULT_ROUTES'
,
sidebarRoutes
)
...
...
@@ -106,6 +109,23 @@ function filterChildren(childrenMap, lastRouter = false) {
return
children
}
// 动态路由遍历,验证是否具备权限
export
function
filterDynamicRoutes
(
routes
)
{
const
res
=
[]
routes
.
forEach
(
route
=>
{
if
(
route
.
permissions
)
{
if
(
auth
.
hasPermiOr
(
route
.
permissions
))
{
res
.
push
(
route
)
}
}
else
if
(
route
.
roles
)
{
if
(
auth
.
hasRoleOr
(
route
.
roles
))
{
res
.
push
(
route
)
}
}
})
return
res
}
export
const
loadView
=
(
view
)
=>
{
if
(
process
.
env
.
NODE_ENV
===
'development'
)
{
return
(
resolve
)
=>
require
([
`@/views/
${
view
}
`
],
resolve
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论