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 +++++++++++++++++++++++++----------
 src/api/system/dept/types.ts    |   12 ++++++++++++
 src/api/system/user/index.ts    |    4 ++--
 3 files changed, 39 insertions(+), 12 deletions(-)

diff --git a/src/api/system/dept/types.ts b/src/api/system/dept/types.ts
index 494745c..adaefd2 100644
--- a/src/api/system/dept/types.ts
+++ b/src/api/system/dept/types.ts
@@ -29,6 +29,18 @@
 }
 
 /**
+ * 閮ㄩ棬绫诲瀷
+ */
+export interface DeptTreeVO extends BaseEntity {
+  id: number | string;
+  label: string;
+  parentId: number | string;
+  weight: number;
+  children: DeptTreeVO[];
+  disabled: boolean;
+}
+
+/**
  * 閮ㄩ棬琛ㄥ崟绫诲瀷
  */
 export interface DeptForm {
diff --git a/src/api/system/user/index.ts b/src/api/system/user/index.ts
index 25c7884..0867c48 100644
--- a/src/api/system/user/index.ts
+++ b/src/api/system/user/index.ts
@@ -1,4 +1,4 @@
-import { DeptVO } from './../dept/types';
+import {DeptTreeVO, DeptVO} from './../dept/types';
 import { RoleVO } from '@/api/system/role/types';
 import request from '@/utils/request';
 import { AxiosPromise } from 'axios';
@@ -202,7 +202,7 @@
 /**
  * 鏌ヨ閮ㄩ棬涓嬫媺鏍戠粨鏋�
  */
-export const deptTreeSelect = (): AxiosPromise<DeptVO[]> => {
+export const deptTreeSelect = (): AxiosPromise<DeptTreeVO[]> => {
   return request({
     url: '/system/user/deptTree',
     method: 'get'
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