Skip to content

Let's use AI to Earn!

feat(热门内容): 爆款标题完成

gaoSir3c0ad24a2a93
diff --git a/src/app/[lng]/hotContent/components/HotTitle/components/HotTitleCommons.tsx b/src/app/[lng]/hotContent/components/HotTitle/components/HotTitleCommons.tsx
index d7b2e38d..3875d689 100644
--- a/src/app/[lng]/hotContent/components/HotTitle/components/HotTitleCommons.tsx
+++ b/src/app/[lng]/hotContent/components/HotTitle/components/HotTitleCommons.tsx
@@ -3,14 +3,15 @@ import styles from "../hotTitle.module.scss";
import HotTitleBackSvg from "../svgs/hotTitleBack.svg";
import Icon from "@ant-design/icons";
import { CSSProperties } from "react";
-import { Table, type TableProps } from "antd";
+import { Table, type TableProps, Typography } from "antd";
import hotEventStyles from "../../HotEvent/hotEvent.module.scss";
import hotContentStyles from "../../HotContent/hotContent.module.scss";
+import { describeNumber } from "@/utils";
const columns: TableProps<ViralTitle>["columns"] = [
{
title: "排名",
- width: 60,
+ width: 50,
render: (text, data, ind) => (
<>
{ind <= 2 ? (
@@ -26,23 +27,48 @@ const columns: TableProps<ViralTitle>["columns"] = [
</>
),
},
+ {
+ title: "爆款标题",
+ render: (text, data, ind) => (
+ <div className="hotTitleItem-title">
+ <Typography.Paragraph copyable={{ text: data.title }}>
+ {data.title}
+ </Typography.Paragraph>
+ </div>
+ ),
+ },
+ {
+ title: "互动量",
+ width: 100,
+ align: "center",
+ render: (text, data, ind) => <>{describeNumber(data.engagement)}</>,
+ },
];
export const HotTitleItem = ({
data,
style,
+ bottomLinkText,
+ onBottomLinkClick,
+ headRightElement,
}: {
data: {
category: string;
titles: ViralTitle[];
};
+ bottomLinkText: string;
+ onBottomLinkClick: () => void;
style?: CSSProperties;
+ headRightElement?: React.ReactNode;
}) => {
return (
- <div className={styles.hotTitleItem} style={style}>
+ <div className={styles.hotTitleItem + " hotTitleItem"} style={style}>
<div className="hotTitleItem-head">
- <div className="hotTitleItem-head-name">{data.category}</div>
- <Icon component={HotTitleBackSvg} />
+ <div className="hotTitleItem-head-left">
+ <div className="hotTitleItem-head-name">{data.category}</div>
+ <Icon component={HotTitleBackSvg} />
+ </div>
+ {headRightElement}
</div>
<div
className={`hotTitleItem-content ${hotEventStyles["hotEvent-item-content"]}`}
@@ -53,7 +79,23 @@ export const HotTitleItem = ({
rowKey={(record) => record._id}
pagination={false}
scroll={{ y: 400 }}
+ onRow={(record) => {
+ return {
+ onClick: () => {
+ if (!record.url) return;
+ window.open(record.url, "_blank");
+ },
+ };
+ }}
/>
+ <a
+ onClick={(e) => {
+ e.preventDefault();
+ onBottomLinkClick();
+ }}
+ >
+ {bottomLinkText}
+ </a>
</div>
</div>
);
diff --git a/src/app/[lng]/hotContent/components/HotTitle/hotTitle.module.scss b/src/app/[lng]/hotContent/components/HotTitle/hotTitle.module.scss
index 20033600..2a439554 100644
--- a/src/app/[lng]/hotContent/components/HotTitle/hotTitle.module.scss
+++ b/src/app/[lng]/hotContent/components/HotTitle/hotTitle.module.scss
@@ -19,6 +19,21 @@
display: none;
}
}
+ .hotTitle-content-wrapper-details {
+ display: flex;
+ flex-direction: column;
+ height: 100%;
+ min-height: 0;
+ overflow: auto;
+ .hotTitleItem, .hotTitleItem-content {
+ display: flex;
+ flex-direction: column;
+ height: 100% !important;
+ min-height: 0;
+ margin: 0 !important;
+ @include table-flex-container-with-selectors;
+ }
+ }
}
}
}
@@ -27,21 +42,51 @@
:global {
.hotTitleItem-head {
display: flex;
+ justify-content: space-between;
align-items: center;
background-image: linear-gradient(to left, rgba(90,246,242,.1), rgba(254,44,85,.1));
- position: relative;
padding: 10px 20px;
border-radius: 10px 10px 0 0;
- font-weight: 500;
- .anticon {
+ .hotTitleItem-head-left {
+ display: flex;
position: relative;
- left: -20px;
- svg {
- width: 120px;
+ font-weight: 500;
+ .anticon {
+ position: relative;
+ left: -20px;
+ svg {
+ width: 120px;
+ }
}
}
}
.hotTitleItem-content {
+ & > a {
+ text-align: center;
+ display: block;
+ margin-top: 15px;
+ }
+ tbody {
+ .ant-table-cell {
+ background: #fff !important;
+ .hotTitleItem-title {
+ @include omitText(1);
+ .ant-typography {
+ margin: 0 !important;
+ .ant-typography-copy {
+ display: none;
+ }
+ &:hover {
+ color: var(--colorPrimary5) !important;
+ .ant-typography-copy {
+ display: inline-block;
+ }
+ }
+ }
+ }
+ padding: 8px !important;
+ }
+ }
}
}
}
\ No newline at end of file
diff --git a/src/app/[lng]/hotContent/components/HotTitle/index.tsx b/src/app/[lng]/hotContent/components/HotTitle/index.tsx
index 0b1a2a73..e3411b36 100644
--- a/src/app/[lng]/hotContent/components/HotTitle/index.tsx
+++ b/src/app/[lng]/hotContent/components/HotTitle/index.tsx
@@ -39,8 +39,9 @@ const HotTitle = memo(
setCurrentRankCategory: state.setCurrentRankCategory,
})),
);
+ const labelAll = useRef("全部");
// 当前选中的标签
- const [labelValue, setLabelValue] = useState("全部");
+ const [labelValue, setLabelValue] = useState(labelAll.current);
const allDates = useRef(["近7天", "近30天", "近90天"]);
// 当前选择的日期范围
const [currDate, setCurrDate] = useState(allDates.current[0]);
@@ -52,6 +53,8 @@ const HotTitle = memo(
titles: ViralTitle[];
}[]
>();
+ // 爆款标题数据详情
+ const [hotTitleData, setHotTitleData] = useState<ViralTitle[]>([]);
// 获取当前选中的标签、日期、榜单
const selectedLabelInfo = useMemo(() => {
@@ -70,23 +73,45 @@ const HotTitle = memo(
// 获取所有爆款数据
const getAllData = useCallback(async () => {
+ setLoading(true);
const res = await platformApi.findTopByPlatformAndCategories(
selectedLabelInfo.platId,
currDate,
);
- console.log(res);
+ setLoading(false);
setAllHotTitleData(res?.data);
}, [currDate, selectedLabelInfo.platId]);
+ // 获取爆款数据详情
+ const getDetailData = useCallback(async () => {
+ if (labelValue === labelAll.current) return;
+ setLoading(true);
+ const res = await platformApi.findByPlatformAndCategory(
+ selectedLabelInfo.platId,
+ {
+ category: labelValue,
+ page: 1,
+ timeType: currDate,
+ pageSize: 50,
+ },
+ );
+ setHotTitleData(res?.data.items || []);
+ setLoading(false);
+ }, [labelValue, currDate, selectedLabelInfo.ranking.id]);
+
useEffect(() => {
getAllData();
}, [twoMenuKey]);
+ useEffect(() => {
+ getDetailData();
+ }, [labelValue, currDate]);
+
return (
<div className={styles.hotTitle}>
<HotContentLabel
style={{ marginBottom: "15px" }}
- labels={["全部", ...(selectedLabelInfo.labelData ?? [])]}
+ labels={[labelAll.current, ...(selectedLabelInfo.labelData ?? [])]}
value={labelValue}
onChange={(value) => {
setLabelValue(value);
@@ -103,17 +128,58 @@ const HotTitle = memo(
/>
<Spin wrapperClassName="hotTitle-content" spinning={loading}>
- <div className="hotTitle-content-wrapper">
+ <div
+ className="hotTitle-content-wrapper"
+ style={{
+ display: labelValue === labelAll.current ? "flex" : "none",
+ }}
+ >
{allHotTitleData?.map((v) => {
return (
<HotTitleItem
data={v}
key={v.category}
style={{ width: "calc(50% - 15px)", marginBottom: "30px" }}
+ onBottomLinkClick={() => {
+ setLabelValue(v.category);
+ }}
+ bottomLinkText="查看更多"
/>
);
})}
</div>
+
+ <div
+ className="hotTitle-content-wrapper-details"
+ style={{
+ display: labelValue !== labelAll.current ? "flex" : "none",
+ }}
+ >
+ <HotTitleItem
+ headRightElement={
+ <>
+ <a
+ onClick={(e) => {
+ e.preventDefault();
+ setLabelValue(labelAll.current);
+ }}
+ >
+ 返回全部
+ </a>
+ </>
+ }
+ data={{
+ category: labelValue,
+ titles: hotTitleData,
+ }}
+ key={labelValue}
+ style={{ width: "100%", marginBottom: "30px" }}
+ onBottomLinkClick={() => {
+ setLabelValue(labelAll.current);
+ }}
+ bottomLinkText="收起"
+ />
+ </div>
</Spin>
</div>
);