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,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 | export function getDept(deptId) { | 21 | export function getDept(deptId) { |
| 14 | return request({ | 22 | return request({ |
ruoyi-ui/src/views/system/dept/index.vue
| @@ -138,7 +138,7 @@ | @@ -138,7 +138,7 @@ | ||
| 138 | </template> | 138 | </template> |
| 139 | 139 | ||
| 140 | <script> | 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 | import Treeselect from "@riophae/vue-treeselect"; | 142 | import Treeselect from "@riophae/vue-treeselect"; |
| 143 | import "@riophae/vue-treeselect/dist/vue-treeselect.css"; | 143 | import "@riophae/vue-treeselect/dist/vue-treeselect.css"; |
| 144 | 144 | ||
| @@ -220,12 +220,6 @@ export default { | @@ -220,12 +220,6 @@ export default { | ||
| 220 | children: node.children | 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 | statusFormat(row, column) { | 224 | statusFormat(row, column) { |
| 231 | return this.selectDictLabel(this.statusOptions, row.status); | 225 | return this.selectDictLabel(this.statusOptions, row.status); |
| @@ -256,22 +250,26 @@ export default { | @@ -256,22 +250,26 @@ export default { | ||
| 256 | /** 新增按钮操作 */ | 250 | /** 新增按钮操作 */ |
| 257 | handleAdd(row) { | 251 | handleAdd(row) { |
| 258 | this.reset(); | 252 | this.reset(); |
| 259 | - this.getTreeselect(); | ||
| 260 | if (row != undefined) { | 253 | if (row != undefined) { |
| 261 | this.form.parentId = row.deptId; | 254 | this.form.parentId = row.deptId; |
| 262 | } | 255 | } |
| 263 | this.open = true; | 256 | this.open = true; |
| 264 | this.title = "添加部门"; | 257 | this.title = "添加部门"; |
| 258 | + listDept().then(response => { | ||
| 259 | + this.deptOptions = this.handleTree(response.data, "deptId"); | ||
| 260 | + }); | ||
| 265 | }, | 261 | }, |
| 266 | /** 修改按钮操作 */ | 262 | /** 修改按钮操作 */ |
| 267 | handleUpdate(row) { | 263 | handleUpdate(row) { |
| 268 | this.reset(); | 264 | this.reset(); |
| 269 | - this.getTreeselect(); | ||
| 270 | getDept(row.deptId).then(response => { | 265 | getDept(row.deptId).then(response => { |
| 271 | this.form = response.data; | 266 | this.form = response.data; |
| 272 | this.open = true; | 267 | this.open = true; |
| 273 | this.title = "修改部门"; | 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 | submitForm: function() { | 275 | submitForm: function() { |
ruoyi/src/main/java/com/ruoyi/project/system/controller/SysDeptController.java
| 1 | package com.ruoyi.project.system.controller; | 1 | package com.ruoyi.project.system.controller; |
| 2 | 2 | ||
| 3 | +import java.util.Iterator; | ||
| 3 | import java.util.List; | 4 | import java.util.List; |
| 5 | +import org.apache.commons.lang3.ArrayUtils; | ||
| 4 | import org.springframework.beans.factory.annotation.Autowired; | 6 | import org.springframework.beans.factory.annotation.Autowired; |
| 5 | import org.springframework.security.access.prepost.PreAuthorize; | 7 | import org.springframework.security.access.prepost.PreAuthorize; |
| 6 | import org.springframework.validation.annotation.Validated; | 8 | import org.springframework.validation.annotation.Validated; |
| @@ -46,6 +48,27 @@ public class SysDeptController extends BaseController | @@ -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 | @PreAuthorize("@ss.hasPermi('system:dept:query')") | 74 | @PreAuthorize("@ss.hasPermi('system:dept:query')") |