Open NM1024 opened 2 months ago
system/dept.js
export function getDeptSuperior(ids, exclude) { exclude = exclude !== undefined ? exclude : false // 修改后 const data = Array.isArray(ids) || ids.length === 0 ? ids : Array.of(ids) // 原来的,再某些情况下参数无法以数组的形式传递给后端 // const data = ids.length || ids.length === 0 ? ids : Array.of(ids) debugger return request({ url: 'api/dept/superior?exclude=' + exclude, method: 'post', data }) }
对应的后端APIsystem/rest/DeptController
system/rest/DeptController
@ApiOperation("查询部门:根据ID获取同级与上级数据") @PostMapping("/superior") @PreAuthorize("@el.check('user:list','dept:list','coreuser:list')") 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); }
system/dept.js
对应的后端API
system/rest/DeptController