//入参为数组化组织架构,获得所有上级部门,node为完整架构
function getNode(nodes, path = []) {
if (!nodes) return [];
for (const data of nodes) {
path.push(data);
//无props.departmentID,面包屑展示根部门
if (!props.departmentID) {
return path;
}
if (data.id === props.departmentID) {
return path;
}
if (data.children && data.children.length > 0) {
const findChildren = getNode(data.children, path);
if (findChildren.length) return findChildren;
}
path.pop();
}
return [];
}
//监听传入的ID
watch(() => props.departmentID, () => {
crumb.crumbArr = getNode([wholeStructure])
})