Przeglądaj źródła

用户管理过滤掉已禁用部门

RuoYi 1 rok temu
rodzic
commit
7216b56a56

+ 16 - 0
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/vo/TreeSelect.java

@@ -4,6 +4,8 @@ import java.io.Serializable;
4
 import java.util.List;
4
 import java.util.List;
5
 import java.util.stream.Collectors;
5
 import java.util.stream.Collectors;
6
 import com.fasterxml.jackson.annotation.JsonInclude;
6
 import com.fasterxml.jackson.annotation.JsonInclude;
7
+import com.ruoyi.common.core.constant.UserConstants;
8
+import com.ruoyi.common.core.utils.StringUtils;
7
 import com.ruoyi.system.api.domain.SysDept;
9
 import com.ruoyi.system.api.domain.SysDept;
8
 import com.ruoyi.system.domain.SysMenu;
10
 import com.ruoyi.system.domain.SysMenu;
9
 
11
 
@@ -22,6 +24,9 @@ public class TreeSelect implements Serializable
22
     /** 节点名称 */
24
     /** 节点名称 */
23
     private String label;
25
     private String label;
24
 
26
 
27
+    /** 节点禁用 */
28
+    private boolean disabled = false;
29
+
25
     /** 子节点 */
30
     /** 子节点 */
26
     @JsonInclude(JsonInclude.Include.NON_EMPTY)
31
     @JsonInclude(JsonInclude.Include.NON_EMPTY)
27
     private List<TreeSelect> children;
32
     private List<TreeSelect> children;
@@ -35,6 +40,7 @@ public class TreeSelect implements Serializable
35
     {
40
     {
36
         this.id = dept.getDeptId();
41
         this.id = dept.getDeptId();
37
         this.label = dept.getDeptName();
42
         this.label = dept.getDeptName();
43
+        this.disabled = StringUtils.equals(UserConstants.DEPT_DISABLE, dept.getStatus());
38
         this.children = dept.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
44
         this.children = dept.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
39
     }
45
     }
40
 
46
 
@@ -65,6 +71,16 @@ public class TreeSelect implements Serializable
65
         this.label = label;
71
         this.label = label;
66
     }
72
     }
67
 
73
 
74
+    public boolean isDisabled()
75
+    {
76
+        return disabled;
77
+    }
78
+
79
+    public void setDisabled(boolean disabled)
80
+    {
81
+        this.disabled = disabled;
82
+    }
83
+
68
     public List<TreeSelect> getChildren()
84
     public List<TreeSelect> getChildren()
69
     {
85
     {
70
         return children;
86
         return children;

+ 17 - 2
ruoyi-ui/src/views/system/user/index.vue

@@ -105,7 +105,7 @@
105
           </el-col>
105
           </el-col>
106
           <el-col :span="12">
106
           <el-col :span="12">
107
             <el-form-item label="归属部门" prop="deptId">
107
             <el-form-item label="归属部门" prop="deptId">
108
-              <treeselect v-model="form.deptId" :options="deptOptions" :show-count="true" placeholder="请选择归属部门" />
108
+              <treeselect v-model="form.deptId" :options="enabledDeptOptions" :show-count="true" placeholder="请选择归属部门" />
109
             </el-form-item>
109
             </el-form-item>
110
           </el-col>
110
           </el-col>
111
         </el-row>
111
         </el-row>
@@ -230,8 +230,10 @@ export default {
230
       userList: null,
230
       userList: null,
231
       // 弹出层标题
231
       // 弹出层标题
232
       title: "",
232
       title: "",
233
-      // 部门树选项
233
+      // 所有部门树选项
234
       deptOptions: undefined,
234
       deptOptions: undefined,
235
+      // 过滤掉已禁用部门树选项
236
+      enabledDeptOptions: undefined,
235
       // 是否显示弹出层
237
       // 是否显示弹出层
236
       open: false,
238
       open: false,
237
       // 部门名称
239
       // 部门名称
@@ -343,6 +345,19 @@ export default {
343
     getDeptTree() {
345
     getDeptTree() {
344
       deptTreeSelect().then(response => {
346
       deptTreeSelect().then(response => {
345
         this.deptOptions = response.data;
347
         this.deptOptions = response.data;
348
+        this.enabledDeptOptions = this.filterDisabledDept(JSON.parse(JSON.stringify(response.data)));
349
+      });
350
+    },
351
+    // 过滤禁用的部门
352
+    filterDisabledDept(deptList) {
353
+      return deptList.filter(dept => {
354
+        if (dept.disabled) {
355
+          return false;
356
+        }
357
+        if (dept.children && dept.children.length) {
358
+          dept.children = this.filterDisabledDept(dept.children);
359
+        }
360
+        return true;
346
       });
361
       });
347
     },
362
     },
348
     // 筛选节点
363
     // 筛选节点