[代码优化](v2.6):角色管理分配菜单,菜单节点选择优化
1、选中主菜单,默认选中所有子菜单 2、取消主菜单,默认取消所有子菜单 close https://github.com/elunez/eladmin/issues/449
This commit is contained in:
@@ -24,6 +24,13 @@ export function getMenuSuperior(ids) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getChild(id) {
|
||||||
|
return request({
|
||||||
|
url: 'api/menus/child?id=' + id,
|
||||||
|
method: 'get'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
export function buildMenus() {
|
export function buildMenus() {
|
||||||
return request({
|
return request({
|
||||||
url: 'api/menus/build',
|
url: 'api/menus/build',
|
||||||
@@ -55,4 +62,4 @@ export function edit(data) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export default { add, edit, del, getMenusTree, getMenuSuperior, getMenus }
|
export default { add, edit, del, getMenusTree, getMenuSuperior, getMenus, getChild }
|
||||||
|
|||||||
@@ -120,7 +120,7 @@
|
|||||||
<script>
|
<script>
|
||||||
import crudRoles from '@/api/system/role'
|
import crudRoles from '@/api/system/role'
|
||||||
import { getDepts, getDeptSuperior } from '@/api/system/dept'
|
import { getDepts, getDeptSuperior } from '@/api/system/dept'
|
||||||
import { getMenusTree } from '@/api/system/menu'
|
import { getMenusTree, getChild } from '@/api/system/menu'
|
||||||
import CRUD, { presenter, header, form, crud } from '@crud/crud'
|
import CRUD, { presenter, header, form, crud } from '@crud/crud'
|
||||||
import rrOperation from '@crud/RR.operation'
|
import rrOperation from '@crud/RR.operation'
|
||||||
import crudOperation from '@crud/CRUD.operation'
|
import crudOperation from '@crud/CRUD.operation'
|
||||||
@@ -228,13 +228,23 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
menuChange(menu) {
|
menuChange(menu) {
|
||||||
// 判断是否在 menuIds 中,如果存在则删除,否则添加
|
// 获取该节点的所有子节点,id 包含自身
|
||||||
const index = this.menuIds.indexOf(menu.id)
|
getChild(menu.id).then(childIds => {
|
||||||
if (index !== -1) {
|
// 判断是否在 menuIds 中,如果存在则删除,否则添加
|
||||||
this.menuIds.splice(index, 1)
|
if (this.menuIds.indexOf(menu.id) !== -1) {
|
||||||
} else {
|
for (let i = 0; i < childIds.length; i++) {
|
||||||
this.menuIds.push(menu.id)
|
const index = this.menuIds.indexOf(childIds[i])
|
||||||
}
|
if (index !== -1) {
|
||||||
|
this.menuIds.splice(index, 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (let i = 0; i < childIds.length; i++) {
|
||||||
|
this.menuIds.push(childIds[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.$refs.menu.setCheckedKeys(this.menuIds)
|
||||||
|
})
|
||||||
},
|
},
|
||||||
// 保存菜单
|
// 保存菜单
|
||||||
saveMenu() {
|
saveMenu() {
|
||||||
|
|||||||
Reference in New Issue
Block a user