>["data"],
nextPage: number
) {
setLists((lists) => [
@@ -62,15 +62,18 @@ export default function SearchPage() {
return { ...itemRes, id: nanoid(4) };
}),
]);
+ handerChangeLoading(false);
}
const fetchHandler = async (page: number = 1) => {
- const data = await fetchVideohandler(page, {
+ const { data, canceledByAxios } = await fetchVideohandler(page, {
order,
q: `tag.${tagParam}~name.${nameParam}`,
});
- handlerSetList(data, page + 1);
+ if (!canceledByAxios) {
+ handlerSetList(data, page + 1);
+ }
};
- fetchHandler(1).then(() => handerChangeLoading(false));
+ fetchHandler(1);
}, loaderData);
const { loading, isEmpty } = useSearchShowState(lists),
propsObj = { loading, isEmpty, data: lists };
diff --git a/src/routers/video/masonry.tsx b/src/routers/video/masonry.tsx
index 9743efa..f6d7490 100644
--- a/src/routers/video/masonry.tsx
+++ b/src/routers/video/masonry.tsx
@@ -20,7 +20,7 @@ export default function VideoMasonry(props: VideoRouterMasonryType) {
handerChangeLoading(true);
// 在内部定义fetchHandler,保证拿到的是同步的
const fetchHandler = async (page: number = 1) => {
- const data = await fetchVideohandler(page, props);
+ const { data, canceledByAxios } = await fetchVideohandler(page, props);
setLists((lists) => [
...lists,
...data.map((item, index) => {
@@ -38,8 +38,11 @@ export default function VideoMasonry(props: VideoRouterMasonryType) {
return { ...itemRes, id: nanoid(4) };
}),
]);
+ if (!canceledByAxios) {
+ handerChangeLoading(false);
+ }
};
- fetchHandler(1).then(() => handerChangeLoading(false));
+ fetchHandler(1);
}, [props]);
return (
diff --git a/src/routers/video/tools.ts b/src/routers/video/tools.ts
index ee6cd2d..8322c5e 100644
--- a/src/routers/video/tools.ts
+++ b/src/routers/video/tools.ts
@@ -2,9 +2,18 @@ import { VideoRouterMasonryType, VideoRouterImageCardType } from "./videotype";
import { fetchVideos } from "@utils/fetch/index";
import message from "@components/message";
import { Pick } from "@utils/index";
+import { RFetchVideoRes } from "@utils/fetch/fetchtype";
-export const fetchVideohandler = async (
- page: number = 1,
+type fetchVideohandlerType = (
+ page: number,
+ props: VideoRouterMasonryType
+) => Promise<{
+ data: RFetchVideoRes["data"]["result"];
+ canceledByAxios: boolean;
+}>;
+
+export const fetchVideohandler: fetchVideohandlerType = async (
+ page = 1,
props: VideoRouterMasonryType
) => {
const res = await fetchVideos({
@@ -16,11 +25,14 @@ export const fetchVideohandler = async (
if (res.code !== 0) {
res.code === 400 && message.info("参数错误,请尝试其他tag");
res.code === 500 && message.info(res.message);
- return [];
+ if (res.code === 403) {
+ return { data: [], canceledByAxios: true };
+ }
+ return { data: [], canceledByAxios: false };
} else if (res.data.result.length < 1) {
message.info("没有更多数据了,请尝试其他tag");
}
- return res.data.result;
+ return { data: res.data.result, canceledByAxios: false };
};
export function PickVideoRouterImageCardType<
diff --git a/src/utils/hooks/match.ts b/src/utils/hooks/match.ts
index 252268d..95a9eca 100644
--- a/src/utils/hooks/match.ts
+++ b/src/utils/hooks/match.ts
@@ -10,14 +10,6 @@ export const useScreenMatchSize = (size: Breakpoint) => {
const matchSize = useMediaQuery(theme.breakpoints.down(size));
return matchSize;
};
-//个人主页头像大小
-`@240w_240h_1c_1s.webp`;
-//移动平台首页图片大小
-`@480w_270h_1c`;
-//电脑平台首页图片大小
-`@672w_378h_1c_!web-search-common-cover`;
-//首页up头像大小
-`@96w_96h_1s.webp`;
export const useBodyScrollHide = (hidden: boolean) => {
useEffect(() => {
diff --git a/src/utils/hooks/popover.ts b/src/utils/hooks/popover.ts
index 46a054c..6744e65 100644
--- a/src/utils/hooks/popover.ts
+++ b/src/utils/hooks/popover.ts
@@ -1,10 +1,16 @@
import React from "react";
-export function usePopoverConfig() {
+export function usePopoverConfig(
+ target: "target" | "currentTaarget" = "currentTaarget"
+) {
const [anchorEl, setAnchorEl] = React.useState(null);
- const handleClick = (event: React.MouseEvent) => {
- //@ts-ignore
- setAnchorEl(event.currentTarget);
+ const handleClick = (event: React.MouseEvent) => {
+ if (target === "currentTaarget") {
+ setAnchorEl(event.currentTarget);
+ } else {
+ //@ts-ignore
+ setAnchorEl(event.target);
+ }
},
handleClose = () => {
setAnchorEl(null);