部门报错优化

This commit is contained in:
禺狨 2023-03-29 09:36:26 +08:00
parent 7f4a08f7a4
commit d9d3be1434

View File

@ -30,23 +30,25 @@ export const Header: React.FC = () => {
const [currentNav, serCurrentNav] = useState(location.pathname); const [currentNav, serCurrentNav] = useState(location.pathname);
useEffect(() => { useEffect(() => {
setCurrentDepartment(departments[0].name); if (departments.length > 0) {
const arr: any = [ setCurrentDepartment(departments[0].name);
{ const arr: any = [
key: "1", {
type: "group", key: "1",
label: "部门", type: "group",
children: [], label: "部门",
}, children: [],
]; },
departments.map((item: any) => { ];
arr[0].children.push({ departments.map((item: any) => {
key: item.id, arr[0].children.push({
label: item.name, key: item.id,
disabled: item.name === currentDepartment, label: item.name,
disabled: item.name === currentDepartment,
});
}); });
}); setDepartmentsMenu(arr);
setDepartmentsMenu(arr); }
}, [departments]); }, [departments]);
const onClick: MenuProps["onClick"] = ({ key }) => { const onClick: MenuProps["onClick"] = ({ key }) => {