Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
C
center-project
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
EzijingWeb
center-project
Commits
dda9f13d
提交
dda9f13d
authored
10月 15, 2021
作者:
王鹏飞
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
新增权限控制
上级
45e753e8
显示空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
95 行增加
和
20 行删除
+95
-20
base.js
src/api/base.js
+7
-0
Aside.vue
src/components/layout/Aside.vue
+22
-2
Permissions.vue
src/modules/roles/components/Permissions.vue
+35
-15
index.js
src/store/index.js
+17
-3
axios.js
src/utils/axios.js
+14
-0
没有找到文件。
src/api/base.js
浏览文件 @
dda9f13d
...
...
@@ -27,3 +27,10 @@ export function uploadFile(data) {
headers
:
{
'Content-Type'
:
'multipart/form-data'
}
})
}
/**
* 获取权限列表
*/
export
function
getPermissions
(
params
)
{
return
httpRequest
.
get
(
'/api/permissions/api/v1/user/permissions'
,
{
params
})
}
src/components/layout/Aside.vue
浏览文件 @
dda9f13d
...
...
@@ -5,11 +5,16 @@
<template
v-for=
"item in menuList"
>
<el-submenu
:index=
"item.path"
:key=
"item.path"
v-if=
"item.children"
>
<template
#
title
><i
:class=
"item.icon"
></i>
{{
item
.
name
}}
</
template
>
<el-menu-item
:index=
"subitem.path"
v-for=
"subitem in item.children"
:key=
"subitem.path"
>
<el-menu-item
:index=
"subitem.path"
v-for=
"subitem in item.children"
:key=
"subitem.path"
v-show=
"menuVisible(subitem.tag)"
>
{{ subitem.name }}
</el-menu-item>
</el-submenu>
<el-menu-item
:index=
"item.path"
:key=
"item.path"
v-else
>
<el-menu-item
:index=
"item.path"
:key=
"item.path"
v-else
v-show=
"menuVisible(item.tag)"
>
<i
:class=
"item.icon"
></i>
{{ item.name }}
</el-menu-item>
</template>
...
...
@@ -25,16 +30,19 @@ export default {
return
{
menuList
:
[
{
tag
:
'menu_org'
,
name
:
'机构管理'
,
path
:
'/school'
,
icon
:
'el-icon-school'
},
{
tag
:
'menu_role'
,
name
:
'角色管理'
,
path
:
'/roles'
,
icon
:
'el-icon-star-off'
},
{
tag
:
'menu_permission'
,
name
:
'权限管理'
,
path
:
'/permissions'
,
icon
:
'el-icon-coordinate'
...
...
@@ -56,6 +64,18 @@ export default {
return
this
.
$route
.
path
.
includes
(
item
.
path
)
})
return
found
?
found
.
path
:
'/school/class'
},
// 菜单权限
menuPermissions
()
{
return
this
.
$store
.
state
.
permissions
.
filter
(
item
=>
item
.
type
===
2
)
}
},
methods
:
{
menuVisible
(
tag
)
{
if
(
!
tag
)
{
return
true
}
return
!!
this
.
menuPermissions
.
find
(
item
=>
item
.
tag
===
tag
)
}
}
}
...
...
src/modules/roles/components/Permissions.vue
浏览文件 @
dda9f13d
...
...
@@ -11,13 +11,7 @@
<el-form-item
label=
"权限设置"
prop=
"name"
>
<div
v-for=
"(item, index) in options"
:key=
"index"
v-show=
"form.system_tag.includes(item.system_tag)"
>
{{
item
.
name
}}
<el-cascader-panel
:options=
"item.permissions"
:props=
"defaultProps"
v-model=
"item.value"
ref=
"tree"
@
change=
"handleChange"
></el-cascader-panel>
<el-cascader-panel
:options=
"item.permissions"
:props=
"defaultProps"
v-model=
"item.value"
></el-cascader-panel>
</div>
</el-form-item>
</el-form>
...
...
@@ -50,7 +44,8 @@ export default {
{
name
:
'学校管理系统'
,
system_tag
:
1
,
permissions
:
[],
value
:
[]
},
{
name
:
'教师端'
,
system_tag
:
2
,
permissions
:
[],
value
:
[]
},
{
name
:
'学生端'
,
system_tag
:
3
,
permissions
:
[],
value
:
[]
}
]
],
idsPath
:
[]
}
},
async
beforeMount
()
{
...
...
@@ -68,8 +63,8 @@ export default {
getPermissions
()
{
return
getPermissionList
({
is_format
:
1
}).
then
(
res
=>
{
// 移除空数组
const
permissions
=
JSON
.
parse
(
JSON
.
stringify
(
res
.
data
).
replaceAll
(
',"children":[]'
,
''
))
this
.
options
=
permissions
.
reduce
((
result
,
item
)
=>
{
this
.
permissions
=
JSON
.
parse
(
JSON
.
stringify
(
res
.
data
).
replaceAll
(
',"children":[]'
,
''
))
this
.
options
=
this
.
permissions
.
reduce
((
result
,
item
)
=>
{
const
index
=
result
.
findIndex
(
i
=>
i
.
system_tag
===
item
.
system_tag
)
if
(
index
!==
-
1
)
{
result
[
index
].
permissions
.
push
(
item
)
...
...
@@ -102,12 +97,22 @@ export default {
},
// 确定
onPrimary
()
{
this
.
$refs
.
form
.
validate
().
then
(()
=>
{
this
.
$refs
.
form
.
validate
().
then
(
this
.
updateRolePermissions
)
},
updateRolePermissions
()
{
const
params
=
{
role_id
:
this
.
data
.
id
,
data
:
this
.
options
.
reduce
((
result
,
item
)
=>
{
if
(
this
.
form
.
system_tag
.
includes
(
item
.
system_tag
))
{
result
.
push
({
system_tag
:
item
.
system_tag
,
permission_ids
:
item
.
value
})
// item.value 所有选中的权限,最后节点的ID
let
ids
=
[]
item
.
value
.
forEach
(
id
=>
{
// 通过子节点ID,返回包含父节点ID的数组
this
.
getIdPath
(
this
.
permissions
,
id
)
ids
=
ids
.
concat
(
this
.
idsPath
)
this
.
idsPath
=
[]
})
result
.
push
({
system_tag
:
item
.
system_tag
,
permission_ids
:
this
.
uniqueIds
(
ids
)
})
}
return
result
},
[])
...
...
@@ -122,10 +127,25 @@ export default {
.
finally
(()
=>
{
this
.
submitLoading
=
false
})
})
},
handleChange
(
e
)
{
console
.
log
(
e
)
// 通过子节点ID,返回路径数组
getIdPath
(
tree
,
targetId
)
{
for
(
let
index
=
0
;
index
<
tree
.
length
;
index
++
)
{
if
(
tree
[
index
].
children
)
{
if
(
this
.
getIdPath
(
tree
[
index
].
children
,
targetId
))
{
this
.
idsPath
.
push
(
tree
[
index
].
id
)
return
true
}
}
if
(
tree
[
index
].
id
===
targetId
)
{
this
.
idsPath
.
push
(
tree
[
index
].
id
)
return
true
}
}
},
// ID去重
uniqueIds
(
ids
)
{
return
Array
.
from
(
new
Set
(
ids
))
}
}
}
...
...
src/store/index.js
浏览文件 @
dda9f13d
import
Vue
from
'vue'
import
Vuex
from
'vuex'
import
{
getUser
,
logout
}
from
'@/api/base'
import
{
getUser
,
logout
,
getPermissions
}
from
'@/api/base'
Vue
.
use
(
Vuex
)
export
default
new
Vuex
.
Store
({
const
store
=
new
Vuex
.
Store
({
state
:
{
user
:
{}
user
:
{},
permissions
:
[]
// 权限列表
},
mutations
:
{
setUser
(
state
,
user
)
{
state
.
user
=
user
},
setPermissions
(
state
,
permissions
)
{
state
.
permissions
=
permissions
}
},
actions
:
{
getPermissions
({
commit
})
{
getPermissions
({
type
:
2
}).
then
(
res
=>
{
if
(
res
.
data
&&
res
.
data
.
items
)
{
commit
(
'setPermissions'
,
res
.
data
.
items
)
}
})
},
// 获取用户信息
getUser
({
commit
})
{
getUser
().
then
(
response
=>
{
...
...
@@ -46,3 +57,6 @@ export default new Vuex.Store({
}
}
})
store
.
dispatch
(
'getPermissions'
)
export
default
store
src/utils/axios.js
浏览文件 @
dda9f13d
...
...
@@ -12,6 +12,20 @@ const httpRequest = axios.create({
// 请求拦截
httpRequest
.
interceptors
.
request
.
use
(
function
(
config
)
{
// 权限接口单独签名
// https://gitlab.ezijing.com/root/api-documents/-/blob/master/ezijing_permissions/%E7%AD%BE%E5%90%8D%E9%AA%8C%E8%AF%81.md
if
(
/^
\/
api
\/
permissions/
.
test
(
config
.
url
))
{
// 默认参数
const
defaultHeaders
=
{
timestamp
:
parseInt
(
Date
.
now
()
/
1000
),
nonce
:
Math
.
random
().
toString
(
36
).
slice
(
-
8
),
'secret-id'
:
'ezijing_05eb8ba938a32c105e0c0a505444ba26'
,
'secret-key'
:
'49272e8f17b2fa46cdadebc512984129'
,
signature
:
'UG7wBenexQhiuD2wpCwuxkU0jqcj006d'
}
config
.
headers
=
Object
.
assign
(
config
.
headers
,
defaultHeaders
)
}
if
(
config
.
headers
[
'Content-Type'
]
===
'application/x-www-form-urlencoded'
)
{
config
.
data
=
queryString
.
stringify
(
config
.
data
)
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论