pixel
5 years ago
5 changed files with 246 additions and 190 deletions
-
180QMPlusVuePage/src/view/superAdmin/authority/authority.vue
-
99QMPlusVuePage/src/view/superAdmin/authority/components/apis.vue
-
76QMPlusVuePage/src/view/superAdmin/authority/components/menus.vue
-
10QMPlusVuePage/src/view/superAdmin/menu/menu.vue
-
57QMPlusVuePage/src/view/superAdmin/user/user.vue
@ -0,0 +1,99 @@ |
|||||
|
<template> |
||||
|
<div> |
||||
|
<div class="clearflex"> |
||||
|
<el-button @click="authApiEnter" class="fl-right" size="small" type="primary">确 定</el-button> |
||||
|
</div> |
||||
|
<el-tree |
||||
|
:data="apiTreeData" |
||||
|
:default-checked-keys="apiTreeIds" |
||||
|
:props="apiDefaultProps" |
||||
|
default-expand-all |
||||
|
highlight-current |
||||
|
node-key="path" |
||||
|
ref="apiTree" |
||||
|
show-checkbox |
||||
|
></el-tree> |
||||
|
</div> |
||||
|
</template> |
||||
|
<script> |
||||
|
import { getAllApis } from '@/api/api' |
||||
|
import { casbinPUpdata, getPolicyPathByAuthorityId } from '@/api/casbin' |
||||
|
export default { |
||||
|
name: 'Apis', |
||||
|
props: { |
||||
|
row: { |
||||
|
default: function() { |
||||
|
return {} |
||||
|
}, |
||||
|
type: Object |
||||
|
} |
||||
|
}, |
||||
|
data() { |
||||
|
return { |
||||
|
apiTreeData: [], |
||||
|
apiTreeIds: [], |
||||
|
apiDefaultProps: { |
||||
|
children: 'children', |
||||
|
label: 'description' |
||||
|
} |
||||
|
} |
||||
|
}, |
||||
|
methods: { |
||||
|
// 创建api树方法 |
||||
|
buildApiTree(apis) { |
||||
|
const apiObj = new Object() |
||||
|
apis && |
||||
|
apis.map(item => { |
||||
|
if (apiObj.hasOwnProperty(item.group)) { |
||||
|
apiObj[item.group].push(item) |
||||
|
} else { |
||||
|
Object.assign(apiObj, { [item.group]: [item] }) |
||||
|
} |
||||
|
}) |
||||
|
const apiTree = [] |
||||
|
for (const key in apiObj) { |
||||
|
const treeNode = { |
||||
|
ID: key, |
||||
|
description: key + '组', |
||||
|
children: apiObj[key] |
||||
|
} |
||||
|
apiTree.push(treeNode) |
||||
|
} |
||||
|
return apiTree |
||||
|
}, |
||||
|
// 关联用户api关系 |
||||
|
async addAuthApi(row) { |
||||
|
const res = await getPolicyPathByAuthorityId({ |
||||
|
authorityId: this.row.authorityId |
||||
|
}) |
||||
|
this.activeUserId = this.row.authorityId |
||||
|
this.apiTreeIds = res.data.paths || [] |
||||
|
}, |
||||
|
// 关联关系确定 |
||||
|
async authApiEnter() { |
||||
|
const checkArr = this.$refs.apiTree.getCheckedKeys(true) |
||||
|
const res = await casbinPUpdata({ |
||||
|
authorityId: this.activeUserId, |
||||
|
paths: checkArr |
||||
|
}) |
||||
|
if (res.success) { |
||||
|
this.$message({ type: 'success', message: res.msg }) |
||||
|
} |
||||
|
} |
||||
|
}, |
||||
|
async created() { |
||||
|
// 获取api并整理成树结构 |
||||
|
const res2 = await getAllApis() |
||||
|
const apis = res2.data.apis |
||||
|
this.apiTreeData = this.buildApiTree(apis) |
||||
|
|
||||
|
const res = await getPolicyPathByAuthorityId({ |
||||
|
authorityId: this.row.authorityId |
||||
|
}) |
||||
|
this.activeUserId = this.row.authorityId |
||||
|
this.apiTreeIds = res.data.paths || [] |
||||
|
} |
||||
|
} |
||||
|
</script> |
||||
|
<style lang="scss"> |
||||
|
</style> |
@ -0,0 +1,76 @@ |
|||||
|
<template> |
||||
|
<div> |
||||
|
<div class="clearflex"> |
||||
|
<el-button @click="relation" class="fl-right" size="small" type="primary">确 定</el-button> |
||||
|
</div> |
||||
|
<el-tree |
||||
|
:data="menuTreeData" |
||||
|
:default-checked-keys="menuTreeIds" |
||||
|
:props="menuDefaultProps" |
||||
|
default-expand-all |
||||
|
highlight-current |
||||
|
node-key="ID" |
||||
|
ref="menuTree" |
||||
|
show-checkbox |
||||
|
></el-tree> |
||||
|
</div> |
||||
|
</template> |
||||
|
<script> |
||||
|
import { getBaseMenuTree, getMenuAuthority, addMenuAuthority } from '@/api/menu' |
||||
|
|
||||
|
export default { |
||||
|
name: 'Menus', |
||||
|
props: { |
||||
|
row: { |
||||
|
default: function() { |
||||
|
return {} |
||||
|
}, |
||||
|
type: Object |
||||
|
} |
||||
|
}, |
||||
|
data() { |
||||
|
return { |
||||
|
menuTreeData: [], |
||||
|
menuTreeIds: [], |
||||
|
menuDefaultProps: { |
||||
|
children: 'children', |
||||
|
label: 'nickName' |
||||
|
} |
||||
|
} |
||||
|
}, |
||||
|
methods: { |
||||
|
// 关联树 确认方法 |
||||
|
async relation() { |
||||
|
const checkArr = this.$refs.menuTree.getCheckedNodes(false, true) |
||||
|
const res = await addMenuAuthority({ |
||||
|
menus: checkArr, |
||||
|
authorityId: this.row.authorityId |
||||
|
}) |
||||
|
if (res.success) { |
||||
|
this.$message({ |
||||
|
type: 'success', |
||||
|
message: '添加成功!' |
||||
|
}) |
||||
|
} |
||||
|
} |
||||
|
}, |
||||
|
async created() { |
||||
|
// 获取所有菜单树 |
||||
|
const res = await getBaseMenuTree() |
||||
|
this.menuTreeData = res.data.menus |
||||
|
|
||||
|
const res1 = await getMenuAuthority({ authorityId: this.row.authorityId }) |
||||
|
const menus = res1.data.menus |
||||
|
const arr = [] |
||||
|
menus.map(item => { |
||||
|
// 防止直接选中父级造成全选 |
||||
|
if (!menus.some(same => same.parentId === item.menuId)) { |
||||
|
arr.push(Number(item.menuId)) |
||||
|
} |
||||
|
}) |
||||
|
this.menuTreeIds = arr |
||||
|
} |
||||
|
} |
||||
|
</script> |
||||
|
<style lang="scss"> |
||||
|
</style> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue