Browse Source

remove obsolete components :PermissionTree

pull/109/head
cKey 5 years ago
parent
commit
ea1f8a6d3b
  1. 236
      vueJs/src/components/PermissionTree/index.vue
  2. 12
      vueJs/src/views/admin/users/index.vue

236
vueJs/src/components/PermissionTree/index.vue

@ -1,236 +0,0 @@
<template>
<el-tree
ref="tree"
show-checkbox
node-key="id"
:data="permissionTreeData"
:default-checked-keys="[]"
:render-content="renderContent"
:default-expanded-keys="permissionExpandedKeys"
@check="handlePermissionChecked"
@node-expand="handleNodeExpand"
/>
</template>
<script lang="ts">
import { IPermission } from '@/api/types'
import { Component, Vue, Prop, Watch } from 'vue-property-decorator'
import { PermissionDto, PermissionGroup, Permission } from '@/api/permission'
/** element权限树 */
export class PermissionTree {
/** 权限标识 */
id!: string
/** 显示名称 */
label!: string
/** 是否禁用 */
disabled!: boolean
/** 父节点 */
parent!: string
/** 子节点 */
children!: PermissionTree[]
constructor() {
this.disabled = false
this.children = new Array<PermissionTree>()
}
}
/** 权限树组件 */
@Component({
name: 'PermissionTree'
})
export default class extends Vue {
/** 是否只读 */
@Prop({ default: false }) private readonly!: boolean
/** 是否展开权限树 */
@Prop({ default: false }) private expanded!: boolean
/**
* @description 功能实现来自https://www.jianshu.com/p/f740e8c9fca6
*/
@Prop({ default: false }) private horizontally!: boolean
/** 权限列表 */
@Prop({ default: () => new PermissionDto() }) private permission!: PermissionDto
/** 权限树 */
private permissionTreeData: PermissionTree[]
/** 权限树选中节点 */
private permissionCheckedKeys: string[]
/** 权限树展开节点 */
private permissionExpandedKeys: string[]
/** 授权接口集合 */
private permissionEditData: IPermission[]
constructor() {
super()
this.permissionTreeData = new Array<PermissionTree>()
this.permissionCheckedKeys = new Array<string>()
this.permissionExpandedKeys = new Array<string>()
this.permissionEditData = new Array<IPermission>()
}
@Watch('permission', { immediate: true })
private onPermissionChanged(permission: PermissionDto) {
this.initilzePermissionTree(permission)
setTimeout(() => {
const treeControl = this.$refs.tree as any
treeControl.setCheckedKeys(this.permissionCheckedKeys)
}, 10)
}
/** 重置权限树 */
public resetPermissions() {
this.permissionTreeData.splice(0)
this.permissionCheckedKeys.splice(0)
this.permissionExpandedKeys.splice(0)
this.permissionEditData.splice(0)
}
/**
* @param permission 权限数据
*/
private initilzePermissionTree(permission: PermissionDto) {
this.resetPermissions()
const permissionTree = new PermissionTree()
permissionTree.id = permission.entityDisplayName
permissionTree.label = '权限设置'
permissionTree.disabled = this.readonly
this.generatePermissionGroup(permissionTree, permission.groups)
this.permissionTreeData.push(permissionTree)
this.permissionExpandedKeys.push(permissionTree.id)
}
/**
* @param permissionTree 根权限树
* @param permissionGroups 根权限组
*/
private generatePermissionGroup(permissionTree: PermissionTree, permissionGroups: PermissionGroup[]) {
permissionGroups.forEach((group) => {
const permissionTreeItem = new PermissionTree()
permissionTreeItem.id = group.name
permissionTreeItem.label = group.displayName
permissionTreeItem.disabled = this.readonly
//
if (this.expanded) {
this.permissionExpandedKeys.push(group.name)
}
this.generatePermission(permissionTreeItem, group.permissions)
permissionTree.children.push(permissionTreeItem)
//
// abp,Group,,,
// this.permissionEditData.push({ name: group.name, isGranted: group.permissions.some(p => p.isGranted) })
})
}
/**
* @param permissionTree 二级权限树
* @param permissions 权限列表
*/
private generatePermission(permissionTree: PermissionTree, permissions: Permission[]) {
const parentPermissions = permissions.filter(p => !p.parentName)
parentPermissions.forEach((permission) => {
const permissionTreeItem = new PermissionTree()
permissionTreeItem.id = permission.name
permissionTreeItem.label = permission.displayName
permissionTreeItem.disabled = this.readonly
this.permissionEditData.push(permission)
const subPermissions = permissions.filter(p => p.parentName === permission.name)
// 2020-08-28 ,
if (subPermissions.length === 0) {
if (permission.isGranted) {
this.permissionCheckedKeys.push(permissionTreeItem.id)
}
} else {
this.generateSubPermission(permissionTreeItem, subPermissions, permissions)
}
permissionTree.children.push(permissionTreeItem)
})
}
/**
* @param permissionTree 父权限树
* @param permissions 当前遍历权限节点
* @param parentPermissions 当前遍历权限的父权限节点
* @description abp框架定义所有子节点都在第三级里面.所以需要传递父节点来判断当前循环的权限的子权限节点
*/
private generateSubPermission(permissionTree: PermissionTree, permissions: Permission[], parentPermissions: Permission[]) {
permissions.forEach((permission) => {
const permissionTreeItem = new PermissionTree()
permissionTreeItem.id = permission.name
permissionTreeItem.label = permission.displayName
permissionTreeItem.disabled = this.readonly
this.permissionEditData.push(permission)
//
const subPermissions = parentPermissions.filter(p => p.parentName === permission.name)
//
if (subPermissions.length > 0) {
this.generateSubPermission(permissionTreeItem, subPermissions, permissions)
} else { // ,
if (permission.isGranted) {
this.permissionCheckedKeys.push(permissionTreeItem.id)
}
}
permissionTree.children.push(permissionTreeItem)
})
}
/** 权限树选择相应事件 */
private handlePermissionChecked(data: any, treeCheckData: any) {
this.permissionEditData.forEach((permission: IPermission) => {
permission.isGranted = treeCheckData.checkedKeys.some((k: string) => k.indexOf(permission.name) !== -1)
})
// ,
this.$emit('onPermissionChanged', this.permissionEditData)
}
/**
* @description 监听节点展开完毕事件,刷新子节点样式
*/
private handleNodeExpand() {
this.$nextTick().then(() => {
this.changeTree()
})
}
/** 自定义权限树子节点渲染 */
private renderContent(h: any, context: { node: any, data: PermissionTree}) {
if (this.horizontally) {
if (context.data.children.length > 0) {
return h(
'span',
{ class: 'el-tree-node__label' },
[context.node.label]
)
} else {
return h(
'div',
{ class: 'horizontally' },
[context.node.label])
}
}
return h(
'span',
{ class: 'el-tree-node__label' },
[context.node.label]
)
}
/**
* @description https://www.jianshu.com/p/f740e8c9fca6
*/
private changeTree() {
const classDomList = document.getElementsByClassName('horizontally')
for (let i = 0; i < classDomList.length; i++) {
const parentNode = classDomList[i].parentNode as any
parentNode.style.cssText = 'float: left'
parentNode.className = 'el-tree-node__content option-wrapper'
parentNode.parentNode.style.marginLeft = '70px'
}
}
}
</script>
<style lang="scss" scoped>
.option-wrapper {
padding: 0 !important;
}
</style>

12
vueJs/src/views/admin/users/index.vue

@ -138,12 +138,6 @@
> >
{{ $t('AbpIdentity.Edit') }} {{ $t('AbpIdentity.Edit') }}
</el-dropdown-item> </el-dropdown-item>
<el-dropdown-item
:command="{key: 'claim', row}"
:disabled="!checkPermission(['AbpIdentity.Users.ManageClaims'])"
>
{{ $t('AbpIdentity.ManageClaim') }}
</el-dropdown-item>
<el-dropdown-item <el-dropdown-item
:command="{key: 'permission', row}" :command="{key: 'permission', row}"
:disabled="!checkPermission(['AbpIdentity.Users.ManagePermissions'])" :disabled="!checkPermission(['AbpIdentity.Users.ManagePermissions'])"
@ -156,6 +150,12 @@
> >
{{ $t('AbpIdentity.Lock') }} {{ $t('AbpIdentity.Lock') }}
</el-dropdown-item> </el-dropdown-item>
<el-dropdown-item
:command="{key: 'claim', row}"
:disabled="!checkPermission(['AbpIdentity.Users.ManageClaims'])"
>
{{ $t('AbpIdentity.ManageClaim') }}
</el-dropdown-item>
<el-dropdown-item <el-dropdown-item
divided divided
:command="{key: 'delete', row}" :command="{key: 'delete', row}"

Loading…
Cancel
Save