Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ant-design-pro-vue
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tianzhuanghu
ant-design-pro-vue
Commits
69cf97af
Commit
69cf97af
authored
Dec 15, 2018
by
Sendya
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dev' into pr/29
parents
cc99477e
b350c3bf
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
271 additions
and
4 deletions
+271
-4
router.config.js
src/config/router.config.js
+15
-0
main.js
src/main.js
+2
-0
permission.js
src/utils/helper/permission.js
+54
-0
TableList.vue
src/views/list/TableList.vue
+6
-4
RoleList.vue
src/views/role/RoleList.vue
+194
-0
No files found.
src/config/router.config.js
View file @
69cf97af
...
...
@@ -169,6 +169,21 @@ export const asyncRouterMap = [
}
]
},
{
path
:
'/system'
,
name
:
'system'
,
component
:
RouteView
,
redirect
:
'/system/role'
,
meta
:
{
title
:
'系统管理'
,
icon
:
'setting'
,
permission
:
[
'table'
]
},
children
:
[
{
path
:
'/system/role'
,
name
:
'SystemRole'
,
component
:
()
=>
import
(
'@/views/role/RoleList'
),
meta
:
{
title
:
'角色列表'
,
permission
:
[
'table'
]}
}
]
},
// result
{
...
...
src/main.js
View file @
69cf97af
...
...
@@ -12,6 +12,7 @@ import 'ant-design-vue/dist/antd.less' // or 'ant-design-vue/dist/antd.less'
import
'@/permission'
// permission control
import
'@/utils/filter'
// base filter
import
PermissionHelper
from
'@/utils/helper/permission'
import
{
ACCESS_TOKEN
,
...
...
@@ -33,6 +34,7 @@ Vue.use(Storage, config.storageOptions)
Vue
.
use
(
Antd
)
Vue
.
use
(
VueAxios
,
router
)
Vue
.
use
(
Viser
)
Vue
.
use
(
PermissionHelper
)
new
Vue
({
router
,
...
...
src/utils/helper/permission.js
0 → 100644
View file @
69cf97af
const
PERMISSION_ENUM
=
{
'add'
:
{
key
:
'add'
,
label
:
'新增'
},
'delete'
:
{
key
:
'delete'
,
label
:
'删除'
},
'edit'
:
{
key
:
'edit'
,
label
:
'修改'
},
'query'
:
{
key
:
'query'
,
label
:
'查询'
},
'get'
:
{
key
:
'get'
,
label
:
'详情'
},
'enable'
:
{
key
:
'enable'
,
label
:
'启用'
},
'disable'
:
{
key
:
'disable'
,
label
:
'禁用'
},
'import'
:
{
key
:
'import'
,
label
:
'导入'
},
'export'
:
{
key
:
'import'
,
label
:
'导入'
},
};
function
plugin
(
Vue
)
{
if
(
plugin
.
installed
)
{
return
;
}
!
Vue
.
prototype
.
$auth
&&
Object
.
defineProperties
(
Vue
.
prototype
,
{
$auth
:
{
get
()
{
const
_this
=
this
;
return
(
permissions
)
=>
{
let
[
permission
,
action
]
=
permissions
.
split
(
'.'
);
const
permissionList
=
_this
.
$store
.
getters
.
roles
.
permissions
;
permissionList
.
find
((
val
)
=>
{
return
val
.
permissionId
===
permission
}).
actionList
.
findIndex
((
val
)
=>
{
return
val
===
action
});
return
false
}
}
}
});
!
Vue
.
prototype
.
$enum
&&
Object
.
defineProperties
(
Vue
.
prototype
,
{
$enum
:
{
get
()
{
// const _this = this;
return
(
val
)
=>
{
let
result
=
PERMISSION_ENUM
;
val
&&
val
.
split
(
'.'
).
forEach
(
v
=>
{
result
=
result
&&
result
[
v
]
||
null
});
return
result
}
}
}
});
}
export
default
plugin
\ No newline at end of file
src/views/list/TableList.vue
View file @
69cf97af
...
...
@@ -62,8 +62,8 @@
</div>
<div
class=
"table-operator"
>
<a-button
type=
"primary"
icon=
"plus"
>
新建
</a-button>
<a-dropdown
v-if=
"
selectedRowKeys.length > 0"
>
<a-button
type=
"primary"
icon=
"plus"
v-if=
"$auth('table.add')"
>
新建
</a-button>
<a-dropdown
v-if=
"
$auth('table.edit') && selectedRowKeys.length > 0"
>
<a-menu
slot=
"overlay"
>
<a-menu-item
key=
"1"
><a-icon
type=
"delete"
/>
删除
</a-menu-item>
<!-- lock | unlock -->
...
...
@@ -84,8 +84,10 @@
@
onSelect=
"onChange"
>
<span
slot=
"action"
slot-scope=
"text, record"
>
<
template
v-if=
"$auth('table.update')"
>
<a
@
click=
"handleEdit(record)"
>
编辑
</a>
<a-divider
type=
"vertical"
/>
</
template
>
<a-dropdown>
<a
class=
"ant-dropdown-link"
>
更多
<a-icon
type=
"down"
/>
...
...
@@ -94,10 +96,10 @@
<a-menu-item>
<a
href=
"javascript:;"
>
详情
</a>
</a-menu-item>
<a-menu-item
>
<a-menu-item
v-if=
"$auth('table.disable')"
>
<a
href=
"javascript:;"
>
禁用
</a>
</a-menu-item>
<a-menu-item
>
<a-menu-item
v-if=
"$auth('table.delete')"
>
<a
href=
"javascript:;"
>
删除
</a>
</a-menu-item>
</a-menu>
...
...
src/views/role/RoleList.vue
0 → 100644
View file @
69cf97af
<
template
>
<page-layout
title=
"角色管理"
>
<a-card
:bordered=
"false"
:style=
"
{ height: '100%' }">
<!--
<a-tabs
defaultActiveKey=
"1"
tabPosition=
"left"
size=
"large"
:style=
"
{ height: '400px'}" :tabBarStyle="{ textAlign: 'left' }" @prevClick="callback" @nextClick="callback">
<a-tab-pane
tab=
"管理员"
key=
"1"
>
Content of tab 1
</a-tab-pane>
<a-tab-pane
tab=
"销售组长"
key=
"2"
>
Content of tab 2
</a-tab-pane>
<a-tab-pane
tab=
"销售总负责人"
key=
"3"
>
Content of tab 3
</a-tab-pane>
<a-tab-pane
tab=
"总经理"
key=
"4"
>
Content of tab 4
</a-tab-pane>
<a-tab-pane
tab=
"普通销售"
key=
"5"
>
Content of tab 5
</a-tab-pane>
<a-tab-pane
tab=
"客服"
key=
"6"
>
Content of tab 6
</a-tab-pane>
<a-tab-pane
tab=
"会员"
key=
"7"
>
Content of tab 7
</a-tab-pane>
<a-tab-pane
tab=
"增加角色"
key=
"-1"
>
Content of tab 7
</a-tab-pane>
</a-tabs>
-->
<a-row
:gutter=
"24"
>
<a-col
:md=
"4"
>
<a-list
itemLayout=
"vertical"
:dataSource=
"roles"
>
<a-list-item
slot=
"renderItem"
slot-scope=
"item, index"
:key=
"index"
>
<a-list-item-meta
:style=
"
{ marginBottom: '0' }">
<span
slot=
"description"
style=
"text-align: center; display: block"
>
{{
item
.
describe
}}
</span>
<a
slot=
"title"
style=
"text-align: center; display: block"
@
click=
"edit(item)"
>
{{
item
.
name
}}
</a>
</a-list-item-meta>
</a-list-item>
</a-list>
</a-col>
<a-col
:md=
"20"
>
<a-row
v-if=
"mdl.id"
>
<a-col
:span=
"5"
><h3
style=
"text-align: right"
>
角色:
</h3></a-col>
<a-col
:span=
"19"
><h3>
{{
mdl
.
name
}}
</h3></a-col>
</a-row>
<a-form
:form=
"form"
>
<a-form-item
label=
"唯一键"
:labelCol=
"
{ span: 5 }"
:wrapperCol="{ span: 18 }"
>
<a-input
v-decorator=
"[ 'id',
{rules: [{ required: true, message: 'Please input unique key!' }]} ]" placeholder="请填写唯一键" />
</a-form-item>
<a-form-item
label=
"角色名称"
:labelCol=
"
{ span: 5 }"
:wrapperCol="{ span: 18 }"
>
<a-input
v-decorator=
"[ 'name',
{rules: [{ required: true, message: 'Please input role name!' }]} ]" placeholder="请填写角色名称" />
</a-form-item>
<a-form-item
label=
"状态"
:labelCol=
"
{ span: 5 }"
:wrapperCol="{ span: 18 }"
>
<a-select
v-decorator=
"[ 'status',
{rules: []} ]">
<a-select-option
:value=
"1"
>
正常
</a-select-option>
<a-select-option
:value=
"2"
>
禁用
</a-select-option>
</a-select>
</a-form-item>
<a-form-item
label=
"备注说明"
:labelCol=
"
{ span: 5 }"
:wrapperCol="{ span: 18 }"
>
<a-textarea
:row=
"3"
v-decorator=
"[ 'describe',
{rules: [{ required: true, message: 'Please input role name!' }]} ]" placeholder="请填写角色名称" />
</a-form-item>
<a-form-item
label=
"拥有权限"
:labelCol=
"
{ span: 5 }"
:wrapperCol="{ span: 18 }"
>
<a-row
:gutter=
"16"
v-for=
"(permission, index) in permissions"
:key=
"index"
>
<a-col
:span=
"4"
>
{{
permission
.
name
}}
:
</a-col>
<a-col
:span=
"20"
>
<a-checkbox
v-if=
"permission.actionsOptions.length > 0"
:indeterminate=
"permission.indeterminate"
:checked=
"permission.checkedAll"
@
change=
"onChangeCheckAll($event, permission)"
>
全选
</a-checkbox>
<a-checkbox-group
:options=
"permission.actionsOptions"
v-model=
"permission.selected"
@
change=
"onChangeCheck(permission)"
/>
</a-col>
</a-row>
</a-form-item>
</a-form>
</a-col>
</a-row>
</a-card>
</page-layout>
</
template
>
<
script
>
import
PageLayout
from
'@/components/page/PageLayout'
import
{
getRoleList
,
getPermissions
}
from
"@/api/manage"
import
{
actionToObject
}
from
'@/utils/permissions'
import
pick
from
'lodash.pick'
export
default
{
name
:
"RoleList"
,
components
:
{
PageLayout
},
data
()
{
return
{
form
:
this
.
$form
.
createForm
(
this
),
mdl
:
{},
roles
:
[],
permissions
:
[]
}
},
created
()
{
getRoleList
().
then
((
res
)
=>
{
this
.
roles
=
res
.
result
.
data
this
.
roles
.
push
({
id
:
'-1'
,
name
:
'新增角色'
,
describe
:
'新增一个角色'
})
console
.
log
(
'this.roles'
,
this
.
roles
)
})
this
.
loadPermissions
()
},
methods
:
{
callback
(
val
)
{
console
.
log
(
val
)
},
add
()
{
this
.
edit
({
id
:
0
})
},
edit
(
record
)
{
this
.
mdl
=
Object
.
assign
({},
record
)
// 有权限表,处理勾选
if
(
this
.
mdl
.
permissions
&&
this
.
permissions
)
{
// 先处理要勾选的权限结构
const
permissionsAction
=
{}
this
.
mdl
.
permissions
.
forEach
(
permission
=>
{
permissionsAction
[
permission
.
permissionId
]
=
permission
.
actionEntitySet
.
map
(
entity
=>
entity
.
action
)
})
// 把权限表遍历一遍,设定要勾选的权限 action
this
.
permissions
.
forEach
(
permission
=>
{
permission
.
selected
=
permissionsAction
[
permission
.
id
]
})
}
this
.
$nextTick
(()
=>
{
this
.
form
.
setFieldsValue
(
pick
(
this
.
mdl
,
'id'
,
'name'
,
'status'
,
'describe'
))
})
console
.
log
(
'this.mdl'
,
this
.
mdl
)
},
onChangeCheck
(
permission
)
{
permission
.
indeterminate
=
!!
permission
.
selected
.
length
&&
(
permission
.
selected
.
length
<
permission
.
actionsOptions
.
length
)
permission
.
checkedAll
=
permission
.
selected
.
length
===
permission
.
actionsOptions
.
length
},
onChangeCheckAll
(
e
,
permission
)
{
Object
.
assign
(
permission
,
{
selected
:
e
.
target
.
checked
?
permission
.
actionsOptions
.
map
(
obj
=>
obj
.
value
)
:
[],
indeterminate
:
false
,
checkedAll
:
e
.
target
.
checked
})
},
loadPermissions
()
{
getPermissions
().
then
(
res
=>
{
let
result
=
res
.
result
this
.
permissions
=
result
.
map
(
permission
=>
{
const
options
=
actionToObject
(
permission
.
actionData
)
permission
.
checkedAll
=
false
permission
.
selected
=
[]
permission
.
indeterminate
=
false
permission
.
actionsOptions
=
options
.
map
(
option
=>
{
return
{
label
:
option
.
describe
,
value
:
option
.
action
}
})
return
permission
})
})
}
},
}
</
script
>
<
style
scoped
>
</
style
>
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment