线上课列表初步

This commit is contained in:
禺狨
2023-03-13 18:15:50 +08:00
parent f83fbc15d5
commit 87de8155e0
3 changed files with 144 additions and 104 deletions

View File

@@ -9,24 +9,32 @@ interface Option {
}
interface PropInterface {
text: string;
onUpdate: (keys: any) => void;
}
export const TreeDepartment = (props: PropInterface) => {
const [treeData, setTreeData] = useState<any>([]);
const [loading, setLoading] = useState<boolean>(true);
const [selectKey, setSelectKey] = useState<any>([]);
useEffect(() => {
setLoading(true);
department.departmentList().then((res: any) => {
const departments = res.data.departments;
const new_arr: Option[] = [
{
key: "",
title: "全部",
children: checkArr(departments, 0),
},
];
setTreeData(new_arr);
if (JSON.stringify(departments) !== "{}") {
const new_arr: Option[] = checkArr(departments, 0);
setTreeData(new_arr);
} else {
const new_arr: Option[] = [
{
key: "",
title: "全部",
children: [],
},
];
setTreeData(new_arr);
}
setLoading(false);
});
}, []);
@@ -53,7 +61,22 @@ export const TreeDepartment = (props: PropInterface) => {
const onSelect = (selectedKeys: any, info: any) => {
props.onUpdate(selectedKeys);
setSelectKey(selectedKeys);
};
return <Tree onSelect={onSelect} treeData={treeData} />;
return (
<div>
<div
className={
selectKey.length === 0
? "mb-8 category-label active"
: "mb-8 category-label"
}
onClick={() => onSelect([], "")}
>
{props.text}
</div>
<Tree onSelect={onSelect} treeData={treeData} />
</div>
);
};