|
31 | 31 | </el-col>
|
32 | 32 |
|
33 | 33 |
|
34 |
| - <!--左侧菜单按钮权限树--> |
| 34 | + <!--按钮权限树--> |
35 | 35 | <el-col :span="8">
|
36 | 36 | <el-card class="box-card">
|
37 | 37 | <div slot="header">
|
38 | 38 | <div class="title-box">
|
39 |
| - <span>菜单、按钮权限元数据</span> |
| 39 | + <span>按钮权限元数据</span> |
40 | 40 | <el-tooltip content="添加顶级菜单" placement="top">
|
41 | 41 | <el-button style="font-size: 25px;" type="text" @click="handleAddTopNode(permType.MENU)"
|
42 | 42 | icon="el-icon-circle-plus-outline" circle></el-button>
|
|
47 | 47 | <el-input class="mgb-15" placeholder="输入关键字进行过滤" v-model="filterMenuButtonText">
|
48 | 48 | </el-input>
|
49 | 49 | <el-tree draggable ref="menuButtonTreeRef" :filter-node-method="filterNode" @node-drop="handleMenuButtonDrop"
|
50 |
| - :data="menuButtonTree" :props="treeProps" node-key="pid" default-expand-all> |
| 50 | + :data="buttonPermissionTree" :props="treeProps" node-key="pid" default-expand-all> |
51 | 51 | <span class="custom-tree-node" slot-scope="{ node, data }">
|
52 | 52 | <span>
|
53 |
| - <span class="mgl-10">{{ node.label }}</span> |
| 53 | + <span class="mgl-10">{{ data.pname }}</span> |
54 | 54 | <el-tag v-if="data.ptype==1" type="success" size="mini">菜单</el-tag>
|
55 | 55 | <el-tag v-else-if="data.ptype==2" type="warning" size="mini"><i class="el-icon-rank"></i>按钮</el-tag>
|
56 | 56 | <i class="el-icon-rank mgl-10"></i>
|
|
190 | 190 | menuPermValSet: new Set(),
|
191 | 191 | buttonPermList: [],
|
192 | 192 | apiPermList: [],
|
| 193 | + btnPermMap:{},//按parent字段分组的map |
| 194 | +
|
| 195 | + menuPermissionTree: [],//菜单权限树 |
| 196 | + buttonPermissionTree: [],//菜单权限树 |
| 197 | +
|
193 | 198 |
|
194 |
| - menuPermissionTree: [], |
195 | 199 | permType,
|
196 | 200 | filterMenuButtonText: '',
|
197 | 201 | filterApiText: '',
|
|
264 | 268 | //获取后台权限数据
|
265 | 269 | initData() {
|
266 | 270 | listAllPermissions().then(res => {
|
| 271 | + this.btnPermMap = res.data.btnPermMap |
267 | 272 | this.menuPermList = res.data.permMap[permType.MENU]
|
268 | 273 | this.buttonPermList = res.data.permMap[permType.BUTTON]
|
269 | 274 | this.apiPermList = res.data.permMap[permType.API]
|
270 | 275 | this.menuPermValSet = new Set(this.menuPermList.map(p=>p.pval))
|
271 |
| - console.log(this.menuPermValSet) |
| 276 | +
|
| 277 | +
|
272 | 278 | //显示菜单权限树
|
273 | 279 | this.generateMenuPermissionTree()
|
| 280 | + //显示按钮权限树 |
| 281 | + this.generateButtonPermissionTree() |
274 | 282 | })
|
275 | 283 | },
|
276 | 284 |
|
|
473 | 481 | this.handleNodeDrop(permType.API, draggingNode, dropNode, dropType, event)
|
474 | 482 | },
|
475 | 483 |
|
| 484 | + /** |
| 485 | + * 根据菜单树,生成按钮权限树 |
| 486 | + */ |
| 487 | + generateButtonPermissionTree() { |
| 488 | + console.log("this.btnPermMap: %o",JSON.stringify(this.btnPermMap)) |
| 489 | + console.log("==this.menuPermissionTree: "+JSON.stringify(this.menuPermissionTree)) |
| 490 | + this.buttonPermissionTree = this.mapToButtonPermissionTree(this.menuPermissionTree) |
| 491 | + console.log("this.buttonPermissionTree: %o",JSON.stringify(this.buttonPermissionTree)) |
| 492 | + }, |
| 493 | +
|
| 494 | + /** |
| 495 | + * 根据菜单树,生成按钮权限树 |
| 496 | + * @param menuPermissionTree 菜单树 |
| 497 | + */ |
| 498 | + mapToButtonPermissionTree(menuPermissionTree) { |
| 499 | + return menuPermissionTree.map(perm => { |
| 500 | +
|
| 501 | + if(perm){ |
| 502 | + if(!perm.children){ |
| 503 | + perm.children = [] |
| 504 | + } |
| 505 | + if(perm.ptype==permType.MENU){ |
| 506 | + let btnPerms = this.btnPermMap[perm.pval] |
| 507 | + if(btnPerms){ |
| 508 | + btnPerms.forEach(p=>{ |
| 509 | + perm.children.push(p) |
| 510 | + }) |
| 511 | + } |
| 512 | + } |
| 513 | + if(perm.children&&perm.children.length>0){ |
| 514 | + this.mapToButtonPermissionTree(perm.children) |
| 515 | + } |
| 516 | + } |
| 517 | + return perm; |
| 518 | +
|
| 519 | + }) |
| 520 | + }, |
| 521 | +
|
476 | 522 |
|
477 | 523 | /**
|
478 | 524 | * 根据前端定义的路由表,生成菜单权限列表
|
|
0 commit comments