Skip to content

Let's use AI to Earn!

feat(数据统计): echarts图接入API

gaoSire868234f3dd0
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index db501c13..b915fe23 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,13 +4,10 @@
<option name="autoReloadType" value="NONE" />
</component>
<component name="ChangeListManager">
- <list default="true" id="8ce961ad-7c9e-494c-bc53-9ecde4358af8" name="更改" comment="feat(数据统计): 接入数据API,并且分拣数据">
- <change afterPath="$PROJECT_DIR$/pnpm-lock.yaml" afterDir="false" />
- <change afterPath="$PROJECT_DIR$/src/app/[lng]/dataStatistics/echart/drawDataStatisticsEchartLine.ts" afterDir="false" />
+ <list default="true" id="8ce961ad-7c9e-494c-bc53-9ecde4358af8" name="更改" comment="feat(数据统计): 引入echarts">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
- <change beforePath="$PROJECT_DIR$/package.json" beforeDir="false" afterPath="$PROJECT_DIR$/package.json" afterDir="false" />
- <change beforePath="$PROJECT_DIR$/src/app/[lng]/dataStatistics/components/DataStatisticsDetails/dataStatisticsDetails.module.scss" beforeDir="false" afterPath="$PROJECT_DIR$/src/app/[lng]/dataStatistics/components/DataStatisticsDetails/dataStatisticsDetails.module.scss" afterDir="false" />
- <change beforePath="$PROJECT_DIR$/src/app/[lng]/dataStatistics/components/DataStatisticsDetails/index.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/app/[lng]/dataStatistics/components/DataStatisticsDetails/index.tsx" 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" />
</list>
<option name="SHOW_DIALOG" value="false" />
@@ -211,15 +208,8 @@
<workItem from="1757646405605" duration="66000" />
<workItem from="1757646484870" duration="466000" />
<workItem from="1757647784882" duration="2426000" />
- <workItem from="1757656251307" duration="25080000" />
- </task>
- <task id="LOCAL-00003" summary="fix: platInfo添加一些非空判断">
- <option name="closed" value="true" />
- <created>1751986703860</created>
- <option name="number" value="00003" />
- <option name="presentableId" value="LOCAL-00003" />
- <option name="project" value="LOCAL" />
- <updated>1751986703860</updated>
+ <workItem from="1757656251307" duration="25699000" />
+ <workItem from="1757687709611" duration="257000" />
</task>
<task id="LOCAL-00004" summary="feat: 发布记录展示添加状态展示">
<option name="closed" value="true" />
@@ -605,7 +595,15 @@
<option name="project" value="LOCAL" />
<updated>1757686166523</updated>
</task>
- <option name="localTasksCounter" value="52" />
+ <task id="LOCAL-00052" summary="feat(数据统计): 引入echarts">
+ <option name="closed" value="true" />
+ <created>1757687087834</created>
+ <option name="number" value="00052" />
+ <option name="presentableId" value="LOCAL-00052" />
+ <option name="project" value="LOCAL" />
+ <updated>1757687087834</updated>
+ </task>
+ <option name="localTasksCounter" value="53" />
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
@@ -668,7 +666,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="选择用户弹框恢复" />
<MESSAGE value="feat: 恢复选择账户弹框" />
<MESSAGE value="feat: 尝试多语言SEO优化,添加静态站点配置" />
<MESSAGE value="fix: 解决404问题" />
@@ -693,6 +690,7 @@
<MESSAGE value="feat(数据统计): 顶部账号完成" />
<MESSAGE value="feat(数据统计): 数据明细完成" />
<MESSAGE value="feat(数据统计): 接入数据API,并且分拣数据" />
- <option name="LAST_COMMIT_MESSAGE" value="feat(数据统计): 接入数据API,并且分拣数据" />
+ <MESSAGE value="feat(数据统计): 引入echarts" />
+ <option name="LAST_COMMIT_MESSAGE" value="feat(数据统计): 引入echarts" />
</component>
</project>
\ No newline at end of file
diff --git a/src/app/[lng]/dataStatistics/DataStatisticsCore.tsx b/src/app/[lng]/dataStatistics/DataStatisticsCore.tsx
index 26ca3e17..b4abea81 100644
--- a/src/app/[lng]/dataStatistics/DataStatisticsCore.tsx
+++ b/src/app/[lng]/dataStatistics/DataStatisticsCore.tsx
@@ -7,6 +7,7 @@ import { useShallow } from "zustand/react/shallow";
import { useEffect } from "react";
import { useAccountStore } from "@/store/account";
import DataStatisticsDetails from "@/app/[lng]/dataStatistics/components/DataStatisticsDetails";
+import { Spin } from "antd";
export const DataStatisticsCore = () => {
const {
@@ -19,6 +20,7 @@ export const DataStatisticsCore = () => {
filteredAccountList,
currentDetailType,
sortingData,
+ loading,
} = useDataStatisticsStore(
useShallow((state) => ({
setChoosedGroupIds: state.setChoosedGroupIds,
@@ -30,6 +32,7 @@ export const DataStatisticsCore = () => {
filteredAccountList: state.filteredAccountList,
currentDetailType: state.currentDetailType,
sortingData: state.sortingData,
+ loading: state.loading,
})),
);
const { accountGroupList, accountList } = useAccountStore(
@@ -71,9 +74,11 @@ export const DataStatisticsCore = () => {
}, [choosedGroupIds, accountList]);
return (
- <div className={styles.dataStatistics}>
- <DataStatisticsHeader />
- <DataStatisticsDetails />
- </div>
+ <Spin spinning={loading}>
+ <div className={styles.dataStatistics}>
+ <DataStatisticsHeader />
+ <DataStatisticsDetails />
+ </div>
+ </Spin>
);
};
diff --git a/src/app/[lng]/dataStatistics/echart/drawDataStatisticsEchartLine.ts b/src/app/[lng]/dataStatistics/echart/drawDataStatisticsEchartLine.ts
index e1109c04..10ca8e95 100644
--- a/src/app/[lng]/dataStatistics/echart/drawDataStatisticsEchartLine.ts
+++ b/src/app/[lng]/dataStatistics/echart/drawDataStatisticsEchartLine.ts
@@ -1,18 +1,27 @@
import * as echarts from "echarts";
+import { useDataStatisticsStore } from "../useDataStatistics"; // 引入store
type EChartsOption = echarts.EChartsOption;
export default function drawDataStatisticsEchartLine(elId: string) {
const chartDom = document.getElementById(elId)!;
+ // 先销毁已有实例,防止重复初始化报错
+ if (echarts.getInstanceByDom(chartDom)) {
+ echarts.dispose(chartDom);
+ }
const myChart = echarts.init(chartDom);
+ // 获取store中的echartData
+ const { legend, xAxis, series } =
+ useDataStatisticsStore.getState().echartData;
+
const option: EChartsOption = {
tooltip: {
trigger: "axis",
},
legend: {
top: 25,
- data: ["Email", "Union Ads", "Video Ads", "Direct", "Search Engine"],
+ data: legend,
},
grid: {
left: "3%",
@@ -28,43 +37,13 @@ export default function drawDataStatisticsEchartLine(elId: string) {
xAxis: {
type: "category",
boundaryGap: false,
- data: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
+ data: xAxis,
},
yAxis: {
type: "value",
},
- series: [
- {
- name: "Email",
- type: "line",
- stack: "Total",
- data: [120, 132, 101, 134, 90, 230, 210],
- },
- {
- name: "Union Ads",
- type: "line",
- stack: "Total",
- data: [220, 182, 191, 234, 290, 330, 310],
- },
- {
- name: "Video Ads",
- type: "line",
- stack: "Total",
- data: [150, 232, 201, 154, 190, 330, 410],
- },
- {
- name: "Direct",
- type: "line",
- stack: "Total",
- data: [320, 332, 301, 334, 390, 330, 320],
- },
- {
- name: "Search Engine",
- type: "line",
- stack: "Total",
- data: [820, 932, 901, 934, 1290, 1330, 1320],
- },
- ],
+ // @ts-ignore
+ series: series,
};
if (option) {
diff --git a/src/app/[lng]/dataStatistics/useDataStatistics.tsx b/src/app/[lng]/dataStatistics/useDataStatistics.tsx
index 9e247f45..cb5af9b4 100644
--- a/src/app/[lng]/dataStatistics/useDataStatistics.tsx
+++ b/src/app/[lng]/dataStatistics/useDataStatistics.tsx
@@ -38,16 +38,16 @@ export interface IDataStatisticsStore {
originData?: StatisticsPeriodModel;
// loading
loading: boolean;
- // echart 数据
+ // echart 数据,直接适配 ECharts 格式
echartData: {
- // 平台,格式:['抖音', '微信', '快手', '小红书']
- platforms: string[];
- // 日期,格式:['2023-10-01', '2023-10-02', ...]
- dates: string[];
- // 数据,格式:{'抖音': [100, 200, ...], '微信': [150, 250, ...], ...}
- data: {
- [key: string]: number[];
- };
+ legend: string[];
+ xAxis: string[];
+ series: {
+ name: string;
+ type: string;
+ stack: string;
+ data: number[];
+ }[];
};
}
@@ -103,9 +103,9 @@ const state: IDataStatisticsStore = {
loading: false,
originData: undefined,
echartData: {
- platforms: [],
- dates: [],
- data: {},
+ legend: [],
+ xAxis: [],
+ series: [],
},
};
@@ -176,7 +176,7 @@ export const useDataStatisticsStore = create(
})),
});
- // 2. 生成折线图数据
+ // 2. 生成 ECharts 适配数据
const currentField = get().currentDetailType;
// 日期
@@ -211,11 +211,21 @@ export const useDataStatisticsStore = create(
});
});
+ // 组装 ECharts 格式
+ const legend = platforms;
+ const xAxis = dates;
+ const series = platforms.map((p) => ({
+ name: p,
+ type: "line",
+ stack: "Total",
+ data: chartData[p],
+ }));
+
set({
echartData: {
- platforms,
- dates,
- data: chartData,
+ legend,
+ xAxis,
+ series,
},
});