代码优化,避免【菜单、部门】移动节点时出现PID数据环形问题:https://github.com/elunez/eladmin/issues/803
This commit is contained in:
parent
2572c1600c
commit
47806c6cc4
@ -161,10 +161,10 @@ export default {
|
||||
}
|
||||
},
|
||||
getSupDepts(id) {
|
||||
crudDept.getDeptSuperior(id).then(res => {
|
||||
const date = res.content
|
||||
this.buildDepts(date)
|
||||
this.depts = date
|
||||
crudDept.getDeptSuperior(id, true).then(res => {
|
||||
const data = res.content
|
||||
this.buildDepts(data)
|
||||
this.depts = data
|
||||
})
|
||||
},
|
||||
buildDepts(depts) {
|
||||
@ -224,7 +224,7 @@ export default {
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
}).then(() => {
|
||||
crudDept.edit(data).then(res => {
|
||||
crudDept.edit(data).then(() => {
|
||||
this.crud.notify(this.dict.label.dept_status[val] + '成功', CRUD.NOTIFICATION_TYPE.SUCCESS)
|
||||
}).catch(err => {
|
||||
data.enabled = !data.enabled
|
||||
@ -234,7 +234,7 @@ export default {
|
||||
data.enabled = !data.enabled
|
||||
})
|
||||
},
|
||||
checkboxT(row, rowIndex) {
|
||||
checkboxT(row) {
|
||||
return row.id !== 1
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
@ -65,11 +66,21 @@ public class DeptController {
|
||||
@ApiOperation("查询部门:根据ID获取同级与上级数据")
|
||||
@PostMapping("/superior")
|
||||
@PreAuthorize("@el.check('user:list','dept:list')")
|
||||
public ResponseEntity<Object> getDeptSuperior(@RequestBody List<Long> ids) {
|
||||
public ResponseEntity<Object> getDeptSuperior(@RequestBody List<Long> ids,
|
||||
@RequestParam(defaultValue = "false") Boolean exclude) {
|
||||
Set<Dept> deptSet = new LinkedHashSet<>();
|
||||
for (Long id : ids) {
|
||||
Dept dept = deptService.findById(id);
|
||||
List<Dept> depts = deptService.getSuperior(dept, new ArrayList<>());
|
||||
if(exclude){
|
||||
for (Dept data : depts) {
|
||||
if(data.getId().equals(dept.getPid())) {
|
||||
data.setSubCount(data.getSubCount() - 1);
|
||||
}
|
||||
}
|
||||
// 编辑部门时不显示自己以及自己下级的数据,避免出现PID数据环形问题
|
||||
depts = depts.stream().filter(i -> !ids.contains(i.getId())).collect(Collectors.toList());
|
||||
}
|
||||
deptSet.addAll(depts);
|
||||
}
|
||||
return new ResponseEntity<>(deptService.buildTree(new ArrayList<>(deptSet)),HttpStatus.OK);
|
||||
|
@ -41,7 +41,6 @@ import java.util.stream.Collectors;
|
||||
* @author Zheng Jie
|
||||
* @date 2018-12-03
|
||||
*/
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@Api(tags = "系统:菜单管理")
|
||||
@ -101,8 +100,16 @@ public class MenuController {
|
||||
if(CollectionUtil.isNotEmpty(ids)){
|
||||
for (Long id : ids) {
|
||||
Menu menu = menuService.findById(id);
|
||||
menus.addAll(menuService.getSuperior(menu, new ArrayList<>()));
|
||||
List<Menu> menuList = menuService.getSuperior(menu, new ArrayList<>());
|
||||
for (Menu data : menuList) {
|
||||
if(data.getId().equals(menu.getPid())) {
|
||||
data.setSubCount(data.getSubCount() - 1);
|
||||
}
|
||||
}
|
||||
menus.addAll(menuList);
|
||||
}
|
||||
// 编辑菜单时不显示自己以及自己下级的数据,避免出现PID数据环形问题
|
||||
menus = menus.stream().filter(i -> !ids.contains(i.getId())).collect(Collectors.toSet());
|
||||
return new ResponseEntity<>(menuService.buildTree(new ArrayList<>(menus)),HttpStatus.OK);
|
||||
}
|
||||
return new ResponseEntity<>(menuService.getMenus(null),HttpStatus.OK);
|
||||
|
Loading…
Reference in New Issue
Block a user