From 7a9ccedadcd7f6a27d6c2a40b2083a899dae4732 Mon Sep 17 00:00:00 2001
From: 疯狂的狮子Li <15040126243@163.com>
Date: 星期三, 11 十二月 2024 15:30:44 +0800
Subject: [PATCH] update 优化 新增编辑用户 过滤禁用的部门

---
 src/views/system/user/index.vue |   35 +++++++++++++++++++++++++----------
 1 files changed, 25 insertions(+), 10 deletions(-)

diff --git a/src/views/system/user/index.vue b/src/views/system/user/index.vue
index 9597ca1..572f50c 100644
--- a/src/views/system/user/index.vue
+++ b/src/views/system/user/index.vue
@@ -154,7 +154,7 @@
             <el-form-item label="褰掑睘閮ㄩ棬" prop="deptId">
               <el-tree-select
                 v-model="form.deptId"
-                :data="deptOptions"
+                :data="enabledDeptOptions"
                 :props="{ value: 'id', label: 'label', children: 'children' }"
                 value-key="id"
                 placeholder="璇烽�夋嫨褰掑睘閮ㄩ棬"
@@ -287,7 +287,7 @@
 <script setup name="User" lang="ts">
 import api from '@/api/system/user';
 import { UserForm, UserQuery, UserVO } from '@/api/system/user/types';
-import { DeptVO } from '@/api/system/dept/types';
+import {DeptTreeVO, DeptVO} from '@/api/system/dept/types';
 import { RoleVO } from '@/api/system/role/types';
 import { PostQuery, PostVO } from '@/api/system/post/types';
 import { treeselect } from '@/api/system/dept';
@@ -307,7 +307,8 @@
 const total = ref(0);
 const dateRange = ref<[DateModelType, DateModelType]>(['', '']);
 const deptName = ref('');
-const deptOptions = ref<DeptVO[]>([]);
+const deptOptions = ref<DeptTreeVO[]>([]);
+const enabledDeptOptions = ref<DeptTreeVO[]>([]);
 const initPassword = ref<string>('');
 const postOptions = ref<PostVO[]>([]);
 const roleOptions = ref<RoleVO[]>([]);
@@ -431,12 +432,6 @@
   }
 );
 
-/** 鏌ヨ閮ㄩ棬涓嬫媺鏍戠粨鏋� */
-const getTreeSelect = async () => {
-  const res = await api.deptTreeSelect();
-  deptOptions.value = res.data;
-};
-
 /** 鏌ヨ鐢ㄦ埛鍒楄〃 */
 const getList = async () => {
   loading.value = true;
@@ -444,6 +439,26 @@
   loading.value = false;
   userList.value = res.rows;
   total.value = res.total;
+};
+
+/** 鏌ヨ閮ㄩ棬涓嬫媺鏍戠粨鏋� */
+const getDeptTree = async () => {
+  const res = await api.deptTreeSelect();
+  deptOptions.value = res.data;
+  enabledDeptOptions.value = filterDisabledDept(res.data);
+};
+
+/** 杩囨护绂佺敤鐨勯儴闂� */
+const filterDisabledDept = (deptList: DeptTreeVO[]) => {
+  return deptList.filter(dept => {
+    if (dept.disabled) {
+      return false;
+    }
+    if (dept.children && dept.children.length) {
+      dept.children = filterDisabledDept(dept.children);
+    }
+    return true;
+  });
 };
 
 /** 鑺傜偣鍗曞嚮浜嬩欢 */
@@ -643,7 +658,7 @@
   form.value.status = '1';
 };
 onMounted(() => {
-  getTreeSelect(); // 鍒濆鍖栭儴闂ㄦ暟鎹�
+  getDeptTree(); // 鍒濆鍖栭儴闂ㄦ暟鎹�
   getList(); // 鍒濆鍖栧垪琛ㄦ暟鎹�
   proxy?.getConfigKey('sys.user.initPassword').then((response) => {
     initPassword.value = response.data;

--
Gitblit v1.9.3