// 转换构造树形数据
const convertDeptTreeData = (originlDeptList: any[]) => {
let result: any = [];
if (originlDeptList && originlDeptList.length > 0) {
let map = {};
let data: any = [];
originlDeptList.forEach(item => {
const node: any = {
key: item.id,//主键id
value: item.id,//主键id
parentId: item.parentId,
label: item.name
};
map[node.key] = node;
data.push(node);
});
data.forEach(item => {
let parent = map[item.parentId];
if (parent) {
(parent.children || (parent.children = [])).push(item);
} else {
result.push(item);
}
});
} else {
result.push({
key: "0",
value: "0",
label: "无数据",
children: [],
parentId: "-1"
});
}
return result
}