Let's use AI to Earn!
TypeScript auto-publishdouyindouyin-apielectron-appelectron-reactkuaishoukwaipublishedshipinhaotoolxiaohongshu
feat(热门内容): 添加侧边栏、标签数据、构建获取数据的基本逻辑及缓存逻辑
gaoSir188caeaa8a1c
diff --git a/.env b/.envindex 4ccb0c1b..65eaae89 100644--- a/.env+++ b/.env@@ -1,2 +1,4 @@# OSS URL-NEXT_PUBLIC_OSS_URL="https://aitoearn.s3.ap-southeast-1.amazonaws.com/"\ No newline at end of file+NEXT_PUBLIC_OSS_URL="https://aitoearn.s3.ap-southeast-1.amazonaws.com/"+# yika OSS+NEXT_PUBLIC_YIKA_OSS_HOST=https://yika-bj.oss-cn-beijing.aliyuncs.comdiff --git a/.idea/workspace.xml b/.idea/workspace.xmlindex ad56df0d..46167dba 100644--- a/.idea/workspace.xml+++ b/.idea/workspace.xml@@ -4,13 +4,21 @@<option name="autoReloadType" value="NONE" /></component><component name="ChangeListManager">- <list default="true" id="8ce961ad-7c9e-494c-bc53-9ecde4358af8" name="更改" comment="feat(数据统计): 添加昨日新增">- <change afterPath="$PROJECT_DIR$/src/app/[lng]/hotContent/HotContentCore.tsx" afterDir="false" />- <change afterPath="$PROJECT_DIR$/src/app/[lng]/hotContent/components/HotContentSidebar/hotContentSidebar.module.scss" afterDir="false" />- <change afterPath="$PROJECT_DIR$/src/app/[lng]/hotContent/components/HotContentSidebar/index.tsx" afterDir="false" />- <change afterPath="$PROJECT_DIR$/src/app/[lng]/hotContent/hotContent.module.scss" afterDir="false" />- <change afterPath="$PROJECT_DIR$/src/app/[lng]/hotContent/page.tsx" afterDir="false" />- <change afterPath="$PROJECT_DIR$/src/app/[lng]/hotContent/useHotContent.ts" afterDir="false" />+ <list default="true" id="8ce961ad-7c9e-494c-bc53-9ecde4358af8" name="更改" comment="feat(热门内容): 恢复新热门内容">+ <change afterPath="$PROJECT_DIR$/src/app/[lng]/hotContent/components/HotContent/index.tsx" afterDir="false" />+ <change afterPath="$PROJECT_DIR$/src/app/[lng]/hotContent/components/HotContentLabel/hotContentLabel.module.scss" afterDir="false" />+ <change afterPath="$PROJECT_DIR$/src/app/[lng]/hotContent/components/HotContentLabel/index.tsx" afterDir="false" />+ <change afterPath="$PROJECT_DIR$/src/app/[lng]/hotContent/components/HotEvent/index.tsx" afterDir="false" />+ <change afterPath="$PROJECT_DIR$/src/app/[lng]/hotContent/components/HotFeatures/index.tsx" afterDir="false" />+ <change afterPath="$PROJECT_DIR$/src/app/[lng]/hotContent/components/HotTitle/index.tsx" afterDir="false" />+ <change afterPath="$PROJECT_DIR$/src/app/[lng]/hotContent/hotContent.enum.ts" afterDir="false" />+ <change beforePath="$PROJECT_DIR$/.env" beforeDir="false" afterPath="$PROJECT_DIR$/.env" afterDir="false" />+ <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />+ <change beforePath="$PROJECT_DIR$/src/app/[lng]/hotContent/HotContentCore.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/app/[lng]/hotContent/HotContentCore.tsx" afterDir="false" />+ <change beforePath="$PROJECT_DIR$/src/app/[lng]/hotContent/components/HotContentSidebar/hotContentSidebar.module.scss" beforeDir="false" afterPath="$PROJECT_DIR$/src/app/[lng]/hotContent/components/HotContentSidebar/hotContentSidebar.module.scss" afterDir="false" />+ <change beforePath="$PROJECT_DIR$/src/app/[lng]/hotContent/components/HotContentSidebar/index.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/app/[lng]/hotContent/components/HotContentSidebar/index.tsx" afterDir="false" />+ <change beforePath="$PROJECT_DIR$/src/app/[lng]/hotContent/hotContent.module.scss" beforeDir="false" afterPath="$PROJECT_DIR$/src/app/[lng]/hotContent/hotContent.module.scss" afterDir="false" />+ <change beforePath="$PROJECT_DIR$/src/app/[lng]/hotContent/useHotContent.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/app/[lng]/hotContent/useHotContent.ts" afterDir="false" /></list><option name="SHOW_DIALOG" value="false" /><option name="HIGHLIGHT_CONFLICTS" value="true" />@@ -214,14 +222,6 @@<workItem from="1757687709611" duration="2478000" /><workItem from="1757902659875" duration="8213000" /></task>- <task id="LOCAL-00011" summary="feat(日历): 删除任务、修改任务时间接入API,删除任务完成">- <option name="closed" value="true" />- <created>1752153478814</created>- <option name="number" value="00011" />- <option name="presentableId" value="LOCAL-00011" />- <option name="project" value="LOCAL" />- <updated>1752153478814</updated>- </task><task id="LOCAL-00012" summary="fix(发布): 默认返回快手参数"><option name="closed" value="true" /><created>1752219562256</created>@@ -606,7 +606,15 @@<option name="project" value="LOCAL" /><updated>1757929872003</updated></task>- <option name="localTasksCounter" value="60" />+ <task id="LOCAL-00060" summary="feat(热门内容): 恢复新热门内容">+ <option name="closed" value="true" />+ <created>1757930268660</created>+ <option name="number" value="00060" />+ <option name="presentableId" value="LOCAL-00060" />+ <option name="project" value="LOCAL" />+ <updated>1757930268660</updated>+ </task>+ <option name="localTasksCounter" value="61" /><servers /></component><component name="TypeScriptGeneratedFilesManager">@@ -669,7 +677,6 @@<option name="CHECK_CODE_SMELLS_BEFORE_PROJECT_COMMIT" value="false" /><option name="CHECK_NEW_TODO" value="false" /><option name="ADD_EXTERNAL_FILES_SILENTLY" value="true" />- <MESSAGE value="fix: 账号过滤不支持的三个平台:视频号、小红书、抖音" /><MESSAGE value="feat: password 密码登录、重置密码,添加md5加密" /><MESSAGE value="fix: 将之前转发的逻辑改为直连" /><MESSAGE value="fix: 删除代理地址" />@@ -694,6 +701,7 @@<MESSAGE value="feat(数据统计): 国际化处理完成" /><MESSAGE value="feat(数据统计): 1. echarts图优化。 2. 平台名称进行国际化。" /><MESSAGE value="feat(数据统计): 添加昨日新增" />- <option name="LAST_COMMIT_MESSAGE" value="feat(数据统计): 添加昨日新增" />+ <MESSAGE value="feat(热门内容): 恢复新热门内容" />+ <option name="LAST_COMMIT_MESSAGE" value="feat(热门内容): 恢复新热门内容" /></component></project>\ No newline at end of filediff --git a/src/app/[lng]/hotContent/HotContentCore.tsx b/src/app/[lng]/hotContent/HotContentCore.tsxindex 2bed3c69..fd261257 100644--- a/src/app/[lng]/hotContent/HotContentCore.tsx+++ b/src/app/[lng]/hotContent/HotContentCore.tsx@@ -1,11 +1,42 @@"use client";import styles from "./hotContent.module.scss";import HotContentSidebar from "@/app/[lng]/hotContent/components/HotContentSidebar";+import HotContent from "@/app/[lng]/hotContent/components/HotContent";+import { useHotContent } from "@/app/[lng]/hotContent/useHotContent";+import { useShallow } from "zustand/react/shallow";+import { HotType } from "@/app/[lng]/hotContent/hotContent.enum";+import HotEvent from "@/app/[lng]/hotContent/components/HotEvent";+import HotFeatures from "@/app/[lng]/hotContent/components/HotFeatures";+import HotTitle from "@/app/[lng]/hotContent/components/HotTitle";+import { Spin } from "antd";export const HotContentCore = () => {+ const { hotType, pageLoading } = useHotContent(+ useShallow((state) => ({+ hotType: state.hotType,+ pageLoading: state.pageLoading,+ })),+ );+return (- <div className={styles.hotContent}>+ <Spin+ spinning={pageLoading}+ size="large"+ wrapperClassName={styles.hotContent}+ ><HotContentSidebar />- </div>++ <div className="hotContent-content">+ {hotType === HotType.hotContent ? (+ <HotContent />+ ) : hotType === HotType.hotEvent ? (+ <HotEvent />+ ) : hotType === HotType.hotFeatures ? (+ <HotFeatures />+ ) : (+ <HotTitle />+ )}+ </div>+ </Spin>);};diff --git a/src/app/[lng]/hotContent/components/HotContent/index.tsx b/src/app/[lng]/hotContent/components/HotContent/index.tsxnew file mode 100644index 00000000..7dc3a420--- /dev/null+++ b/src/app/[lng]/hotContent/components/HotContent/index.tsx@@ -0,0 +1,70 @@+import {+ ForwardedRef,+ forwardRef,+ memo,+ 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 { PlatformRanking } from "@/api/hot";++export interface IHotContentRef {}++export interface IHotContentProps {}++const HotContent = memo(+ forwardRef(({}: IHotContentProps, ref: ForwardedRef<IHotContentRef>) => {+ const { labelData, rankingData, datesData, twoMenuKey } = useHotContent(+ useShallow((state) => ({+ labelData: state.labelData,+ rankingData: state.rankingData,+ datesData: state.datesData,+ twoMenuKey: state.twoMenuKey,+ })),+ );+ const lastSelectedLabelInfo = useRef<{+ ranking?: PlatformRanking;+ labelData?: string[];+ datesData?: string[];+ }>();+ // 当前选中的标签+ const [labelValue, setLabelValue] = useState("全部");++ // 获取当前选中的标签、日期、榜单+ const selectedLabelInfo = useMemo(() => {+ const platId = twoMenuKey.split("_")[1];+ const ranking = rankingData[platId] ?? {};++ // 判断 ranking 是否为空对象+ const isEmptyRanking = !ranking || Object.keys(ranking).length === 0;++ if (isEmptyRanking && lastSelectedLabelInfo.current) {+ return lastSelectedLabelInfo.current;+ }++ const value = {+ ranking,+ labelData: labelData[ranking?.type] || [],+ datesData: datesData[platId] || [],+ };++ lastSelectedLabelInfo.current = value;+ return value;+ }, [labelData, rankingData, datesData, twoMenuKey]);++ return (+ <div>+ <HotContentLabel+ labels={["全部", ...(selectedLabelInfo.labelData ?? [])]}+ value={labelValue}+ onChange={(value) => setLabelValue(value)}+ />+ </div>+ );+ }),+);++export default HotContent;diff --git a/src/app/[lng]/hotContent/components/HotContentLabel/hotContentLabel.module.scss b/src/app/[lng]/hotContent/components/HotContentLabel/hotContentLabel.module.scssnew file mode 100644index 00000000..4493c80f--- /dev/null+++ b/src/app/[lng]/hotContent/components/HotContentLabel/hotContentLabel.module.scss@@ -0,0 +1,31 @@+.hotContentLabelWrapper {+ position: relative;++ :global {+ .hotContentLabel {+ display: flex;+ gap: 10px;+ flex-wrap: wrap;+ padding-right: 35px;++ .hotContentLabel-item {+ cursor: pointer;+ padding: 4px 8px;+ border-radius: 6px;++ &--active {+ background: var(--colorPrimary1);+ color: var(--colorPrimary5);+ }+ &:hover {+ color: var(--colorPrimary5);+ }+ }+ }+ .hotContentLabel-toggle {+ position: absolute;+ right: 0;+ top: 4px;+ }+ }+}diff --git a/src/app/[lng]/hotContent/components/HotContentLabel/index.tsx b/src/app/[lng]/hotContent/components/HotContentLabel/index.tsxnew file mode 100644index 00000000..0245252e--- /dev/null+++ b/src/app/[lng]/hotContent/components/HotContentLabel/index.tsx@@ -0,0 +1,85 @@+import {+ ForwardedRef,+ forwardRef,+ memo,+ useRef,+ useState,+ useLayoutEffect,+} from "react";+import styles from "./hotContentLabel.module.scss";++export interface IHotContentLabelRef {}++export interface IHotContentLabelProps {+ labels: string[];+ value: string;+ onChange: (label: string) => void;+}++const HotContentLabel = memo(+ forwardRef(+ (+ { labels, value, onChange }: IHotContentLabelProps,+ ref: ForwardedRef<IHotContentLabelRef>,+ ) => {+ const listRef = useRef<HTMLUListElement>(null);+ const [expanded, setExpanded] = useState(false);+ const [showToggle, setShowToggle] = useState(false);+ const [collapsedHeight, setCollapsedHeight] = useState(0);+ const [fullHeight, setFullHeight] = useState(0);++ useLayoutEffect(() => {+ const ul = listRef.current;+ if (ul) {+ const firstLi = ul.querySelector("li");+ if (firstLi) {+ const lineHeight = firstLi.getBoundingClientRect().height;+ setCollapsedHeight(lineHeight);+ setFullHeight(ul.scrollHeight);+ setShowToggle(ul.scrollHeight > lineHeight + 2);+ }+ }+ }, [labels]);++ return (+ <div className={styles.hotContentLabelWrapper}>+ <ul+ className="hotContentLabel"+ ref={listRef}+ style={{+ maxHeight: expanded ? fullHeight : collapsedHeight,+ overflow: "hidden",+ transition: "max-height 0.3s cubic-bezier(0.4,0,0.2,1)",+ }}+ >+ {labels.map((label) => (+ <li+ key={label}+ className={`hotContentLabel-item ${+ label === value ? "hotContentLabel-item--active" : ""+ }`}+ title={label}+ onClick={() => onChange(label)}+ >+ {label}+ </li>+ ))}+ </ul>+ {showToggle && (+ <a+ className="hotContentLabel-toggle"+ onClick={(e) => {+ e.preventDefault();+ setExpanded((v) => !v);+ }}+ >+ {expanded ? "收起" : "展开"}+ </a>+ )}+ </div>+ );+ },+ ),+);++export default HotContentLabel;diff --git a/src/app/[lng]/hotContent/components/HotContentSidebar/hotContentSidebar.module.scss b/src/app/[lng]/hotContent/components/HotContentSidebar/hotContentSidebar.module.scssindex b69e8022..7b9eaa5a 100644--- a/src/app/[lng]/hotContent/components/HotContentSidebar/hotContentSidebar.module.scss+++ b/src/app/[lng]/hotContent/components/HotContentSidebar/hotContentSidebar.module.scss@@ -1,4 +1,8 @@.hotContentSidebar {+ height: 100%;:global {+ .ant-menu {+ height: 100%;+ }}}\ No newline at end of filediff --git a/src/app/[lng]/hotContent/components/HotContentSidebar/index.tsx b/src/app/[lng]/hotContent/components/HotContentSidebar/index.tsxindex c66cb5d7..54fd73ae 100644--- a/src/app/[lng]/hotContent/components/HotContentSidebar/index.tsx+++ b/src/app/[lng]/hotContent/components/HotContentSidebar/index.tsx@@ -1,4 +1,4 @@-import { ForwardedRef, forwardRef, memo, useMemo } from "react";+import { ForwardedRef, forwardRef, memo, useEffect, useMemo } from "react";import styles from "./hotContentSidebar.module.scss";import React from "react";import Icon from "@ant-design/icons";@@ -8,6 +8,9 @@ import HotContentSvg from "../../svgs/hotContent.svg";import HotEventSvg from "../../svgs/hotEvent.svg";import HotFeaturesSvg from "../../svgs/hotFeatures.svg";import HotTitleSvg from "../../svgs/hotTitle.svg";+import { HotType } from "@/app/[lng]/hotContent/hotContent.enum";+import { useShallow } from "zustand/react/shallow";+import { useHotContent } from "@/app/[lng]/hotContent/useHotContent";type MenuItem = GetProp<MenuProps, "items">[number];@@ -15,45 +18,134 @@ export interface IHotContentSidebarRef {}export interface IHotContentSidebarProps {}+const yikaOss = process.env.NEXT_PUBLIC_YIKA_OSS_HOST;+const HotContentSidebar = memo(forwardRef(({}: IHotContentSidebarProps, ref: ForwardedRef<IHotContentSidebarRef>) => {+ const {+ setHotType,+ hotType,+ hotContentPlatformList,+ twoMenuKey,+ setTwoMenuKey,+ init,+ hotTitlePlatformList,+ changeHotContentPlatform,+ } = useHotContent(+ useShallow((state) => ({+ setHotType: state.setHotType,+ hotType: state.hotType,+ hotContentPlatformList: state.hotContentPlatformList,+ setTwoMenuKey: state.setTwoMenuKey,+ twoMenuKey: state.twoMenuKey,+ init: state.init,+ hotTitlePlatformList: state.hotTitlePlatformList,+ changeHotContentPlatform: state.changeHotContentPlatform,+ })),+ );+const items = useMemo(() => {const items: MenuItem[] = [{- key: "1",+ key: HotType.hotContent,icon: <Icon component={HotContentSvg} />,- label: "热门内容",+ label: <b>热门内容</b>,+ children: hotContentPlatformList.map((platform) => ({+ key: `${HotType.hotContent}_${platform.id}`,+ label: platform.name,+ icon: (+ <img+ src={`${yikaOss}/${platform.icon}`}+ style={{ width: "18px" }}+ />+ ),+ })),},{- key: "2",+ key: HotType.hotEvent,icon: <Icon component={HotEventSvg} />,- label: "热点事件",+ label: <b>热点事件</b>,},{- key: "3",+ key: HotType.hotFeatures,icon: <Icon component={HotFeaturesSvg} />,- label: "热门专题",+ label: <b>热门专题</b>,+ children: [+ {+ key: "AIGC",+ label: "AIGC",+ },+ {+ key: "短剧",+ label: "短剧",+ },+ {+ key: "文旅",+ label: "文旅",+ },+ {+ key: "内容出海",+ label: "内容出海",+ },+ ],},{- key: "4",+ key: HotType.hotTitle,icon: <Icon component={HotTitleSvg} />,- label: "爆款标题",+ label: <b>爆款标题</b>,+ children: hotTitlePlatformList.map((platform) => ({+ key: `${HotType.hotTitle}_${platform.id}`,+ label: platform.name,+ icon: (+ <img+ src={`${yikaOss}/${platform.icon}`}+ style={{ width: "18px" }}+ />+ ),+ })),},];return items;- }, []);+ }, [hotContentPlatformList, hotTitlePlatformList]);- console.log(HotContentSvg);+ useEffect(() => {+ init();+ }, [init]);return (<div className={styles.hotContentSidebar}><Menu- style={{ width: 256 }}- defaultSelectedKeys={["1"]}- defaultOpenKeys={["sub1"]}+ style={{ width: 180 }}+ defaultSelectedKeys={[hotType]}+ defaultOpenKeys={[+ HotType.hotContent,+ HotType.hotEvent,+ HotType.hotFeatures,+ HotType.hotTitle,+ ]}+ selectedKeys={twoMenuKey ? [twoMenuKey, hotType] : [hotType]}+ onClick={(e) => {+ const hotType = e["keyPath"][e["keyPath"].length - 1] as HotType;+ // 热门内容分类设置+ setHotType(hotType);++ switch (hotType) {+ case HotType.hotContent:+ changeHotContentPlatform(e.key);+ break;+ }++ if (e.keyPath.length === 2) {+ // 侧边栏二级菜单选择+ setTwoMenuKey(e.key);+ } else {+ setTwoMenuKey("");+ }+ }}items={items}mode="inline"+ inlineIndent={10}/></div>);diff --git a/src/app/[lng]/hotContent/components/HotEvent/index.tsx b/src/app/[lng]/hotContent/components/HotEvent/index.tsxnew file mode 100644index 00000000..ffbaed80--- /dev/null+++ b/src/app/[lng]/hotContent/components/HotEvent/index.tsx@@ -0,0 +1,26 @@+import {+ ForwardedRef,+ forwardRef,+ memo+} from "react";++export interface IHotEventRef {+}++export interface IHotEventProps {+}++const HotEvent = memo(+ forwardRef(+ (+ {}: IHotEventProps,+ ref: ForwardedRef<IHotEventRef>+ ) => {+ return (+ <div></div>+ );+ }+ )+);++export default HotEvent;diff --git a/src/app/[lng]/hotContent/components/HotFeatures/index.tsx b/src/app/[lng]/hotContent/components/HotFeatures/index.tsxnew file mode 100644index 00000000..91132ba6--- /dev/null+++ b/src/app/[lng]/hotContent/components/HotFeatures/index.tsx@@ -0,0 +1,26 @@+import {+ ForwardedRef,+ forwardRef,+ memo+} from "react";++export interface IHotFeaturesRef {+}++export interface IHotFeaturesProps {+}++const HotFeatures = memo(+ forwardRef(+ (+ {}: IHotFeaturesProps,+ ref: ForwardedRef<IHotFeaturesRef>+ ) => {+ return (+ <div></div>+ );+ }+ )+);++export default HotFeatures;diff --git a/src/app/[lng]/hotContent/components/HotTitle/index.tsx b/src/app/[lng]/hotContent/components/HotTitle/index.tsxnew file mode 100644index 00000000..79ac1ed0--- /dev/null+++ b/src/app/[lng]/hotContent/components/HotTitle/index.tsx@@ -0,0 +1,26 @@+import {+ ForwardedRef,+ forwardRef,+ memo+} from "react";++export interface IHotTitleRef {+}++export interface IHotTitleProps {+}++const HotTitle = memo(+ forwardRef(+ (+ {}: IHotTitleProps,+ ref: ForwardedRef<IHotTitleRef>+ ) => {+ return (+ <div></div>+ );+ }+ )+);++export default HotTitle;diff --git a/src/app/[lng]/hotContent/hotContent.enum.ts b/src/app/[lng]/hotContent/hotContent.enum.tsnew file mode 100644index 00000000..65a306d4--- /dev/null+++ b/src/app/[lng]/hotContent/hotContent.enum.ts@@ -0,0 +1,6 @@+export enum HotType {+ hotContent = "hotContent",+ hotEvent = "hotEvent",+ hotFeatures = "HotFeatures",+ hotTitle = "hotTitle",+}diff --git a/src/app/[lng]/hotContent/hotContent.module.scss b/src/app/[lng]/hotContent/hotContent.module.scssindex 72c7361a..f36c9db4 100644--- a/src/app/[lng]/hotContent/hotContent.module.scss+++ b/src/app/[lng]/hotContent/hotContent.module.scss@@ -1,4 +1,19 @@.hotContent {+ display: flex;+ height: 100%;+ border-top: 1px solid var(--grayColor1);:global {+ .ant-spin-container {+ display: flex;+ flex: 1;+ .hotContent-content {+ padding: 15px 20px;+ box-sizing: border-box;+ flex: 1;+ min-width: 0;+ min-height: 0;+ overflow: auto;+ }+ }}}\ No newline at end of filediff --git a/src/app/[lng]/hotContent/useHotContent.ts b/src/app/[lng]/hotContent/useHotContent.tsindex 8318e540..6d5ef028 100644--- a/src/app/[lng]/hotContent/useHotContent.ts+++ b/src/app/[lng]/hotContent/useHotContent.ts@@ -1,10 +1,47 @@import { create } from "zustand";import { combine } from "zustand/middleware";import lodash from "lodash";+import { Platform, platformApi, PlatformRanking } from "@/api/hot";+import { HotType } from "@/app/[lng]/hotContent/hotContent.enum";-export interface IHotContentStore {}+export interface IHotContentStore {+ // 当前选择的 热点分类+ hotType: HotType;+ // 热门内容平台list+ hotContentPlatformList: Platform[];+ // 爆款标题平台list+ hotTitlePlatformList: Platform[];+ // 数据loading+ dataLoading: boolean;+ // 当前侧边栏二级菜单选择的ID+ twoMenuKey: string;+ // 热门内容页面loading+ pageLoading: boolean;+ // 热门内容的标签数据 key=平台,value=标签数组+ labelData: {+ [key: string]: string[];+ };+ // 热门内容的榜单数据 key=平台ID,value=榜单数据+ rankingData: {+ [key: string]: PlatformRanking;+ };+ // 日期数据 key=平台ID,value=日期数据+ datesData: {+ [key: string]: string[];+ };+}-const store: IHotContentStore = {};+const store: IHotContentStore = {+ hotType: HotType.hotContent,+ hotContentPlatformList: [],+ dataLoading: false,+ twoMenuKey: "",+ hotTitlePlatformList: [],+ pageLoading: false,+ labelData: {},+ rankingData: {},+ datesData: {},+};const getStore = () => {return lodash.cloneDeep(store);@@ -19,7 +56,95 @@ export const useHotContent = create(...getStore(),},(set, get, storeApi) => {- const methods = {};+ const methods = {+ // 设置 当前侧边栏二级菜单选择的ID+ setTwoMenuKey(twoMenuKey: string) {+ set({ twoMenuKey });+ },+ // 设置当前选择的 热点分类+ setHotType(hotType: HotType) {+ set({ hotType });+ },++ // 初始化+ async init() {+ set({ pageLoading: true });+ await Promise.all([+ methods.getHotContentPlatform(),+ methods.getHotTitlePlatform(),+ ]);+ set({ pageLoading: false });+ },++ // 获取热门内容平台+ async getHotContentPlatform() {+ const res = await platformApi.getPlatformList();+ const twoMenuKey = `${HotType.hotContent}_${res?.data?.[0]?.id}`;++ set({+ hotContentPlatformList: res?.data,+ twoMenuKey,+ });++ methods.changeHotContentPlatform(twoMenuKey);+ },++ // 获取爆款标题平台+ async getHotTitlePlatform() {+ const res = await platformApi.findPlatformsWithData();++ set({+ hotTitlePlatformList: res?.data,+ });+ },++ // 热门内容平台切换+ async changeHotContentPlatform(platformId: string) {+ const { rankingData } = get();+ platformId = platformId.split("_")[1];++ set({+ pageLoading: true,+ });++ if (!rankingData[platformId]) {+ const res = await platformApi.getPlatformRanking(platformId);+ if (res?.data?.length) {+ const newRankingData = {+ ...rankingData,+ [platformId]: res.data[0],+ };+ set({ rankingData: newRankingData });+ }+ }++ const rankingItem = get().rankingData[platformId];+ // 获取标签和日期数据+ if (!get().labelData[rankingItem.type]) {+ await Promise.all([+ platformApi.getRankingLabel(rankingItem.id),+ platformApi.getRankingDates(rankingItem.id),+ ]).then(([labelRes, dateRes]) => {+ const newLabelData = {+ ...get().labelData,+ [rankingItem.type]: labelRes!.data,+ };+ const newDatesData = {+ ...get().datesData,+ [platformId]: dateRes!.data,+ };+ set({+ labelData: newLabelData,+ datesData: newDatesData,+ });+ });+ }++ set({+ pageLoading: false,+ });+ },+ };return methods;},