diff --git a/apps/web-antd/src/api/mp/statistics/index.ts b/apps/web-antd/src/api/mp/statistics/index.ts index e36073820..47200ff2b 100644 --- a/apps/web-antd/src/api/mp/statistics/index.ts +++ b/apps/web-antd/src/api/mp/statistics/index.ts @@ -1,13 +1,10 @@ -import type { PageParam } from '@vben/request'; - import { requestClient } from '#/api/request'; export namespace MpStatisticsApi { /** 统计查询参数 */ - export interface StatisticsQuery extends PageParam { + export interface StatisticsQuery { accountId: number; - beginDate: string; - endDate: string; + date: Date[]; } /** 消息发送概况数据 */ diff --git a/apps/web-antd/src/views/mp/statistics/chart-options.ts b/apps/web-antd/src/views/mp/statistics/chart-options.ts new file mode 100644 index 000000000..0567136e0 --- /dev/null +++ b/apps/web-antd/src/views/mp/statistics/chart-options.ts @@ -0,0 +1,163 @@ +import type { MpStatisticsApi } from '#/api/mp/statistics'; + +// 用户增减数据图表配置项 +export function userSummaryOption( + data: MpStatisticsApi.UserSummary[], + dates: string[], +): any { + return { + color: ['#67C23A', '#E5323E'], + legend: { + data: ['新增用户', '取消关注的用户'], + }, + tooltip: {}, + xAxis: { + data: dates, + }, + yAxis: { + minInterval: 1, + }, + series: [ + { + name: '新增用户', + type: 'bar', + label: { + show: true, + }, + barGap: 0, + data: data.map((item) => item.newUser), // 新增用户的数据 + }, + { + name: '取消关注的用户', + type: 'bar', + label: { + show: true, + }, + data: data.map((item) => item.cancelUser), // 取消关注的用户的数据 + }, + ], + }; +} + +// 累计用户数据图表配置项 +export function userCumulateOption( + data: MpStatisticsApi.UserCumulate[], + dates: string[], +): any { + return { + legend: { + data: ['累计用户量'], + }, + xAxis: { + type: 'category', + data: dates, + }, + yAxis: { + minInterval: 1, + }, + series: [ + { + name: '累计用户量', + data: data.map((item) => item.cumulateUser), // 累计用户量的数据 + type: 'line', + smooth: true, + label: { + show: true, + }, + }, + ], + }; +} + +// 消息发送概况数据图表配置项 +export function upstreamMessageOption( + data: MpStatisticsApi.UpstreamMessage[], + dates: string[], +): any { + return { + color: ['#67C23A', '#E5323E'], + legend: { + data: ['用户发送人数', '用户发送条数'], + }, + tooltip: {}, + xAxis: { + data: dates, // X 轴的日期范围 + }, + yAxis: { + minInterval: 1, + }, + series: [ + { + name: '用户发送人数', + type: 'line', + smooth: true, + label: { + show: true, + }, + data: data.map((item) => item.msgUser), // 用户发送人数的数据 + }, + { + name: '用户发送条数', + type: 'line', + smooth: true, + label: { + show: true, + }, + data: data.map((item) => item.msgCount), // 用户发送条数的数据 + }, + ], + }; +} + +// 接口分析况数据图表配置项 +export function interfaceSummaryOption( + data: MpStatisticsApi.InterfaceSummary[], + dates: string[], +): any { + return { + color: ['#67C23A', '#E5323E', '#E6A23C', '#409EFF'], + legend: { + data: ['被动回复用户消息的次数', '失败次数', '最大耗时', '总耗时'], + }, + tooltip: {}, + xAxis: { + data: dates, // X 轴的日期范围 + }, + yAxis: {}, + series: [ + { + name: '被动回复用户消息的次数', + type: 'bar', + label: { + show: true, + }, + barGap: 0, + data: data.map((item) => item.callbackCount), // 被动回复用户消息的次数的数据 + }, + { + name: '失败次数', + type: 'bar', + label: { + show: true, + }, + data: data.map((item) => item.failCount), // 失败次数的数据 + }, + { + name: '最大耗时', + type: 'bar', + label: { + show: true, + }, + data: data.map((item) => item.maxTimeCost), // 最大耗时的数据 + }, + { + name: '总耗时', + type: 'bar', + label: { + show: true, + }, + data: data.map((item) => item.totalTimeCost), // 总耗时的数据 + }, + ], + }; +} diff --git a/apps/web-antd/src/views/mp/statistics/data.ts b/apps/web-antd/src/views/mp/statistics/data.ts new file mode 100644 index 000000000..21f3c835b --- /dev/null +++ b/apps/web-antd/src/views/mp/statistics/data.ts @@ -0,0 +1,42 @@ +import type { VbenFormSchema } from '#/adapter/form'; +import type { MpAccountApi } from '#/api/mp/account'; + +import { beginOfDay, endOfDay, formatDateTime } from '@vben/utils'; + +import { getSimpleAccountList } from '#/api/mp/account'; + +let accountList: MpAccountApi.AccountSimple[] = []; +getSimpleAccountList().then((data) => (accountList = data)); + +/** 列表的搜索表单 */ +export function useGridFormSchema(): VbenFormSchema[] { + return [ + { + fieldName: 'accountId', + label: '公众号', + component: 'Select', + componentProps: { + options: accountList.map((item) => ({ + label: item.name, + value: item.id, + })), + placeholder: '请选择公众号', + allowClear: true, + }, + defaultValue: accountList[0]?.id, + }, + { + fieldName: 'dateRange', + label: '时间范围', + component: 'RangePicker', + componentProps: { + format: 'YYYY-MM-DD', + valueFormat: 'YYYY-MM-DD HH:mm:ss', + }, + defaultValue: [ + formatDateTime(beginOfDay(new Date(Date.now() - 3600 * 1000 * 24 * 7))), + formatDateTime(endOfDay(new Date(Date.now() - 3600 * 1000 * 24))), + ] as [Date, Date], + }, + ]; +} diff --git a/apps/web-antd/src/views/mp/statistics/index.vue b/apps/web-antd/src/views/mp/statistics/index.vue index 034e0e623..058e0236d 100644 --- a/apps/web-antd/src/views/mp/statistics/index.vue +++ b/apps/web-antd/src/views/mp/statistics/index.vue @@ -1,28 +1,140 @@