feat: 增加用户选择模态框中的部门树节点深度限制,部门按名称检索

pull/113/head
子夜 2025-05-24 09:50:36 +08:00
parent c0a82df7f4
commit e39e5a4ed8
1 changed files with 12 additions and 6 deletions

View File

@ -30,6 +30,7 @@ interface DeptTreeNode {
key: string;
title: string;
children?: DeptTreeNode[];
name: string;
}
defineOptions({ name: 'UserSelectModal' });
@ -107,22 +108,26 @@ const transferDataSource = computed(() => {
const filteredDeptTree = computed(() => {
if (!deptSearchKeys.value) return deptTree.value;
const filterNode = (node: any): any => {
const title = node?.title?.toLowerCase();
const filterNode = (node: any, depth = 0): any => {
//
if (depth > 100) return null;
//
const name = node?.name?.toLowerCase();
const search = deptSearchKeys.value.toLowerCase();
//
if (title.includes(search)) {
//
if (name?.includes(search)) {
return {
...node,
children: node.children?.map((child: any) => filterNode(child)),
children: node.children,
};
}
//
if (node.children) {
const filteredChildren = node.children
.map((child: any) => filterNode(child))
.map((child: any) => filterNode(child, depth + 1))
.filter(Boolean);
if (filteredChildren.length > 0) {
@ -397,6 +402,7 @@ const processDeptNode = (node: any): DeptTreeNode => {
return {
key: String(node.id),
title: `${node.name} (${node.id})`,
name: node.name,
children: node.children?.map((child: any) => processDeptNode(child)),
};
};