From 7a9ccedadcd7f6a27d6c2a40b2083a899dae4732 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90Li?= <15040126243@163.com> Date: Wed, 11 Dec 2024 15:30:44 +0800 Subject: [PATCH] =?UTF-8?q?update=20=E4=BC=98=E5=8C=96=20=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E7=BC=96=E8=BE=91=E7=94=A8=E6=88=B7=20=E8=BF=87?= =?UTF-8?q?=E6=BB=A4=E7=A6=81=E7=94=A8=E7=9A=84=E9=83=A8=E9=97=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/system/dept/types.ts | 12 +++++++++++ src/api/system/user/index.ts | 4 ++-- src/views/system/user/index.vue | 35 +++++++++++++++++++++++---------- 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 @@ -28,6 +28,18 @@ export interface DeptVO extends BaseEntity { menuId: string | number; } +/** + * 部门类型 + */ +export interface DeptTreeVO extends BaseEntity { + id: number | string; + label: string; + parentId: number | string; + weight: number; + children: DeptTreeVO[]; + disabled: boolean; +} + /** * 部门表单类型 */ 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 listUserByDeptId = (deptId: string | number): AxiosPromise => { +export const deptTreeSelect = (): AxiosPromise => { 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 @@ 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 multiple = ref(true); const total = ref(0); const dateRange = ref<[DateModelType, DateModelType]>(['', '']); const deptName = ref(''); -const deptOptions = ref([]); +const deptOptions = ref([]); +const enabledDeptOptions = ref([]); const initPassword = ref(''); const postOptions = ref([]); const roleOptions = ref([]); @@ -431,12 +432,6 @@ watchEffect( } ); -/** 查询部门下拉树结构 */ -const getTreeSelect = async () => { - const res = await api.deptTreeSelect(); - deptOptions.value = res.data; -}; - /** 查询用户列表 */ const getList = async () => { loading.value = true; @@ -446,6 +441,26 @@ const getList = async () => { 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; + }); +}; + /** 节点单击事件 */ const handleNodeClick = (data: DeptVO) => { queryParams.value.deptId = data.id; @@ -643,7 +658,7 @@ const resetForm = () => { form.value.status = '1'; }; onMounted(() => { - getTreeSelect(); // 初始化部门数据 + getDeptTree(); // 初始化部门数据 getList(); // 初始化列表数据 proxy?.getConfigKey('sys.user.initPassword').then((response) => { initPassword.value = response.data;