Skip to content

Commit

Permalink
替换数据
Browse files Browse the repository at this point in the history
  • Loading branch information
master1lan committed Jan 2, 2023
1 parent ef5cc21 commit 3b0af38
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 11 deletions.
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

<head>
<meta charset="UTF-8" />
<meta name="referrer" content="no-referrer" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>eoefans-web</title>
</head>
Expand Down
29 changes: 22 additions & 7 deletions src/components/masonry/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { Masonry as Masonic_masonry, useInfiniteLoader } from "masonic";
import Image from "@components/image";
import { FetchNewImages } from "@utils/faker/index";
import { SingleRun } from "@utils/index";
import { fetchVideos } from "@utils/fetch";
import { nanoid } from "nanoid";
export default function Masonry() {
const [lists, setLists] = useState<
{
Expand All @@ -16,14 +18,27 @@ export default function Masonry() {
stopIndex: number,
currentItems: any[]
) => {
const res = await FetchNewImages(stopIndex - startIndex);
// const res = await FetchNewImages(stopIndex - startIndex);
const res = await fetchVideos({
order: "view",
page: 1,
}),
data = res.data.result;

setLists((lists) => {
console.log({
startIndex,
stopIndex,
currentNum: lists.length + res.length,
});
return [...lists, ...res];
// console.log({
// startIndex,
// stopIndex,
// currentNum: lists.length + res.length,
// });
return [
...lists,
...data.map((item) => ({
image: item.face,
name: item.name,
id: nanoid(10),
})),
];
});
};
const fetchMoreItemsHandler = useCallback(SingleRun(fetchMoreItems), [
Expand Down
11 changes: 10 additions & 1 deletion src/routers/read.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
import getrealtiveTime from "@utils/time";
export default function ReadPage() {
return <h1>这里是read路由页面</h1>;
const time = getrealtiveTime(1672570020000);
return (
<>
<h1>这里是read路由页面</h1>
<p>
<span>1672570020000->{time}</span>
</p>
</>
);
}
6 changes: 4 additions & 2 deletions src/utils/fetch/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { IFetchVideoParams, RFetchVideoRes } from "./fetchtype";
/**
* video视频数据获取接口
*/
export function fetchVideos(params: IFetchVideoParams): RFetchVideoRes {
return videoJson;
export function fetchVideos(
params: IFetchVideoParams
): Promise<RFetchVideoRes> {
return Promise.resolve(videoJson);
}
2 changes: 1 addition & 1 deletion src/utils/time/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ dayJs.locale("zh-cn");
dayJs.extend(realtiveTime);

export default function getrealtiveTime(time: number): string {
return dayJs(time).toNow();
return dayJs(time).fromNow();
}

0 comments on commit 3b0af38

Please sign in to comment.