Commit 9f4918cc14064ea625f75dc616c7a1dc07815b42
1 parent
8c7aca25
修改上级部门(选择项排除本身和下级)
Showing
3 changed files
with
38 additions
and
9 deletions
ruoyi-ui/src/api/system/dept.js
| ... | ... | @@ -9,6 +9,14 @@ export function listDept(query) { |
| 9 | 9 | }) |
| 10 | 10 | } |
| 11 | 11 | |
| 12 | +// 查询部门列表(排除节点) | |
| 13 | +export function listDeptExcludeChild(deptId) { | |
| 14 | + return request({ | |
| 15 | + url: '/system/dept/list/exclude/' + deptId, | |
| 16 | + method: 'get' | |
| 17 | + }) | |
| 18 | +} | |
| 19 | + | |
| 12 | 20 | // 查询部门详细 |
| 13 | 21 | export function getDept(deptId) { |
| 14 | 22 | return request({ | ... | ... |
ruoyi-ui/src/views/system/dept/index.vue
| ... | ... | @@ -138,7 +138,7 @@ |
| 138 | 138 | </template> |
| 139 | 139 | |
| 140 | 140 | <script> |
| 141 | -import { listDept, getDept, delDept, addDept, updateDept } from "@/api/system/dept"; | |
| 141 | +import { listDept, getDept, delDept, addDept, updateDept, listDeptExcludeChild } from "@/api/system/dept"; | |
| 142 | 142 | import Treeselect from "@riophae/vue-treeselect"; |
| 143 | 143 | import "@riophae/vue-treeselect/dist/vue-treeselect.css"; |
| 144 | 144 | |
| ... | ... | @@ -220,12 +220,6 @@ export default { |
| 220 | 220 | children: node.children |
| 221 | 221 | }; |
| 222 | 222 | }, |
| 223 | - /** 查询部门下拉树结构 */ | |
| 224 | - getTreeselect() { | |
| 225 | - listDept().then(response => { | |
| 226 | - this.deptOptions = this.handleTree(response.data, "deptId"); | |
| 227 | - }); | |
| 228 | - }, | |
| 229 | 223 | // 字典状态字典翻译 |
| 230 | 224 | statusFormat(row, column) { |
| 231 | 225 | return this.selectDictLabel(this.statusOptions, row.status); |
| ... | ... | @@ -256,22 +250,26 @@ export default { |
| 256 | 250 | /** 新增按钮操作 */ |
| 257 | 251 | handleAdd(row) { |
| 258 | 252 | this.reset(); |
| 259 | - this.getTreeselect(); | |
| 260 | 253 | if (row != undefined) { |
| 261 | 254 | this.form.parentId = row.deptId; |
| 262 | 255 | } |
| 263 | 256 | this.open = true; |
| 264 | 257 | this.title = "添加部门"; |
| 258 | + listDept().then(response => { | |
| 259 | + this.deptOptions = this.handleTree(response.data, "deptId"); | |
| 260 | + }); | |
| 265 | 261 | }, |
| 266 | 262 | /** 修改按钮操作 */ |
| 267 | 263 | handleUpdate(row) { |
| 268 | 264 | this.reset(); |
| 269 | - this.getTreeselect(); | |
| 270 | 265 | getDept(row.deptId).then(response => { |
| 271 | 266 | this.form = response.data; |
| 272 | 267 | this.open = true; |
| 273 | 268 | this.title = "修改部门"; |
| 274 | 269 | }); |
| 270 | + listDeptExcludeChild(row.deptId).then(response => { | |
| 271 | + this.deptOptions = this.handleTree(response.data, "deptId"); | |
| 272 | + }); | |
| 275 | 273 | }, |
| 276 | 274 | /** 提交按钮 */ |
| 277 | 275 | submitForm: function() { | ... | ... |
ruoyi/src/main/java/com/ruoyi/project/system/controller/SysDeptController.java
| 1 | 1 | package com.ruoyi.project.system.controller; |
| 2 | 2 | |
| 3 | +import java.util.Iterator; | |
| 3 | 4 | import java.util.List; |
| 5 | +import org.apache.commons.lang3.ArrayUtils; | |
| 4 | 6 | import org.springframework.beans.factory.annotation.Autowired; |
| 5 | 7 | import org.springframework.security.access.prepost.PreAuthorize; |
| 6 | 8 | import org.springframework.validation.annotation.Validated; |
| ... | ... | @@ -46,6 +48,27 @@ public class SysDeptController extends BaseController |
| 46 | 48 | } |
| 47 | 49 | |
| 48 | 50 | /** |
| 51 | + * 查询部门列表(排除节点) | |
| 52 | + */ | |
| 53 | + @PreAuthorize("@ss.hasPermi('system:dept:list')") | |
| 54 | + @GetMapping("/list/exclude/{deptId}") | |
| 55 | + public AjaxResult excludeChild(@PathVariable(value = "deptId", required = false) Long deptId) | |
| 56 | + { | |
| 57 | + List<SysDept> depts = deptService.selectDeptList(new SysDept()); | |
| 58 | + Iterator<SysDept> it = depts.iterator(); | |
| 59 | + while (it.hasNext()) | |
| 60 | + { | |
| 61 | + SysDept d = (SysDept) it.next(); | |
| 62 | + if (d.getDeptId().intValue() == deptId | |
| 63 | + || ArrayUtils.contains(StringUtils.split(d.getAncestors(), ","), deptId + "")) | |
| 64 | + { | |
| 65 | + it.remove(); | |
| 66 | + } | |
| 67 | + } | |
| 68 | + return AjaxResult.success(depts); | |
| 69 | + } | |
| 70 | + | |
| 71 | + /** | |
| 49 | 72 | * 根据部门编号获取详细信息 |
| 50 | 73 | */ |
| 51 | 74 | @PreAuthorize("@ss.hasPermi('system:dept:query')") | ... | ... |