Skip to content

Let's use AI to Earn!

fix(热门内容): 热门内容完成

gaoSirabaf18a5e810
diff --git a/src/api/hot.ts b/src/api/hot.ts
index 15bfad24..c7773d81 100644
--- a/src/api/hot.ts
+++ b/src/api/hot.ts
@@ -106,6 +106,8 @@ export interface RankingContent {
fansCount: number;
};
stats: Stats;
+ collectCount?: number;
+ shareCount?: number;
anaAdd: {
addCollectCount: number;
addCommentCount: number;
diff --git a/src/app/[lng]/hotContent/components/HotContent/hotContent.module.scss b/src/app/[lng]/hotContent/components/HotContent/hotContent.module.scss
index 6a33d5e8..cfb8c8dd 100644
--- a/src/app/[lng]/hotContent/components/HotContent/hotContent.module.scss
+++ b/src/app/[lng]/hotContent/components/HotContent/hotContent.module.scss
@@ -3,6 +3,27 @@
display: flex;
flex-direction: column;
:global {
+ .hotContent-rankLabel {
+ display: flex;
+ gap: 10px;
+ margin-bottom: 15px;
+ &-item {
+ padding: 4px 10px;
+ cursor: pointer;
+ border-radius: 6px;
+ display: flex;
+ align-items: center;
+ .anticon {
+ margin-right: 6px;
+ font-size: 16px;
+ }
+ &--active {
+ background: var(--colorPrimary5);
+ color: #fff;
+ }
+ }
+ }
+
.hotContent-options {
margin-top: 15px;
display: flex;
@@ -60,6 +81,7 @@
.ant-table-cell {
background: rgba(237, 242, 242);
padding: 10px 16px;
+ font-weight: 400 !important;
&:last-of-type {
border-bottom-right-radius: 8px;
@@ -160,7 +182,7 @@
justify-content: center;
:global {
.anaAddCall-add {
- font-weight: 600;
+ font-family: 'DIN';
white-space: nowrap;
.anticon {
font-size: 14px;
@@ -175,6 +197,7 @@
padding: 1px 8px;
border-radius: 30px;
font-size: var(--fs-xs);
+ font-family: 'DIN';
white-space: nowrap;
}
}
diff --git a/src/app/[lng]/hotContent/components/HotContent/index.tsx b/src/app/[lng]/hotContent/components/HotContent/index.tsx
index 19ada8db..e4885a56 100644
--- a/src/app/[lng]/hotContent/components/HotContent/index.tsx
+++ b/src/app/[lng]/hotContent/components/HotContent/index.tsx
@@ -15,15 +15,21 @@ import styles from "./hotContent.module.scss";
import { Avatar, Popover, Select, Skeleton, Spin, Table } from "antd";
import Icon, { QuestionCircleOutlined } from "@ant-design/icons";
import type { TableProps } from "antd";
-import { platformApi, RankingContent } from "@/api/hot";
+import { platformApi, PlatformRanking, RankingContent } from "@/api/hot";
import InfiniteScroll from "react-infinite-scroll-component";
import { describeNumber } from "@/utils";
import Uparrow from "../../svgs/uparrow.svg";
+import HotSvg from "../../svgs/hotContent.svg";
+import ReadSvg from "./svgs/read.svg";
export interface IHotContentRef {}
export interface IHotContentProps {}
+const icons = {
+ wechat: [ReadSvg, HotSvg],
+};
+
const AnaAddCall = ({
add,
total,
@@ -38,22 +44,59 @@ const AnaAddCall = ({
className={`${styles.anaAddCall} ${highlight ? styles["anaAddCall-highlight"] : ""}`}
>
<div className="anaAddCall-add">
- <Icon component={Uparrow} />
- {describeNumber(add)}
+ {add ? (
+ <>
+ <Icon component={Uparrow} />
+ {describeNumber(add)}
+ </>
+ ) : (
+ "-"
+ )}
</div>
<div className="anaAddCall-total">总{describeNumber(total)}</div>
</div>
);
};
+const SingleNumberCall = ({
+ total,
+ highlight = false,
+}: {
+ total: number;
+ highlight?: boolean;
+}) => {
+ return (
+ <p
+ style={{
+ textAlign: "center",
+ fontSize: "var(--fs-md)",
+ color: highlight ? "var(--colorPrimary5)" : "#3d4242",
+ fontFamily: "DIN",
+ fontWeight: 100,
+ }}
+ >
+ {describeNumber(total)}
+ </p>
+ );
+};
+
const HotContent = memo(
forwardRef(({}: IHotContentProps, ref: ForwardedRef<IHotContentRef>) => {
- const { labelData, rankingData, datesData, twoMenuKey } = useHotContent(
+ const {
+ labelData,
+ rankingData,
+ currentRankCategory,
+ datesData,
+ twoMenuKey,
+ setCurrentRankCategory,
+ } = useHotContent(
useShallow((state) => ({
labelData: state.labelData,
rankingData: state.rankingData,
datesData: state.datesData,
twoMenuKey: state.twoMenuKey,
+ currentRankCategory: state.currentRankCategory,
+ setCurrentRankCategory: state.setCurrentRankCategory,
})),
);
// 当前选中的标签
@@ -73,11 +116,16 @@ const HotContent = memo(
const selectedLabelInfo = useMemo(() => {
const platId = twoMenuKey.split("_")[1];
return {
- ranking: rankingData[platId] ?? {},
+ // 所有榜单
+ allRanking: rankingData[platId] || [],
+ // 当前选择榜单
+ ranking: (rankingData[platId]?.find(
+ (v) => v.id === currentRankCategory,
+ ) ?? {}) as PlatformRanking,
labelData: labelData[platId] || [],
datesData: datesData[platId] || [],
};
- }, [labelData, rankingData, datesData, twoMenuKey]);
+ }, [labelData, rankingData, datesData, twoMenuKey, currentRankCategory]);
const columns = useMemo(() => {
const callParamsColumnsCommon = (title: string) => {
@@ -163,18 +211,74 @@ const HotContent = memo(
// 视频号
const wxSphColumns: TableProps<RankingContent>["columns"] = [
{
- ...callParamsColumnsCommon("评论增量"),
+ ...callParamsColumnsCommon("评论数"),
render: (text, data) => (
- <AnaAddCall
- add={data.anaAdd.addShareCount}
- total={data.anaAdd.useShareCount}
- />
+ <SingleNumberCall total={data.stats.commentCount} />
+ ),
+ },
+ {
+ ...callParamsColumnsCommon("转发数"),
+ render: (text, data) => <SingleNumberCall total={data.shareCount!} />,
+ },
+ {
+ ...callParamsColumnsCommon("喜欢数"),
+ render: (text, data) => (
+ <SingleNumberCall total={data.stats.likeCount} />
+ ),
+ },
+ {
+ ...callParamsColumnsCommon("推荐数"),
+ render: (text, data) => (
+ <SingleNumberCall total={data.stats.likeCount} />
),
},
];
- const otherColumns: TableProps<RankingContent>["columns"] = [];
-
- console.log(plat);
+ // 微信公众号
+ const wxGzhColumns: TableProps<RankingContent>["columns"] = [
+ ...(dataSource[1]?.stats.watchCount
+ ? [
+ {
+ ...callParamsColumnsCommon("在看数"),
+ render: (text: string, data: RankingContent) => (
+ <SingleNumberCall total={data.stats.watchCount} />
+ ),
+ },
+ ]
+ : []),
+ ...(dataSource[1]?.stats.likeCount
+ ? [
+ {
+ ...callParamsColumnsCommon("点赞数"),
+ render: (text: string, data: RankingContent) => (
+ <SingleNumberCall total={data.stats.likeCount} />
+ ),
+ },
+ ]
+ : []),
+ ...(dataSource[1]?.shareCount
+ ? [
+ {
+ ...callParamsColumnsCommon("转发数"),
+ render: (text: string, data: RankingContent) => (
+ <SingleNumberCall total={data.shareCount!} />
+ ),
+ },
+ ]
+ : []),
+ ...(dataSource[1]?.stats.viewCount
+ ? [
+ {
+ ...callParamsColumnsCommon("阅读数"),
+ render: (text: string, data: RankingContent) => (
+ <SingleNumberCall
+ total={data.stats.viewCount}
+ highlight={true}
+ />
+ ),
+ },
+ ]
+ : []),
+ ];
const columns: TableProps<RankingContent>["columns"] = [
{
@@ -217,9 +321,11 @@ const HotContent = memo(
<p className="baseInfo-right-author-name">
{data.author.name}
</p>
- <p className="baseInfo-right-author-fans">
- 粉丝数 {describeNumber(data.author.fansCount)}
- </p>
+ {data.author.fansCount && (
+ <p className="baseInfo-right-author-fans">
+ 粉丝数 {describeNumber(data.author.fansCount)}
+ </p>
+ )}
<p className="baseInfo-right-author-pubTime">
发布于{data.publishTime}
</p>
@@ -244,7 +350,11 @@ const HotContent = memo(
),
},
- ...(plat === "shipinhao" ? wxSphColumns : anaAddColumns),
+ ...(plat === "shipinhao"
+ ? wxSphColumns
+ : plat === "wechat"
+ ? wxGzhColumns
+ : anaAddColumns),
];
return columns;
}, [selectedLabelInfo, dataSource]);
@@ -290,10 +400,33 @@ const HotContent = memo(
selectedLabelInfo.datesData,
selectedLabelInfo.ranking?.id,
isReset,
+ currentRankCategory,
]);
return (
<div className={`${styles.hotContent}`}>
+ {selectedLabelInfo.allRanking.length > 1 && (
+ <div className="hotContent-rankLabel">
+ {selectedLabelInfo.allRanking.map((v, i) => {
+ const icon = (icons[v.platform.type as "wechat"] ?? [])[i];
+
+ return (
+ <div
+ className={`hotContent-rankLabel-item ${v.id === currentRankCategory ? "hotContent-rankLabel-item--active" : ""}`}
+ key={v.id}
+ onClick={() => {
+ setCurrentRankCategory(v.id);
+ setIsReset(true);
+ }}
+ >
+ <Icon component={icon} />
+ {v.name}
+ </div>
+ );
+ })}
+ </div>
+ )}
+
<HotContentLabel
labels={["全部", ...(selectedLabelInfo.labelData ?? [])]}
value={labelValue}
diff --git a/src/app/[lng]/hotContent/components/HotContent/svgs/read.svg b/src/app/[lng]/hotContent/components/HotContent/svgs/read.svg
new file mode 100644
index 00000000..066be90a
--- /dev/null
+++ b/src/app/[lng]/hotContent/components/HotContent/svgs/read.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="1758102669578" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="4587" xmlns:xlink="http://www.w3.org/1999/xlink" width="300" height="300"><path d="M979.222 415.474C894.954 332.02 776.31 192.004 509.958 192.004c-266.316 0-384.962 140.016-469.23 223.47-19.86 19.682-30.788 45.784-30.788 73.534 0 27.728 10.93 53.85 30.788 73.51 84.27 83.476 202.896 223.47 469.23 223.47 266.368 0 384.996-139.994 469.264-223.47 19.86-19.66 30.79-45.784 30.79-73.51C1010.01 461.256 999.082 435.156 979.222 415.474zM940.882 524.282C862.556 601.838 756.802 732 509.958 732c-246.81 0-352.564-130.164-430.89-207.718-9.548-9.468-14.8-22.01-14.8-35.276 0-13.288 5.252-25.806 14.8-35.252 78.344-77.578 184.098-207.764 430.89-207.764 246.826 0 352.58 130.186 430.924 207.764 9.55 9.446 14.802 21.966 14.802 35.252C955.684 502.272 950.432 514.812 940.882 524.282zM509.974 335.996c-84.868 0-153.928 68.652-153.928 152.988 0 84.358 69.06 153.01 153.928 153.01 84.872 0 153.93-68.652 153.93-153.01C663.904 404.648 594.846 335.996 509.974 335.996zM509.974 588.008c-54.912 0-99.6-44.428-99.6-99.024 0-54.574 44.69-98.978 99.6-98.978 54.912 0 99.6 44.404 99.6 98.978C609.576 543.58 564.888 588.008 509.974 588.008z" p-id="4588"></path></svg>
\ No newline at end of file
diff --git a/src/app/[lng]/hotContent/useHotContent.ts b/src/app/[lng]/hotContent/useHotContent.ts
index bc17c279..d4d54eee 100644
--- a/src/app/[lng]/hotContent/useHotContent.ts
+++ b/src/app/[lng]/hotContent/useHotContent.ts
@@ -23,12 +23,14 @@ export interface IHotContentStore {
};
// 热门内容的榜单数据 key=平台ID,value=榜单数据
rankingData: {
- [key: string]: PlatformRanking;
+ [key: string]: PlatformRanking[];
};
// 日期数据 key=平台ID,value=日期数据
datesData: {
[key: string]: RankingDate[];
};
+ // 当前选择的榜单分类
+ currentRankCategory: string;
}
const store: IHotContentStore = {
@@ -41,6 +43,7 @@ const store: IHotContentStore = {
labelData: {},
rankingData: {},
datesData: {},
+ currentRankCategory: "",
};
const getStore = () => {
@@ -57,6 +60,10 @@ export const useHotContent = create(
},
(set, get, storeApi) => {
const methods = {
+ // 设置 currentRankCategory
+ setCurrentRankCategory(currentRankCategory: string) {
+ set({ currentRankCategory });
+ },
// 设置 当前侧边栏二级菜单选择的ID
setTwoMenuKey(twoMenuKey: string) {
set({ twoMenuKey });
@@ -112,13 +119,19 @@ export const useHotContent = create(
if (res?.data?.length) {
const newRankingData = {
...rankingData,
- [platformId]: res.data[0],
+ [platformId]: res.data,
};
set({ rankingData: newRankingData });
}
}
- const rankingItem = get().rankingData[platformId];
+ set({
+ currentRankCategory: get().rankingData[platformId]?.[0]?.id || "",
+ });
+
+ const rankingItem = get().rankingData[platformId].find(
+ (v) => v.id === get().currentRankCategory,
+ )!;
// 获取标签和日期数据
if (!get().labelData[platformId]) {
await Promise.all([
diff --git a/src/app/globals.css b/src/app/globals.css
index e251eeb2..cc498843 100644
--- a/src/app/globals.css
+++ b/src/app/globals.css
@@ -1,3 +1,5 @@
+@import "../assets/fonts/font.css";
+
/* 全局样式重置 */
* {
margin: 0;
diff --git a/src/assets/fonts/DIN-Medium.otf b/src/assets/fonts/DIN-Medium.otf
new file mode 100644
index 00000000..ceed4bed
Binary files /dev/null and b/src/assets/fonts/DIN-Medium.otf differ
diff --git a/src/assets/fonts/font.css b/src/assets/fonts/font.css
new file mode 100644
index 00000000..b82f5a59
--- /dev/null
+++ b/src/assets/fonts/font.css
@@ -0,0 +1,6 @@
+@font-face {
+ font-family: 'DIN';
+ src: url('./DIN-Medium.otf') format('opentype');
+ font-weight: normal;
+ font-style: normal;
+}
\ No newline at end of file