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