视频列表优化

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

View File

@ -32,6 +32,10 @@ code {
margin-right: 16px; margin-right: 16px;
} }
.mb-8 {
margin-bottom: 8px;
}
.mb-10 { .mb-10 {
margin-bottom: 10px; margin-bottom: 10px;
} }
@ -117,6 +121,22 @@ code {
color: @primaryColor; color: @primaryColor;
} }
.category-label {
width: 100%;
height: 40px;
border-radius: 6px;
font-size: 14px;
font-weight: 500;
color: rgba(0, 0, 0, 0.88);
line-height: 40px;
box-sizing: border-box;
padding-left: 16px;
cursor: pointer;
&.active {
background: rgba(#ff4d4f, 0.1);
}
}
.form-avatar { .form-avatar {
width: 100px; width: 100px;
height: 100px; height: 100px;
@ -160,6 +180,37 @@ code {
} }
} }
.tree-main-body {
width: 100%;
height: auto;
min-height: calc(100vh - 172px);
float: left;
box-sizing: border-box;
border-radius: 12px;
display: flex;
flex-direction: row;
overflow: hidden;
.left-box {
width: 250px;
float: left;
height: auto;
min-height: calc(100vh - 172px);
border-right: 1px solid #f6f6f6;
box-sizing: border-box;
padding: 24px 16px;
background-color: white;
}
.right-box {
width: calc(100% - 251px);
float: left;
height: auto;
min-height: calc(100vh - 172px);
box-sizing: border-box;
padding: 24px;
background-color: white;
}
}
.ant-menu, .ant-menu,
.ant-menu-sub, .ant-menu-sub,
.ant-menu-inline { .ant-menu-inline {

View File

@ -172,7 +172,10 @@ export const CoursePage = () => {
<div className="d-flex mb-24"> <div className="d-flex mb-24">
<Typography.Text></Typography.Text> <Typography.Text></Typography.Text>
</div> </div>
<TreeCategory onUpdate={(keys: any) => setCategoryIds(keys)} /> <TreeCategory
text={"资源"}
onUpdate={(keys: any) => setCategoryIds(keys)}
/>
</div> </div>
<div className="float-left"> <div className="float-left">
<div className="d-flex mb-24"> <div className="d-flex mb-24">

View File

@ -74,79 +74,78 @@ export const ResourceImagesPage = () => {
return ( return (
<> <>
<Row> <div className="tree-main-body">
<Col span={4}> <div className="left-box">
<div className="playedu-main-body" style={{ marginLeft: -24 }}> <TreeCategory
<TreeCategory onUpdate={(keys: any) => setCategoryIds(keys)} /> text={"图片"}
onUpdate={(keys: any) => setCategoryIds(keys)}
/>
</div>
<div className="right-box">
<div className="playedu-main-title float-left mb-24">
/
</div> </div>
</Col> <Row gutter={16} style={{ marginBottom: 24 }}>
<Col span={20}> <Col span={24}>
<div className="playedu-main-body"> <UploadImageSub
<div className="playedu-main-title float-left mb-24"> categoryIds={category_ids}
/ onUpdate={() => {
</div> resetImageList();
<Row gutter={16} style={{ marginBottom: 24 }}> }}
></UploadImageSub>
</Col>
</Row>
<Row gutter={[24, 24]}>
{imageList.length === 0 && (
<Col span={24}> <Col span={24}>
<UploadImageSub <Empty description="暂无图片" />
categoryIds={category_ids}
onUpdate={() => {
resetImageList();
}}
></UploadImageSub>
</Col> </Col>
</Row> )}
<Row gutter={[24, 24]}>
{imageList.length === 0 && (
<Col span={24}>
<Empty description="暂无图片" />
</Col>
)}
{imageList.map((item) => ( {imageList.map((item) => (
<Col key={item.id} span={3}> <Col key={item.id} span={3}>
<div className={styles.imageItem}> <div className={styles.imageItem}>
<Image <Image
preview={true} preview={true}
width={150} width={150}
height={150} height={150}
src={item.url} src={item.url}
/>
<Popconfirm
title="警告"
description="即将删除此图片,确认操作?"
onConfirm={() => removeResource(item.id)}
okText="确定"
cancelText="取消"
>
<Button
className={styles.closeButton}
danger
shape="circle"
icon={<CloseOutlined />}
/>
</Popconfirm>
</div>
</Col>
))}
{imageList.length > 0 && (
<Col span={24}>
<Pagination
showSizeChanger
onChange={(currentPage, currentSize) => {
setPage(currentPage);
setSize(currentSize);
}}
defaultCurrent={page}
total={total}
pageSize={size}
/> />
</Col> <Popconfirm
)} title="警告"
</Row> description="即将删除此图片,确认操作?"
</div> onConfirm={() => removeResource(item.id)}
</Col> okText="确定"
</Row> cancelText="取消"
>
<Button
className={styles.closeButton}
danger
shape="circle"
icon={<CloseOutlined />}
/>
</Popconfirm>
</div>
</Col>
))}
{imageList.length > 0 && (
<Col span={24}>
<Pagination
showSizeChanger
onChange={(currentPage, currentSize) => {
setPage(currentPage);
setSize(currentSize);
}}
defaultCurrent={page}
total={total}
pageSize={size}
/>
</Col>
)}
</Row>
</div>
</div>
</> </>
); );
}; };

View File

@ -38,18 +38,18 @@ export const ResourceVideosPage = () => {
const [category_ids, setCategoryIds] = useState<any>([]); const [category_ids, setCategoryIds] = useState<any>([]);
const columns: ColumnsType<DataType> = [ const columns: ColumnsType<DataType> = [
{ // {
title: "封面", // title: "封面",
dataIndex: "id", // dataIndex: "id",
render: (id: string) => ( // render: (id: string) => (
<Image // <Image
preview={false} // preview={false}
width={120} // width={120}
height={80} // height={80}
src={videosExtra[id].poster} // src={videosExtra[id].poster}
></Image> // ></Image>
), // ),
}, // },
{ {
title: "视频名称", title: "视频名称",
dataIndex: "name", dataIndex: "name",
@ -158,37 +158,36 @@ export const ResourceVideosPage = () => {
return ( return (
<> <>
<Row> <div className="tree-main-body">
<Col span={4}> <div className="left-box">
<div className="playedu-main-body" style={{ marginLeft: -24 }}> <TreeCategory
<TreeCategory onUpdate={(keys: any) => setCategoryIds(keys)} /> text={"视频"}
onUpdate={(keys: any) => setCategoryIds(keys)}
/>
</div>
<div className="right-box">
<div className="playedu-main-title float-left mb-24">
/
</div> </div>
</Col> <div className="float-left mb-24">
<Col span={20}> <UploadVideoButton
<div className="playedu-main-body"> categoryIds={category_ids}
<div className="playedu-main-title float-left mb-24"> onUpdate={() => {
/ resetVideoList();
</div> }}
<div className="float-left mb-24"> ></UploadVideoButton>
<UploadVideoButton
categoryIds={category_ids}
onUpdate={() => {
resetVideoList();
}}
></UploadVideoButton>
</div>
<div className="float-left">
<Table
columns={columns}
dataSource={videoList}
loading={loading}
pagination={paginationProps}
rowKey={(record) => record.id}
/>
</div>
</div> </div>
</Col> <div className="float-left">
</Row> <Table
columns={columns}
dataSource={videoList}
loading={loading}
pagination={paginationProps}
rowKey={(record) => record.id}
/>
</div>
</div>
</div>
</> </>
); );
}; };