Let's use AI to Earn!
TypeScript auto-publishdouyindouyin-apielectron-appelectron-reactkuaishoukwaipublishedshipinhaotoolxiaohongshu
feat(热门内容): 热门专题完成
gaoSir3bdc000d19c1
diff --git a/src/api/hot.ts b/src/api/hot.tsindex 1cef5c31..1f4884e9 100644--- a/src/api/hot.ts+++ b/src/api/hot.ts@@ -259,7 +259,6 @@ 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.tsindex ab069bfb..74c98dcd 100644--- a/src/api/types/topic.ts+++ b/src/api/types/topic.ts@@ -12,6 +12,8 @@ export interface Topic {shareCount: number;likeCount: number;watchingCount: number;+ commentCount: number;+ collectCount: number;readCount: number;publishTime?: string;fans: number;diff --git a/src/app/[lng]/hotContent/components/HotFeatures/index.tsx b/src/app/[lng]/hotContent/components/HotFeatures/index.tsxindex fc1c85f6..bdf4d4d5 100644--- a/src/app/[lng]/hotContent/components/HotFeatures/index.tsx+++ b/src/app/[lng]/hotContent/components/HotFeatures/index.tsx@@ -17,7 +17,10 @@ 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";+import {+ HotContentBaseInfo,+ SingleNumberCall,+} from "@/app/[lng]/hotContent/components/HotContent/hotContentCommonWidget";export interface IHotFeaturesRef {}@@ -27,9 +30,10 @@ const NEXT_PUBLIC_YIKA_OSS_HOST = process.env.NEXT_PUBLIC_YIKA_OSS_HOST;const HotFeatures = memo(forwardRef(({}: IHotFeaturesProps, ref: ForwardedRef<IHotFeaturesRef>) => {- const { hotContentPlatformList } = useHotContent(+ const { hotContentPlatformList, twoMenuKey } = useHotContent(useShallow((state) => ({hotContentPlatformList: state.hotContentPlatformList,+ twoMenuKey: state.twoMenuKey,})),);const allDates = useRef(["近3天", "近7天", "近15天", "近30天"]);@@ -37,11 +41,9 @@ const HotFeatures = memo(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 page = useRef(1);const [isReset, setIsReset] = useState(true);const [dataSource, setDataSource] = useState<Topic[]>([]);@@ -50,6 +52,15 @@ const HotFeatures = memo(}, [hotContentPlatformList]);const columns = useMemo(() => {+ const callParamsColumnsCommon = (title: string) => {+ return {+ width: 90,+ title: () => {+ return <p style={{ textAlign: "center" }}>{title}</p>;+ },+ };+ };+const columns: TableProps<Topic>["columns"] = [{title: "排名",@@ -85,6 +96,74 @@ const HotFeatures = memo();},},+ {+ title: () => <p style={{ textAlign: "center" }}>作品分类</p>,+ dataIndex: "category",+ key: "category",+ width: 120,+ render: (text, data) => (+ <div style={{ textAlign: "center" }}>+ <p>+ <b>{text}</b>+ </p>+ <p>{data.subCategory}</p>+ </div>+ ),+ },++ ...(dataSource[1]?.shareCount+ ? [+ {+ ...callParamsColumnsCommon("分享数"),+ render: (text: any, data: Topic) => (+ <SingleNumberCall total={data.shareCount} />+ ),+ },+ ]+ : []),+ ...(dataSource[1]?.likeCount+ ? [+ {+ ...callParamsColumnsCommon("点赞数"),+ render: (text: any, data: Topic) => (+ <SingleNumberCall total={data.likeCount} />+ ),+ },+ ]+ : []),+ ...(dataSource[1]?.commentCount+ ? [+ {+ ...callParamsColumnsCommon("评论数"),+ render: (text: any, data: Topic) => (+ <SingleNumberCall total={data.commentCount} />+ ),+ },+ ]+ : []),+ ...(dataSource[1]?.collectCount+ ? [+ {+ ...callParamsColumnsCommon("收藏数"),+ render: (text: any, data: Topic) => (+ <SingleNumberCall+ total={data.collectCount}+ highlight={true}+ />+ ),+ },+ ]+ : []),+ ...(dataSource[1]?.readCount+ ? [+ {+ ...callParamsColumnsCommon("阅读数"),+ render: (text: any, data: Topic) => (+ <SingleNumberCall total={data.readCount} highlight={true} />+ ),+ },+ ]+ : []),];return columns;@@ -95,19 +174,22 @@ const HotFeatures = memo(if (loading) return;const res = await platformApi.getAllTopics({- page: 1,+ page: page.current,pageSize: 20,platformId: hotContentPlatformList.find((v) => v.name === currPlat)?.id,timeType: currDate,- msgType: labelValue === "" ? undefined : labelValue,+ msgType: twoMenuKey,});-- setTotal(res?.data.meta.totalItems || 0);page.current = page.current + 1;+ setTotal(res?.data.meta.totalItems || 0);setDataSource((prevState) => {return [...prevState, ...(res?.data.items || [])];});- }, [currDate, currPlat, hotContentPlatformList, labelValue, loading]);+ }, [currDate, currPlat, hotContentPlatformList, loading, twoMenuKey]);++ useEffect(() => {+ setIsReset(true);+ }, [twoMenuKey]);// 重置数据useEffect(() => {@@ -118,7 +200,7 @@ const HotFeatures = memo(getTableData().then(() => setLoading(false));setIsReset(false);}- }, [isReset, currPlat, currDate, labelValue]);+ }, [isReset, currPlat, currDate, twoMenuKey]);return (<div className={styles.hotFeatures}>@@ -134,26 +216,6 @@ const HotFeatures = memo(setCurrPlat(value);}}/>- <HotContentLabel- style={{ marginBottom: "15px" }}- labels={[- "AI教程",- "AI绘画",- "AI热点",- "AI创作",- "AI大模型",- "Prompt",- ]}- value={labelValue}- onChange={(value) => {- if (value === labelValue) {- setLabelValue("");- } else {- setLabelValue(value);- }- setIsReset(true);- }}- /><HotContentLabellabels={allDates.current}value={currDate}