Skip to content

Let's use AI to Earn!

feat(数据统计): 数据大体完成

gaoSir7a9adb126fae
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index b915fe23..1d45a6e9 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,8 +4,11 @@
<option name="autoReloadType" value="NONE" />
</component>
<component name="ChangeListManager">
- <list default="true" id="8ce961ad-7c9e-494c-bc53-9ecde4358af8" name="更改" comment="feat(数据统计): 引入echarts">
+ <list default="true" id="8ce961ad-7c9e-494c-bc53-9ecde4358af8" name="更改" comment="feat(数据统计): echarts图接入API">
+ <change afterPath="$PROJECT_DIR$/src/app/[lng]/dataStatistics/components/DataStatisticsTable/dataStatisticsTable.module.scss" afterDir="false" />
+ <change afterPath="$PROJECT_DIR$/src/app/[lng]/dataStatistics/components/DataStatisticsTable/index.tsx" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
+ <change beforePath="$PROJECT_DIR$/src/api/types/dataStatistics.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/api/types/dataStatistics.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/app/[lng]/dataStatistics/DataStatisticsCore.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/app/[lng]/dataStatistics/DataStatisticsCore.tsx" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/app/[lng]/dataStatistics/echart/drawDataStatisticsEchartLine.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/app/[lng]/dataStatistics/echart/drawDataStatisticsEchartLine.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/app/[lng]/dataStatistics/useDataStatistics.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/app/[lng]/dataStatistics/useDataStatistics.tsx" afterDir="false" />
@@ -23,8 +26,8 @@
<list>
<option value="vue3组件模板" />
<option value="TypeScript JSX File" />
- <option value="tsx组件模板" />
<option value="TypeScript File" />
+ <option value="tsx组件模板" />
</list>
</option>
</component>
@@ -209,15 +212,7 @@
<workItem from="1757646484870" duration="466000" />
<workItem from="1757647784882" duration="2426000" />
<workItem from="1757656251307" duration="25699000" />
- <workItem from="1757687709611" duration="257000" />
- </task>
- <task id="LOCAL-00004" summary="feat: 发布记录展示添加状态展示">
- <option name="closed" value="true" />
- <created>1752049408523</created>
- <option name="number" value="00004" />
- <option name="presentableId" value="LOCAL-00004" />
- <option name="project" value="LOCAL" />
- <updated>1752049408523</updated>
+ <workItem from="1757687709611" duration="2157000" />
</task>
<task id="LOCAL-00005" summary="feat(发布弹框): 上传图片和上传视频完成">
<option name="closed" value="true" />
@@ -603,7 +598,15 @@
<option name="project" value="LOCAL" />
<updated>1757687087834</updated>
</task>
- <option name="localTasksCounter" value="53" />
+ <task id="LOCAL-00053" summary="feat(数据统计): echarts图接入API">
+ <option name="closed" value="true" />
+ <created>1757688007998</created>
+ <option name="number" value="00053" />
+ <option name="presentableId" value="LOCAL-00053" />
+ <option name="project" value="LOCAL" />
+ <updated>1757688007999</updated>
+ </task>
+ <option name="localTasksCounter" value="54" />
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
@@ -666,7 +669,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="feat: 恢复选择账户弹框" />
<MESSAGE value="feat: 尝试多语言SEO优化,添加静态站点配置" />
<MESSAGE value="fix: 解决404问题" />
<MESSAGE value="chore: b站校验优化" />
@@ -691,6 +693,7 @@
<MESSAGE value="feat(数据统计): 数据明细完成" />
<MESSAGE value="feat(数据统计): 接入数据API,并且分拣数据" />
<MESSAGE value="feat(数据统计): 引入echarts" />
- <option name="LAST_COMMIT_MESSAGE" value="feat(数据统计): 引入echarts" />
+ <MESSAGE value="feat(数据统计): echarts图接入API" />
+ <option name="LAST_COMMIT_MESSAGE" value="feat(数据统计): echarts图接入API" />
</component>
</project>
\ No newline at end of file
diff --git a/src/api/types/dataStatistics.ts b/src/api/types/dataStatistics.ts
index 222cc1d4..31438ad5 100644
--- a/src/api/types/dataStatistics.ts
+++ b/src/api/types/dataStatistics.ts
@@ -1,4 +1,6 @@
// getStatisticsPeriodApi 入参
+import { PlatType } from "@/app/config/platConfig";
+
export interface StatisticsPeriodApiParams {
startDate: string;
endDate: string;
@@ -16,7 +18,7 @@ export interface StatisticsPeriodModel {
}
export interface StatisticsPeriodItems {
- platform: string;
+ platform: PlatType;
uid: string;
items?: StatisticsPeriodItems2[];
}
diff --git a/src/app/[lng]/dataStatistics/DataStatisticsCore.tsx b/src/app/[lng]/dataStatistics/DataStatisticsCore.tsx
index b4abea81..992bf0b3 100644
--- a/src/app/[lng]/dataStatistics/DataStatisticsCore.tsx
+++ b/src/app/[lng]/dataStatistics/DataStatisticsCore.tsx
@@ -8,6 +8,7 @@ import { useEffect } from "react";
import { useAccountStore } from "@/store/account";
import DataStatisticsDetails from "@/app/[lng]/dataStatistics/components/DataStatisticsDetails";
import { Spin } from "antd";
+import DataStatisticsTable from "@/app/[lng]/dataStatistics/components/DataStatisticsTable";
export const DataStatisticsCore = () => {
const {
@@ -78,6 +79,7 @@ export const DataStatisticsCore = () => {
<div className={styles.dataStatistics}>
<DataStatisticsHeader />
<DataStatisticsDetails />
+ <DataStatisticsTable />
</div>
</Spin>
);
diff --git a/src/app/[lng]/dataStatistics/components/DataStatisticsTable/dataStatisticsTable.module.scss b/src/app/[lng]/dataStatistics/components/DataStatisticsTable/dataStatisticsTable.module.scss
new file mode 100644
index 00000000..35126f16
--- /dev/null
+++ b/src/app/[lng]/dataStatistics/components/DataStatisticsTable/dataStatisticsTable.module.scss
@@ -0,0 +1,10 @@
+.dataStatisticsTable {
+ margin-top: 20px;
+ :global {
+ .ant-table-thead {
+ .ant-table-cell {
+ padding: 10px 16px;
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/app/[lng]/dataStatistics/components/DataStatisticsTable/index.tsx b/src/app/[lng]/dataStatistics/components/DataStatisticsTable/index.tsx
new file mode 100644
index 00000000..55dfa404
--- /dev/null
+++ b/src/app/[lng]/dataStatistics/components/DataStatisticsTable/index.tsx
@@ -0,0 +1,127 @@
+import React, { ForwardedRef, forwardRef, memo, useMemo } from "react";
+import styles from "./dataStatisticsTable.module.scss";
+import { Table } from "antd";
+import type { TableProps } from "antd";
+import {
+ StatisticsPeriodItems,
+ StatisticsPeriodItems2,
+} from "@/api/types/dataStatistics";
+import { useDataStatisticsStore } from "@/app/[lng]/dataStatistics/useDataStatistics";
+import { useShallow } from "zustand/react/shallow";
+import { useAccountStore } from "@/store/account";
+import AvatarPlat from "@/components/AvatarPlat";
+
+export interface IDataStatisticsTableRef {}
+
+export interface IDataStatisticsTableProps {}
+
+const DataStatisticsTable = memo(
+ forwardRef(
+ (
+ {}: IDataStatisticsTableProps,
+ ref: ForwardedRef<IDataStatisticsTableRef>,
+ ) => {
+ const { originData, dataDetails } = useDataStatisticsStore(
+ useShallow((state) => ({
+ originData: state.originData,
+ dataDetails: state.dataDetails,
+ })),
+ );
+ const { accountList } = useAccountStore(
+ useShallow((state) => ({
+ accountList: state.accountList,
+ })),
+ );
+
+ // key=uid, value=该账号对应的数据,此数据是累加的值
+ const data = useMemo(() => {
+ const d: { [key: string]: Partial<StatisticsPeriodItems2> } = {};
+
+ originData?.items?.map((v) => {
+ if (!d[v.uid]) {
+ d[v.uid] = {
+ commentCount: 0,
+ followingCount: 0,
+ likeCount: 0,
+ fansCount: 0,
+ readCount: 0,
+ collectCount: 0,
+ forwardCount: 0,
+ workCount: 0,
+ };
+ }
+ // 累加该账号的各项数据
+ v.items?.map((item) => {
+ d[v.uid]!.commentCount! += item.commentCount || 0;
+ d[v.uid]!.followingCount! += item.followingCount || 0;
+ d[v.uid]!.likeCount! += item.likeCount || 0;
+ d[v.uid]!.fansCount! += item.fansCount || 0;
+ d[v.uid]!.readCount! += item.readCount || 0;
+ d[v.uid]!.collectCount! += item.collectCount || 0;
+ d[v.uid]!.forwardCount! += item.forwardCount || 0;
+ d[v.uid]!.workCount! += item.workCount || 0;
+ });
+ });
+
+ return d;
+ }, [originData]);
+
+ const columns = useMemo(() => {
+ const columns: TableProps<StatisticsPeriodItems>["columns"] = [
+ {
+ title: "账号",
+ key: "uid",
+ render: (text, item) => {
+ const account = accountList.find((v) => v.uid === item.uid)!;
+
+ return (
+ <div>
+ <AvatarPlat account={account} />
+ <span style={{ display: "inline-block", marginLeft: "10px" }}>
+ {account?.nickname}
+ </span>
+ </div>
+ );
+ },
+ },
+ ];
+
+ dataDetails.map((v) => {
+ columns.push({
+ title: v.title,
+ key: v.value,
+ sorter: (a, b) => {
+ // @ts-ignore
+ const aValue = data[a.uid]?.[v.value] || 0;
+ // @ts-ignore
+ const bValue = data[b.uid]?.[v.value] || 0;
+ return aValue - bValue;
+ },
+ render: (text, item) => {
+ // @ts-ignore
+ return <span>{data[item.uid]?.[v.value] || 0}</span>;
+ },
+ });
+ });
+
+ return columns;
+ }, [accountList, data, dataDetails]);
+
+ return (
+ <div className={styles.dataStatisticsTable}>
+ <Table<StatisticsPeriodItems>
+ columns={columns}
+ key="uid"
+ dataSource={originData?.items?.map((item) => ({
+ ...item,
+ key: item.uid,
+ }))}
+ scroll={{ y: "400px" }}
+ />
+ </div>
+ );
+ },
+ ),
+);
+
+export default DataStatisticsTable;
diff --git a/src/app/[lng]/dataStatistics/echart/drawDataStatisticsEchartLine.ts b/src/app/[lng]/dataStatistics/echart/drawDataStatisticsEchartLine.ts
index 10ca8e95..a0875d9c 100644
--- a/src/app/[lng]/dataStatistics/echart/drawDataStatisticsEchartLine.ts
+++ b/src/app/[lng]/dataStatistics/echart/drawDataStatisticsEchartLine.ts
@@ -5,6 +5,7 @@ type EChartsOption = echarts.EChartsOption;
export default function drawDataStatisticsEchartLine(elId: string) {
const chartDom = document.getElementById(elId)!;
+ const chartDomAny = chartDom as any;
// 先销毁已有实例,防止重复初始化报错
if (echarts.getInstanceByDom(chartDom)) {
echarts.dispose(chartDom);
@@ -49,4 +50,14 @@ export default function drawDataStatisticsEchartLine(elId: string) {
if (option) {
myChart.setOption(option);
}
+
+ // 先移除旧的resize事件监听,防止重复绑定
+ if (chartDomAny._resizeHandler) {
+ window.removeEventListener("resize", chartDomAny._resizeHandler);
+ }
+ function handleResize() {
+ myChart.resize();
+ }
+ window.addEventListener("resize", handleResize);
+ chartDomAny._resizeHandler = handleResize;
}
diff --git a/src/app/[lng]/dataStatistics/useDataStatistics.tsx b/src/app/[lng]/dataStatistics/useDataStatistics.tsx
index cb5af9b4..1b9f07d1 100644
--- a/src/app/[lng]/dataStatistics/useDataStatistics.tsx
+++ b/src/app/[lng]/dataStatistics/useDataStatistics.tsx
@@ -127,10 +127,14 @@ export const useDataStatisticsStore = create(
set({
loading: true,
});
+ // 过滤掉无效的account和account.type
+ const validAccounts = get().filteredAccountList.filter(
+ (account) => account && account.type && account.uid
+ );
const res = await getStatisticsPeriodApi({
startDate: get().timeRangeValue[0].format("YYYY-MM-DD"),
endDate: get().timeRangeValue[1].format("YYYY-MM-DD"),
- queries: get().filteredAccountList.map((account) => ({
+ queries: validAccounts.map((account) => ({
platform: account.type,
uid: account.uid,
})),