mirror of
https://gitee.com/dapppp/ruoyi-plus-vben5.git
synced 2026-03-20 04:35:35 +08:00
fix(用户管理): 修复部门树搜索后子节点丢失的问题
搜索部门树时,由于直接修改了原始树数据导致子节点被清空。通过深拷贝部门树数据并显式清空搜索结果的子节点,确保原始树结构不受影响。
This commit is contained in:
@@ -5,7 +5,7 @@ import type { DeptTree } from '#/api/system/user/model';
|
|||||||
|
|
||||||
import { computed, onMounted, ref } from 'vue';
|
import { computed, onMounted, ref } from 'vue';
|
||||||
|
|
||||||
import { listToTree, treeToList } from '@vben/utils';
|
import { cloneDeep, listToTree, treeToList } from '@vben/utils';
|
||||||
|
|
||||||
import { SyncOutlined } from '@antdv-next/icons';
|
import { SyncOutlined } from '@antdv-next/icons';
|
||||||
import { Empty, Input, Skeleton, SpaceCompact, Tree } from 'antdv-next';
|
import { Empty, Input, Skeleton, SpaceCompact, Tree } from 'antdv-next';
|
||||||
@@ -72,10 +72,11 @@ const deptTreeComputed = computed(() => {
|
|||||||
if (!searchValue.value) {
|
if (!searchValue.value) {
|
||||||
return deptTreeArray.value;
|
return deptTreeArray.value;
|
||||||
}
|
}
|
||||||
const toTree = treeToList(deptTreeArray.value, {
|
const toTree: DeptTreeArray = treeToList(cloneDeep(deptTreeArray.value), {
|
||||||
id: 'id',
|
id: 'id',
|
||||||
pid: 'parentId',
|
pid: 'parentId',
|
||||||
});
|
});
|
||||||
|
toTree.forEach((i) => (i.children = []));
|
||||||
const filteredTree = toTree.filter((item: DeptTree) =>
|
const filteredTree = toTree.filter((item: DeptTree) =>
|
||||||
item.label.toUpperCase().includes(searchValue.value.toUpperCase()),
|
item.label.toUpperCase().includes(searchValue.value.toUpperCase()),
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user