Skip to content

Let's use AI to Earn!

feat(热门内容): 热门内容,抖音、快手、b站、小红书优化完成。视频号数据需要对一下,微信公众号需要分两个,阅读榜、低粉爆文榜

gaoSirb8d314e2c0ae
diff --git a/next.config.mjs b/next.config.mjs
index cc87e406..8a791926 100644
--- a/next.config.mjs
+++ b/next.config.mjs
@@ -32,17 +32,18 @@ const nextConfig = {
output: 'standalone', // Temporarily disabled to avoid symlink issues on Windows
productionBrowserSourceMaps: process.env.NEXT_PUBLIC_EVN === 'dev',
rewrites: async () => {
+ const rewrites = [
+ ];
+
// 存在 NEXT_PUBLIC_PROXY_URL 则代理,本地直连 用
// 如:NEXT_PUBLIC_PROXY_URL = http://localhost:8080
if (process.env.NEXT_PUBLIC_PROXY_URL) {
- return [
- {
- source: `/api/:path*`,
- destination: `${process.env.NEXT_PUBLIC_PROXY_URL}/api/:path*`,
- },
- ];
+ rewrites.push({
+ source: `/api/:path*`,
+ destination: `${process.env.NEXT_PUBLIC_PROXY_URL}/api/:path*`,
+ })
}
- return [];
+ return rewrites;
},
};
diff --git a/src/api/hot.ts b/src/api/hot.ts
index e23ec576..15bfad24 100644
--- a/src/api/hot.ts
+++ b/src/api/hot.ts
@@ -99,6 +99,7 @@ export interface RankingContent {
rankingPosition: number;
category: string;
publishTime: string;
+ subCategory: string;
author: {
name: string;
avatar: string;
@@ -106,7 +107,7 @@ export interface RankingContent {
};
stats: Stats;
anaAdd: {
- addCollectedCunt: number;
+ addCollectCount: number;
addCommentCount: number;
addInteractiveCount: number;
addLikeCount: number;
diff --git a/src/app/[lng]/hotContent/components/HotContent/hotContent.module.scss b/src/app/[lng]/hotContent/components/HotContent/hotContent.module.scss
index 91e21295..6a33d5e8 100644
--- a/src/app/[lng]/hotContent/components/HotContent/hotContent.module.scss
+++ b/src/app/[lng]/hotContent/components/HotContent/hotContent.module.scss
@@ -36,6 +36,10 @@
}
}
+ .infinite-scroll-component {
+ overflow: visible !important;
+ }
+
.hotContent-table {
height: 100%;
box-sizing: border-box;
@@ -65,6 +69,121 @@
}
}
}
+
+ tbody {
+ .ant-table-cell {
+ padding: 10px;
+ }
+ tr {
+ cursor: pointer;
+ }
+ }
+ }
+
+ .ant-spin-container, .ant-spin-nested-loading {
+ height: 100%;
+ min-height: 0;
+ display: flex;
+ flex-direction: column;
+ }
+
+ .hotContent--wechat, .hotContent--bilibili {
+ .baseInfo-cover {
+ width: 100px !important;
+ height: 60px !important;
+ }
+ }
+ }
+}
+
+.rankingTopthree {
+ width: 30px;
+ height: 30px;
+ line-height: 30px;
+ text-align: center;
+ color: #fff;
+ background: url("../../../../../images/bg-rank-index.png") no-repeat center / cover;
+}
+
+.baseInfo {
+ display: flex;
+ & > img {
+ object-fit: cover;
+ width: 60px;
+ height: 80px;
+ flex-shrink: 0;
+ border-radius: 4px;
+ margin-right: 15px;
+ }
+
+ :global {
+ .baseInfo-right {
+ display: flex;
+ flex-direction: column;
+ justify-content: space-between;
+ &-title {
+ @include omitText(2);
+ }
+ &-noTitle {
+ color: var(--grayColor5);
+ }
+ &-author {
+ display: flex;
+ flex-wrap: wrap;
+ align-items: center;
+ font-size: var(--fs-xs);
+ &-avatar {
+ }
+ &-name {
+ margin: 0 10px 0 5px;
+ }
+ &-fans {
+ margin-right: 10px;
+ color: var(--grayColor7);
+ }
+ &-pubTime {
+ color: var(--grayColor7);
+ }
+ }
+ }
+
+ .baseInfo-cover {
+
+ }
+ }
+}
+
+.anaAddCall {
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ justify-content: center;
+ :global {
+ .anaAddCall-add {
+ font-weight: 600;
+ white-space: nowrap;
+ .anticon {
+ font-size: 14px;
+ margin-right: 3px;
+ color: red;
+ }
+ }
+
+ .anaAddCall-total {
+ border: 1px solid var(--grayColor3);
+ color: var(--grayColor8);
+ padding: 1px 8px;
+ border-radius: 30px;
+ font-size: var(--fs-xs);
+ white-space: nowrap;
+ }
+ }
+}
+.anaAddCall-highlight {
+ color: var(--colorPrimary5);
+ :global {
+ .anaAddCall-total {
+ color: var(--colorPrimary5);
}
}
}
\ No newline at end of file
diff --git a/src/app/[lng]/hotContent/components/HotContent/index.tsx b/src/app/[lng]/hotContent/components/HotContent/index.tsx
index 311d5032..eb486d07 100644
--- a/src/app/[lng]/hotContent/components/HotContent/index.tsx
+++ b/src/app/[lng]/hotContent/components/HotContent/index.tsx
@@ -5,29 +5,46 @@ import {
useCallback,
useEffect,
useMemo,
+ useRef,
useState,
} from "react";
import { useHotContent } from "@/app/[lng]/hotContent/useHotContent";
import { useShallow } from "zustand/react/shallow";
import HotContentLabel from "@/app/[lng]/hotContent/components/HotContentLabel";
import styles from "./hotContent.module.scss";
-import { Popover, Select, Table } from "antd";
-import { QuestionCircleOutlined } from "@ant-design/icons";
+import { Avatar, Popover, Select, Spin, Table } from "antd";
+import Icon, { QuestionCircleOutlined } from "@ant-design/icons";
import type { TableProps } from "antd";
import { platformApi, RankingContent } from "@/api/hot";
+import InfiniteScroll from "react-infinite-scroll-component";
+import { describeNumber } from "@/utils";
+import Uparrow from "../../svgs/uparrow.svg";
export interface IHotContentRef {}
export interface IHotContentProps {}
-const columns: TableProps<RankingContent>["columns"] = [
- {
- title: "排名",
- dataIndex: "rankingPosition",
- key: "rankingPosition",
- render: (text, data, index) => <span>{index + 1}</span>,
- },
-];
+const AnaAddCall = ({
+ add,
+ total,
+ highlight = false,
+}: {
+ add: number;
+ total: number;
+ highlight?: boolean;
+}) => {
+ return (
+ <div
+ className={`${styles.anaAddCall} ${highlight ? styles["anaAddCall-highlight"] : ""}`}
+ >
+ <div className="anaAddCall-add">
+ <Icon component={Uparrow} />
+ {describeNumber(add)}
+ </div>
+ <div className="anaAddCall-total">总{describeNumber(total)}</div>
+ </div>
+ );
+};
const HotContent = memo(
forwardRef(({}: IHotContentProps, ref: ForwardedRef<IHotContentRef>) => {
@@ -47,6 +64,10 @@ const HotContent = memo(
const [loading, setLoading] = useState(false);
// 表格数据
const [dataSource, setDataSource] = useState<RankingContent[]>([]);
+ // 总数
+ const [total, setTotal] = useState(0);
+ const page = useRef(0);
+ const [isReset, setIsReset] = useState(false);
// 获取当前选中的标签、日期、榜单
const selectedLabelInfo = useMemo(() => {
@@ -58,36 +79,223 @@ const HotContent = memo(
};
}, [labelData, rankingData, datesData, twoMenuKey]);
- useEffect(() => {
- setLabelValue("全部");
- }, [twoMenuKey]);
+ const columns = useMemo(() => {
+ const callParamsColumnsCommon = (title: string) => {
+ return {
+ width: 90,
+ title: () => {
+ return <p style={{ textAlign: "center" }}>{title}</p>;
+ },
+ };
+ };
+ const plat = selectedLabelInfo?.ranking?.platform?.type;
- // 当平台切换时,重置日期为第一个
- useEffect(() => {
- if (selectedLabelInfo.datesData.length > 0) {
- setDateValue(selectedLabelInfo.datesData[0].value);
- }
- }, [selectedLabelInfo]);
+ const anaAddColumns: TableProps<RankingContent>["columns"] = [
+ ...(dataSource[1]?.anaAdd?.addCollectCount
+ ? [
+ {
+ ...callParamsColumnsCommon("新增收藏"),
+ render: (text: string, data: RankingContent) => (
+ <AnaAddCall
+ add={data.anaAdd.addCollectCount!}
+ total={data.anaAdd.useCollectCount!}
+ />
+ ),
+ },
+ ]
+ : []),
+ {
+ ...callParamsColumnsCommon("新增分享"),
+ render: (text, data) => (
+ <AnaAddCall
+ add={data.anaAdd.addShareCount}
+ total={data.anaAdd.useShareCount}
+ />
+ ),
+ },
+ {
+ ...callParamsColumnsCommon("新增评论"),
+ render: (text, data) => (
+ <AnaAddCall
+ add={data.anaAdd.addCommentCount}
+ total={data.anaAdd.useCommentCount}
+ />
+ ),
+ },
+ ...(dataSource[0]?.anaAdd?.addViewCount
+ ? [
+ {
+ ...callParamsColumnsCommon("新增播放"),
+ render: (text: string, data: RankingContent) => (
+ <AnaAddCall
+ add={data.anaAdd.addViewCount!}
+ total={data.anaAdd.useViewCount!}
+ />
+ ),
+ },
+ ]
+ : []),
+ {
+ ...callParamsColumnsCommon("新增获赞"),
+ render: (text, data) => (
+ <AnaAddCall
+ highlight={plat !== "xiaohongshu"}
+ add={data.anaAdd.addLikeCount}
+ total={data.anaAdd.useLikeCount}
+ />
+ ),
+ },
+ ...(plat === "xiaohongshu"
+ ? [
+ {
+ ...callParamsColumnsCommon("互动增量"),
+ render: (text: string, data: RankingContent) => (
+ <AnaAddCall
+ highlight={true}
+ add={data.anaAdd.addInteractiveCount!}
+ total={data.anaAdd.interactiveCount!}
+ />
+ ),
+ },
+ ]
+ : []),
+ ];
+ // 视频号
+ const wxSphColumns: TableProps<RankingContent>["columns"] = [
+ {
+ ...callParamsColumnsCommon("评论增量"),
+ render: (text, data) => (
+ <AnaAddCall
+ add={data.anaAdd.addShareCount}
+ total={data.anaAdd.useShareCount}
+ />
+ ),
+ },
+ ];
+ const otherColumns: TableProps<RankingContent>["columns"] = [];
- // 请求列表数据
- useEffect(() => {
- if (dateValue === "") return;
- getTableData();
- }, [labelValue, dateValue]);
+ console.log(plat);
+
+ const columns: TableProps<RankingContent>["columns"] = [
+ {
+ title: "排名",
+ dataIndex: "rankingPosition",
+ key: "rankingPosition",
+ width: 60,
+ render: (text, data, ind) => (
+ <>
+ {ind <= 2 ? (
+ <div className={styles.rankingTopthree}>{ind + 1}</div>
+ ) : (
+ <p style={{ width: "30px", textAlign: "center" }}>{ind + 1}</p>
+ )}
+ </>
+ ),
+ },
+ {
+ title: "基本信息",
+ dataIndex: "baseInfo",
+ render: (text, data) => {
+ return (
+ <div className={styles.baseInfo}>
+ <img className="baseInfo-cover" src={data.cover} />
+ <div className="baseInfo-right">
+ {data.title ? (
+ <div className="baseInfo-right-title" title={data.title}>
+ {data.title}
+ </div>
+ ) : (
+ <div className="baseInfo-right-noTitle">暂无标题</div>
+ )}
+
+ <div className="baseInfo-right-author">
+ <Avatar
+ className="baseInfo-right-author-avatar"
+ src={data.author.avatar}
+ size="small"
+ />
+ <p className="baseInfo-right-author-name">
+ {data.author.name}
+ </p>
+ <p className="baseInfo-right-author-fans">
+ 粉丝数 {describeNumber(data.author.fansCount)}
+ </p>
+ <p className="baseInfo-right-author-pubTime">
+ 发布于{data.publishTime}
+ </p>
+ </div>
+ </div>
+ </div>
+ );
+ },
+ },
+ {
+ 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>
+ ),
+ },
+
+ ...(plat === "shipinhao" ? wxSphColumns : anaAddColumns),
+ ];
+ return columns;
+ }, [selectedLabelInfo, dataSource]);
const getTableData = useCallback(async () => {
+ console.log(selectedLabelInfo);
+ if (loading) return;
+
+ setLoading(true);
const res = await platformApi.getRankingContents(
selectedLabelInfo.ranking.id,
- 1,
+ page.current,
20,
labelValue,
dateValue,
);
- setDataSource(res?.data.items || []);
- }, [selectedLabelInfo, labelValue, dateValue]);
+ setLoading(false);
+ page.current += 1;
+ setDataSource((prevState) => {
+ return [...prevState, ...(res?.data.items || [])];
+ });
+ setTotal(res?.data.meta.totalItems || 0);
+ }, [selectedLabelInfo.ranking, labelValue, dateValue]);
+
+ // 当平台切换时,重置数据
+ useEffect(() => {
+ if (selectedLabelInfo.datesData.length > 0) {
+ setDateValue(selectedLabelInfo.datesData[0].value);
+ setLabelValue("全部");
+ setIsReset(true);
+ }
+ }, [selectedLabelInfo.datesData, twoMenuKey]);
+
+ // 请求列表数据
+ useEffect(() => {
+ if (isReset && selectedLabelInfo.ranking?.id) {
+ page.current = 1;
+ setDataSource([]);
+ getTableData();
+ setIsReset(false);
+ }
+ }, [
+ labelValue,
+ dateValue,
+ selectedLabelInfo.datesData,
+ selectedLabelInfo.ranking?.id,
+ isReset,
+ ]);
return (
- <div className={styles.hotContent}>
+ <div className={`${styles.hotContent}`}>
<HotContentLabel
labels={["全部", ...(selectedLabelInfo.labelData ?? [])]}
value={labelValue}
@@ -125,9 +333,28 @@ const HotContent = memo(
</Popover>
</div>
- <div className="hotContent-table">
- <Table dataSource={dataSource} columns={columns} pagination={false} />
- </div>
+ <Spin spinning={loading}>
+ <div
+ className={`hotContent-table hotContent--${selectedLabelInfo?.ranking?.platform?.type}`}
+ id="hotContent-table"
+ >
+ <InfiniteScroll
+ dataLength={dataSource.length}
+ next={getTableData}
+ hasMore={dataSource.length < total}
+ loader={<></>}
+ endMessage={<></>}
+ scrollableTarget="hotContent-table"
+ >
+ <Table
+ dataSource={dataSource}
+ rowKey={(record) => record.id}
+ columns={columns}
+ pagination={false}
+ />
+ </InfiniteScroll>
+ </div>
+ </Spin>
</div>
);
}),
diff --git a/src/app/[lng]/hotContent/page.tsx b/src/app/[lng]/hotContent/page.tsx
index 11b313a9..043161bc 100644
--- a/src/app/[lng]/hotContent/page.tsx
+++ b/src/app/[lng]/hotContent/page.tsx
@@ -12,5 +12,9 @@ export async function generateMetadata({ params }: PageParams) {
}
export default function Page() {
- return <HotContentCore />;
+ return (
+ <>
+ <HotContentCore />
+ </>
+ );
}
diff --git a/src/app/[lng]/hotContent/svgs/uparrow.svg b/src/app/[lng]/hotContent/svgs/uparrow.svg
new file mode 100644
index 00000000..d9bc42d8
--- /dev/null
+++ b/src/app/[lng]/hotContent/svgs/uparrow.svg
@@ -0,0 +1 @@
+<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1758027188174" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="6886" xmlns:xlink="http://www.w3.org/1999/xlink" width="300" height="300"><path d="M771.512499 514.290159 511.614214 64.132646 251.715929 514.290159 414.441057 514.290159 414.441057 959.653483 608.786347 959.653483 608.786347 514.290159Z" p-id="6887"></path></svg>
\ No newline at end of file
diff --git a/src/app/[lng]/layout.tsx b/src/app/[lng]/layout.tsx
index c5af73f7..5fe2c563 100644
--- a/src/app/[lng]/layout.tsx
+++ b/src/app/[lng]/layout.tsx
@@ -1,7 +1,7 @@
import "@/app/var.css";
import "../globals.css";
import { Providers } from "../layout/Providers";
-
+import Head from "next/head";
import { dir } from "i18next";
import { languages, fallbackLng } from "@/app/i18n/settings";
import { useTranslation } from "@/app/i18n";
@@ -38,7 +38,7 @@ export default async function RootLayout({
height: "100vh",
display: "flex",
flexDirection: "column",
- minHeight: '0'
+ minHeight: "0",
}}
>
<ConditionalHeader />
diff --git a/src/constant.ts b/src/constant.ts
index fec4ccb1..05e04eb1 100644
--- a/src/constant.ts
+++ b/src/constant.ts
@@ -2,7 +2,7 @@
export const APP_HOT_URL = "https://att-contents.yikart.cn/api";
// 代理地址
-export const ProxyUrls = ["/api/"];
+export const ProxyUrls = ["/api/", process.env.NEXT_PUBLIC_BILI_OSS_PROXY];
// OSS URL
export const OSS_URL = process.env.NEXT_PUBLIC_OSS_URL;
diff --git a/src/images/bg-rank-index.png b/src/images/bg-rank-index.png
new file mode 100644
index 00000000..ed4c7e69
Binary files /dev/null and b/src/images/bg-rank-index.png differ
diff --git a/src/utils/general.ts b/src/utils/general.ts
index b8dab9a3..99190795 100644
--- a/src/utils/general.ts
+++ b/src/utils/general.ts
@@ -1,7 +1,5 @@
import { Metadata } from "next";
import { useTranslation } from "@/app/i18n";
-import { useParams } from "next/navigation";
-import { fallbackLng } from "@/app/i18n/settings";
export async function getPageTitle(name: string, lng: string) {
const { t } = await useTranslation(lng);
@@ -24,6 +22,7 @@ export async function getMetadata(
return {
...props,
title,
+ referrer: "no-referrer",
};
}
diff --git a/src/utils/index.ts b/src/utils/index.ts
index 0130af7b..be67e865 100644
--- a/src/utils/index.ts
+++ b/src/utils/index.ts
@@ -61,16 +61,13 @@ export function formatSeconds(seconds: number): string {
* @returns 如果数值超过1000返回'n千',超过10000返回'n万'
*/
export function describeNumber(value: number): string {
- if (value > 10000) {
- // 数值超过10000,返回'n w'
- const wan = Math.floor(value / 10000);
- return `${wan}w`;
- } else if (value > 1000) {
- // 数值超过1000,返回'n k'
- const qian = Math.floor(value / 1000);
- return `${qian}k`;
+ if (!value) return `${value ?? 0}`;
+
+ if (value >= 10000) {
+ return `${(value / 10000).toFixed(2).replace(/\.?0+$/, "")}w`;
+ } else if (value >= 1000) {
+ return `${(value / 1000).toFixed(2).replace(/\.?0+$/, "")}k`;
} else {
- // 数值不超过1000,直接返回数值的字符串形式
return value.toString();
}
}