diff --git a/src/routers/video/hooks.tsx b/src/routers/video/hooks.tsx new file mode 100644 index 0000000..682e282 --- /dev/null +++ b/src/routers/video/hooks.tsx @@ -0,0 +1,3 @@ +import { useAppSelector } from "@store/hooks"; +import { selectVideoLoadingState } from "@store/loading/index"; +export const useVideoLoading = () => useAppSelector(selectVideoLoadingState); diff --git a/src/routers/video/masonry.tsx b/src/routers/video/masonry.tsx index 5cf5f3f..6944d58 100644 --- a/src/routers/video/masonry.tsx +++ b/src/routers/video/masonry.tsx @@ -1,25 +1,27 @@ -import { useState, useEffect, FC, memo } from "react"; +import { useState, useEffect, FC, memo, ReactElement } from "react"; import { VideoRouterImageCardType, VideoRouterMasonryType } from "./videotype"; -import { Unstable_Grid2 as Grid } from "@mui/material"; +import { SxProps, Theme, Unstable_Grid2 as Grid } from "@mui/material"; import { VideoRouterImageCard } from "./item"; import { Skeleton } from "@mui/material"; import { nanoid } from "nanoid"; import styles from "./video.module.less"; import { fetchVideohandler, PickVideoRouterImageCardType } from "./tools"; -import { useAppSelector, useAppDispatch } from "@store/hooks"; -import { changeLoading, selectVideoLoadingState } from "@store/loading/index"; +import { useAppDispatch } from "@store/hooks"; +import { changeLoading } from "@store/loading/index"; +import { useVideoLoading } from "./hooks"; +import { useScreenSize } from "@components/proview/screenSize"; +type VideoListType = (VideoRouterImageCardType & { id: string })[]; /** * @description 该组件负责渲染视频图片的瀑布流 */ export default function VideoMasonry(props: VideoRouterMasonryType) { - const [lists, setLists] = useState< - (VideoRouterImageCardType & { id: string })[] - >([]); - const isLoading = useAppSelector(selectVideoLoadingState), - dispatch = useAppDispatch(), + const [lists, setLists] = useState([]); + const dispatch = useAppDispatch(), handerChangeLoading = (state: boolean) => dispatch(changeLoading({ stateName: "videoIsLoading", Tostate: state })); useEffect(() => { + setLists([]); + handerChangeLoading(true); // 在内部定义fetchHandler,保证拿到的是同步的 const fetchHandler = async (page: number = 1) => { const data = await fetchVideohandler(page, props); @@ -41,19 +43,84 @@ export default function VideoMasonry(props: VideoRouterMasonryType) { }), ]); }; - setLists([]); - handerChangeLoading(true); fetchHandler(1).then(() => handerChangeLoading(false)); }, [props]); return (
+ +
+ ); +} + +const VideoContent: FC<{ data: VideoListType }> = memo((props) => { + const { lg, md, sm } = useScreenSize(), + rightLen = (lg ? (md ? (sm ? 0 : 2) : 4) : 6) + 1; + const data = props.data, + loading = useVideoLoading(), + isEmpty = data.length < 1, + shouldNoShowHeroLine = data.length < rightLen + 1 + 10; + const heroItem = data.slice(0, 1), + rightItem = data.slice(1, rightLen), + resItems = shouldNoShowHeroLine ? data : data.slice(rightLen); + return ( + <> + + {loading ? ( + + ) : shouldNoShowHeroLine ? ( + <> + ) : ( + + )} + + {!sm && ( + + + {loading ? ( + Array.from({ length: rightLen - 1 }, (value, key) => ( + + + + )) + ) : shouldNoShowHeroLine ? ( + <> + ) : ( + rightItem.map((item) => ( + + )) + )} + + + )} + + - {lists.map((item) => ( - - ))} - {isLoading && } + {loading ? ( + Array.from({ length: 20 }, (value, key) => ( + + + + )) + ) : isEmpty ? ( + + ) : ( + resItems.map((item) => ) + )} - + ); -} +}); +const EmptyItem = () => ( +
暂无数据
+); + const MemoItems: FC = memo((props) => { return ( @@ -80,24 +157,18 @@ const MemoItems: FC = memo((props) => { ); }); -const LoadingSkeleton: FC<{ num: number }> = ({ num = 0 }) => { - return ( - <> - {...Array.from({ length: num }, (v, key) => ( - - - - -
- - -
-
- ))} - - ); -}; +const LoadingSkeleton = () => ( + <> + + + +
+ + +
+ +); diff --git a/src/routers/video/video.module.less b/src/routers/video/video.module.less index 670ea5d..c2418cc 100644 --- a/src/routers/video/video.module.less +++ b/src/routers/video/video.module.less @@ -13,13 +13,39 @@ } } -.container:empty { - display: flex; - justify-content: center; +.hero-content { + &>section:only-child { + &>a:first-child { + flex-grow: 1; + + img { + height: 100%; + } + + img+div { + padding: 16px; + + span { + font-size: 16px !important; + } + } + } + + &>div:last-child { + justify-content: flex-start; + + } - &::before { - margin-top: 50px; - content: "暂无数据"; - color: #c1c1c1; } -} \ No newline at end of file +} + +// .container:empty { +// display: flex; +// justify-content: center; + +// &::before { +// margin-top: 50px; +// content: "暂无数据"; +// color: #c1c1c1; +// } +// } \ No newline at end of file