Skip to content

Let's use AI to Earn!

feat(热门内容): 热门专题table、基本信息构建

gaoSire3c7d699d9ba
diff --git a/src/api/hot.ts b/src/api/hot.ts
index 1f4884e9..1cef5c31 100644
--- a/src/api/hot.ts
+++ b/src/api/hot.ts
@@ -259,6 +259,7 @@ export const platformApi = {
page?: number;
pageSize?: number;
}) {
+ console.log(params);
return request<Pagination<Topic>>({
url: `hotdata/topics`,
method: "GET",
diff --git a/src/api/types/topic.ts b/src/api/types/topic.ts
index 673d2153..ab069bfb 100644
--- a/src/api/types/topic.ts
+++ b/src/api/types/topic.ts
@@ -13,7 +13,11 @@ export interface Topic {
likeCount: number;
watchingCount: number;
readCount: number;
- publishTime?: Date;
+ publishTime?: string;
+ fans: number;
+ cover: string;
+ avatar: string;
createTime: Date;
+ authorUrl: string;
updateTime: Date;
}
diff --git a/src/app/[lng]/hotContent/components/HotContent/hotContent.module.scss b/src/app/[lng]/hotContent/components/HotContent/hotContent.module.scss
index 7d49ba51..7e5ca71a 100644
--- a/src/app/[lng]/hotContent/components/HotContent/hotContent.module.scss
+++ b/src/app/[lng]/hotContent/components/HotContent/hotContent.module.scss
@@ -57,10 +57,6 @@
}
}
- .infinite-scroll-component {
- overflow: visible !important;
- }
-
.ant-spin-container, .ant-spin-nested-loading {
height: 100%;
min-height: 0;
@@ -90,8 +86,8 @@
display: flex;
& > img {
object-fit: cover;
- width: 60px;
- height: 80px;
+ width: 74px;
+ height: 86px;
flex-shrink: 0;
border-radius: 4px;
margin-right: 15px;
@@ -125,6 +121,12 @@
&-pubTime {
color: var(--grayColor7);
}
+
+ &:hover {
+ .baseInfo-right-author-name {
+ color: var(--colorPrimary5);
+ }
+ }
}
}
@@ -148,6 +150,10 @@
}
:global {
+ .infinite-scroll-component {
+ overflow: visible !important;
+ }
+
.ant-table-thead {
position: sticky;
top: 0;
diff --git a/src/app/[lng]/hotContent/components/HotContent/hotContentCommonWidget.tsx b/src/app/[lng]/hotContent/components/HotContent/hotContentCommonWidget.tsx
index d9523ae5..733a4476 100644
--- a/src/app/[lng]/hotContent/components/HotContent/hotContentCommonWidget.tsx
+++ b/src/app/[lng]/hotContent/components/HotContent/hotContentCommonWidget.tsx
@@ -61,6 +61,7 @@ export const HotContentBaseInfo = ({
nickname,
fansCount,
publishTime,
+ onClick,
}: {
cover: string;
title: string;
@@ -68,6 +69,7 @@ export const HotContentBaseInfo = ({
nickname: string;
fansCount?: number;
publishTime: string;
+ onClick?: () => void;
}) => {
return (
<div className={styles.baseInfo}>
@@ -81,7 +83,12 @@ export const HotContentBaseInfo = ({
<div className="baseInfo-right-noTitle">暂无标题</div>
)}
- <div className="baseInfo-right-author">
+ <div
+ className="baseInfo-right-author"
+ onClick={() => {
+ if (onClick) onClick();
+ }}
+ >
<Avatar
className="baseInfo-right-author-avatar"
src={avatar}
diff --git a/src/app/[lng]/hotContent/components/HotFeatures/hotFeatures.module.scss b/src/app/[lng]/hotContent/components/HotFeatures/hotFeatures.module.scss
index d19160e0..8c19a2aa 100644
--- a/src/app/[lng]/hotContent/components/HotFeatures/hotFeatures.module.scss
+++ b/src/app/[lng]/hotContent/components/HotFeatures/hotFeatures.module.scss
@@ -1,3 +1,13 @@
.hotFeatures {
-
+ height: 100%;
+ display: flex;
+ flex-direction: column;
+ :global {
+ .ant-spin-nested-loading, .hotFeatures-content, .ant-spin-container {
+ height: 100%;
+ display: flex;
+ flex-direction: column;
+ min-height: 0;
+ }
+ }
}
\ No newline at end of file
diff --git a/src/app/[lng]/hotContent/components/HotFeatures/index.tsx b/src/app/[lng]/hotContent/components/HotFeatures/index.tsx
index 5f737ca6..fc1c85f6 100644
--- a/src/app/[lng]/hotContent/components/HotFeatures/index.tsx
+++ b/src/app/[lng]/hotContent/components/HotFeatures/index.tsx
@@ -1,8 +1,23 @@
-import { ForwardedRef, forwardRef, memo, useEffect, useRef, useState } from "react";
+import {
+ ForwardedRef,
+ forwardRef,
+ memo,
+ useCallback,
+ useEffect,
+ useMemo,
+ useRef,
+ useState,
+} from "react";
import styles from "./hotFeatures.module.scss";
import HotContentLabel from "@/app/[lng]/hotContent/components/HotContentLabel";
import { useHotContent } from "@/app/[lng]/hotContent/useHotContent";
import { useShallow } from "zustand/react/shallow";
+import { Skeleton, Spin, Table, type TableProps } from "antd";
+import InfiniteScroll from "react-infinite-scroll-component";
+import { Topic } from "@/api/types/topic";
+import { platformApi } from "@/api/hot";
+import hotContentStyles from "../HotContent/hotContent.module.scss";
+import { HotContentBaseInfo } from "@/app/[lng]/hotContent/components/HotContent/hotContentCommonWidget";
export interface IHotFeaturesRef {}
@@ -19,16 +34,92 @@ const HotFeatures = memo(
);
const allDates = useRef(["近3天", "近7天", "近15天", "近30天"]);
// 当前选择的日期范围
- const [currDate, setCurrDate] = useState(allDates.current[2]);
+ const [currDate, setCurrDate] = useState(allDates.current[1]);
// 当前选择的平台
const [currPlat, setCurrPlat] = useState("");
// 当前选择的分类
const [labelValue, setLabelValue] = useState("");
+ const [loading, setLoading] = useState(false);
+ const [total, setTotal] = useState(0);
+ const page = useRef(0);
+ const [isReset, setIsReset] = useState(true);
+ const [dataSource, setDataSource] = useState<Topic[]>([]);
useEffect(() => {
setCurrPlat(hotContentPlatformList[0]?.name || "");
}, [hotContentPlatformList]);
+ const columns = useMemo(() => {
+ const columns: TableProps<Topic>["columns"] = [
+ {
+ title: "排名",
+ width: 60,
+ render: (text, data, ind) => (
+ <>
+ {ind <= 2 ? (
+ <div className={hotContentStyles.rankingTopthree}>
+ {ind + 1}
+ </div>
+ ) : (
+ <p style={{ width: "30px", textAlign: "center" }}>{ind + 1}</p>
+ )}
+ </>
+ ),
+ },
+ {
+ title: "基本信息",
+ dataIndex: "baseInfo",
+ render: (text, data) => {
+ return (
+ <HotContentBaseInfo
+ title={data.title}
+ avatar={data.avatar!}
+ publishTime={data.publishTime!}
+ fansCount={data.fans}
+ nickname={data.author!}
+ cover={data.cover}
+ onClick={() => {
+ window.open(data.authorUrl, "_blank");
+ }}
+ />
+ );
+ },
+ },
+ ];
+
+ return columns;
+ }, [dataSource]);
+
+ // 获取数据
+ const getTableData = useCallback(async () => {
+ if (loading) return;
+
+ const res = await platformApi.getAllTopics({
+ page: 1,
+ pageSize: 20,
+ platformId: hotContentPlatformList.find((v) => v.name === currPlat)?.id,
+ timeType: currDate,
+ msgType: labelValue === "" ? undefined : labelValue,
+ });
+
+ setTotal(res?.data.meta.totalItems || 0);
+ page.current = page.current + 1;
+ setDataSource((prevState) => {
+ return [...prevState, ...(res?.data.items || [])];
+ });
+ }, [currDate, currPlat, hotContentPlatformList, labelValue, loading]);
+
+ // 重置数据
+ useEffect(() => {
+ if (currPlat && isReset) {
+ page.current = 1;
+ setDataSource([]);
+ setLoading(true);
+ getTableData().then(() => setLoading(false));
+ setIsReset(false);
+ }
+ }, [isReset, currPlat, currDate, labelValue]);
+
return (
<div className={styles.hotFeatures}>
<HotContentLabel
@@ -39,7 +130,8 @@ const HotFeatures = memo(
)}
value={currPlat}
onChange={(value) => {
- setCurrDate(value);
+ setIsReset(true);
+ setCurrPlat(value);
}}
/>
<HotContentLabel
@@ -59,15 +151,50 @@ const HotFeatures = memo(
} else {
setLabelValue(value);
}
+ setIsReset(true);
}}
/>
<HotContentLabel
labels={allDates.current}
value={currDate}
onChange={(value) => {
+ setIsReset(true);
setCurrDate(value);
}}
/>
+
+ <Spin spinning={loading}>
+ <div
+ className={`${hotContentStyles["hotContent-table"]}`}
+ id="hotContent-table"
+ >
+ <InfiniteScroll
+ dataLength={dataSource.length}
+ next={getTableData}
+ hasMore={dataSource.length < total}
+ loader={
+ !loading ? <Skeleton active paragraph={{ rows: 1 }} /> : <></>
+ }
+ endMessage={<></>}
+ scrollableTarget="hotContent-table"
+ >
+ <Table
+ dataSource={dataSource}
+ rowKey={(record) => record._id}
+ columns={columns}
+ pagination={false}
+ onRow={(record) => {
+ return {
+ onClick: () => {
+ if (!record.url) return;
+ window.open(record.url, "_blank");
+ },
+ };
+ }}
+ />
+ </InfiniteScroll>
+ </div>
+ </Spin>
</div>
);
}),