|
|
@@ -15,17 +15,17 @@
|
|
|
ref="tree"
|
|
|
show-checkbox
|
|
|
:data="authData"
|
|
|
- node-key="menuId"
|
|
|
+ node-key="id"
|
|
|
:default-expand-all="true"
|
|
|
- :props="{ label: 'title' }"
|
|
|
+ :props="{ label: 'name' }"
|
|
|
:default-checked-keys="checkedKeys"
|
|
|
>
|
|
|
- <template v-slot="{ data }">
|
|
|
+ <!-- <template v-slot="{ data }">
|
|
|
<span>
|
|
|
<i :class="data.icon"></i>
|
|
|
- <span> {{ data.title }}</span>
|
|
|
+ <span> {{ data.name }}</span>
|
|
|
</span>
|
|
|
- </template>
|
|
|
+ </template> -->
|
|
|
</el-tree>
|
|
|
</el-scrollbar>
|
|
|
<template v-slot:footer>
|
|
|
@@ -39,6 +39,7 @@
|
|
|
|
|
|
<script>
|
|
|
import { listRoleMenus, updateRoleMenus } from '@/api/system/role';
|
|
|
+ import { listMenus } from '@/api/system/menu';
|
|
|
|
|
|
export default {
|
|
|
props: {
|
|
|
@@ -56,35 +57,44 @@
|
|
|
// 提交状态
|
|
|
loading: false,
|
|
|
// 角色权限选中的keys
|
|
|
- checkedKeys: []
|
|
|
+ checkedKeys: [],
|
|
|
+ ids: []
|
|
|
};
|
|
|
},
|
|
|
methods: {
|
|
|
+ async getMenus() {
|
|
|
+ this.authData = [];
|
|
|
+ const res = await listMenus();
|
|
|
+ this.authData = this.$util.toTreeData({
|
|
|
+ data: res,
|
|
|
+ idKey: 'id',
|
|
|
+ pidKey: 'parentId'
|
|
|
+ });
|
|
|
+ // 回显选中的数据;
|
|
|
+ const cks = [];
|
|
|
+ this.$util.eachTreeData(this.authData, (d) => {
|
|
|
+ let falg = this.ids.indexOf(d.id) >= 0; // 检查是否选中该数据; 选中则保留flg=
|
|
|
+ if (falg && !d.children?.length) {
|
|
|
+ cks.push(d.id);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ this.checkedKeys = cks;
|
|
|
+ },
|
|
|
/* 查询权限数据 */
|
|
|
query() {
|
|
|
- this.authData = [];
|
|
|
- this.checkedKeys = [];
|
|
|
if (!this.data) {
|
|
|
return;
|
|
|
}
|
|
|
this.authLoading = true;
|
|
|
- listRoleMenus(this.data.roleId)
|
|
|
+ listRoleMenus(this.data.id)
|
|
|
.then((data) => {
|
|
|
+ this.ids = [];
|
|
|
+ if (data && data.length > 0) {
|
|
|
+ this.ids = data.map((item) => item.resourceId);
|
|
|
+ }
|
|
|
+ this.getMenus();
|
|
|
this.authLoading = false;
|
|
|
// 转成树形结构的数据
|
|
|
- this.authData = this.$util.toTreeData({
|
|
|
- data: data,
|
|
|
- idKey: 'menuId',
|
|
|
- pidKey: 'parentId'
|
|
|
- });
|
|
|
- // 回显选中的数据
|
|
|
- const cks = [];
|
|
|
- this.$util.eachTreeData(this.authData, (d) => {
|
|
|
- if (d.checked && !d.children?.length) {
|
|
|
- cks.push(d.menuId);
|
|
|
- }
|
|
|
- });
|
|
|
- this.checkedKeys = cks;
|
|
|
})
|
|
|
.catch((e) => {
|
|
|
this.authLoading = false;
|
|
|
@@ -97,10 +107,15 @@
|
|
|
const ids = this.$refs.tree
|
|
|
.getCheckedKeys()
|
|
|
.concat(this.$refs.tree.getHalfCheckedKeys());
|
|
|
- updateRoleMenus(this.data.roleId, ids)
|
|
|
+ console.log(ids);
|
|
|
+
|
|
|
+ updateRoleMenus({
|
|
|
+ roleId: this.data.id,
|
|
|
+ resourceIds: ids
|
|
|
+ })
|
|
|
.then((msg) => {
|
|
|
this.loading = false;
|
|
|
- this.$message.success(msg);
|
|
|
+ this.$message.success(msg.data);
|
|
|
this.updateVisible(false);
|
|
|
})
|
|
|
.catch((e) => {
|