视频列表优化

This commit is contained in:
禺狨
2023-03-10 18:46:19 +08:00
parent 97caa68565
commit 5bc78f6192
6 changed files with 186 additions and 125 deletions

View File

@@ -10,24 +10,20 @@ interface Option {
}
interface PropInterface {
text: string;
onUpdate: (keys: any) => void;
}
export const TreeCategory = (props: PropInterface) => {
const [treeData, setTreeData] = useState<any>([]);
const [loading, setLoading] = useState<boolean>(true);
const [selectKey, setSelectKey] = useState<any>([]);
useEffect(() => {
setLoading(true);
resourceCategory.resourceCategoryList().then((res: any) => {
const categories = res.data.categories;
if (JSON.stringify(categories) !== "{}") {
const new_arr: Option[] = [
{
key: "",
title: "全部",
children: checkArr(categories, 0),
},
];
const new_arr: Option[] = checkArr(categories, 0);
setTreeData(new_arr);
} else {
const new_arr: Option[] = [
@@ -65,6 +61,7 @@ export const TreeCategory = (props: PropInterface) => {
const onSelect = (selectedKeys: any, info: any) => {
props.onUpdate(selectedKeys);
setSelectKey(selectedKeys);
};
const onDragEnter: TreeProps["onDragEnter"] = (info) => {
@@ -80,12 +77,24 @@ export const TreeCategory = (props: PropInterface) => {
};
return (
<Tree
onSelect={onSelect}
treeData={treeData}
draggable
onDragEnter={onDragEnter}
onDrop={onDrop}
/>
<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}
draggable
onDragEnter={onDragEnter}
onDrop={onDrop}
/>
</div>
);
};

View File

@@ -97,7 +97,7 @@ export const UploadImageButton = (props: PropsInterface) => {
>
<Row gutter={16}>
<Col span={4}>
<TreeCategory onUpdate={(keys: any) => setCategoryIds(keys)} />
<TreeCategory text={"图片"} onUpdate={(keys: any) => setCategoryIds(keys)} />
</Col>
<Col span={20}>
<Row style={{ marginBottom: 24 }}>