antd tree渲染
/** * 遍历单位基本信息树 * @param data * @param parentId * @returns */ const getTrees = (data: OrganizationResult[], parentId: number | null) => { let itemArr = []; for (let i = 0; i < data.length; i++) { let node = data[i]; if (node.parent_id === parentId) { let newNode: TreeNode = { id: node.id, key: node.id as number, title: node.name, children: getTrees(data, node.id), }; itemArr.push(newNode); } } return itemArr; };
/** * 获取左侧集团架构树 * @returns */ const getBorderOrganizationData = async () => { let res = await getNewOrganizationInfo<OrganizationDataResult>(); let resluts: OrganizationDataResult[] = res?.data; let roles = erji.includes(selector.user.organization_type); let data = getTrees(resluts, roles ? 1 : null); setTreeData(data); setCurrent(Number(data?.[0]?.id)); setStateBorder({ ...stateborder, companyType: selector?.user?.organization_type, }); return getOrginationInfo(selector?.user?.organization_id); };