diff --git a/apps/web-ele/src/api/mp/statistics/index.ts b/apps/web-ele/src/api/mp/statistics/index.ts index e36073820..47200ff2b 100644 --- a/apps/web-ele/src/api/mp/statistics/index.ts +++ b/apps/web-ele/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-ele/src/views/mp/account/index.vue b/apps/web-ele/src/views/mp/account/index.vue index 1de294ebc..3127f9eab 100644 --- a/apps/web-ele/src/views/mp/account/index.vue +++ b/apps/web-ele/src/views/mp/account/index.vue @@ -40,7 +40,7 @@ function handleEdit(row: MpAccountApi.Account) { /** 删除账号 */ async function handleDelete(row: MpAccountApi.Account) { - const hideLoading = ElLoading.service({ + const loadingInstance = ElLoading.service({ text: $t('ui.actionMessage.deleting', [row.name]), }); try { @@ -48,13 +48,13 @@ async function handleDelete(row: MpAccountApi.Account) { ElMessage.success($t('ui.actionMessage.deleteSuccess', [row.name])); handleRefresh(); } finally { - hideLoading.close(); + loadingInstance.close(); } } /** 生成二维码 */ async function handleGenerateQrCode(row: MpAccountApi.Account) { - const hideLoading = ElLoading.service({ + const loadingInstance = ElLoading.service({ text: '正在生成二维码中...', }); try { @@ -62,20 +62,20 @@ async function handleGenerateQrCode(row: MpAccountApi.Account) { ElMessage.success($t('ui.actionMessage.operationSuccess')); handleRefresh(); } finally { - hideLoading.close(); + loadingInstance.close(); } } /** 清空 API 配额 */ async function handleCleanQuota(row: MpAccountApi.Account) { - const hideLoading = ElLoading.service({ + const loadingInstance = ElLoading.service({ text: $t('ui.actionMessage.processing', ['清空 API 配额']), }); try { await clearAccountQuota(row.id as number); ElMessage.success($t('ui.actionMessage.operationSuccess')); } finally { - hideLoading.close(); + loadingInstance.close(); } } diff --git a/apps/web-ele/src/views/mp/statistics/chart-options.ts b/apps/web-ele/src/views/mp/statistics/chart-options.ts new file mode 100644 index 000000000..b9d321dd3 --- /dev/null +++ b/apps/web-ele/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-ele/src/views/mp/statistics/data.ts b/apps/web-ele/src/views/mp/statistics/data.ts new file mode 100644 index 000000000..7ec41d0d0 --- /dev/null +++ b/apps/web-ele/src/views/mp/statistics/data.ts @@ -0,0 +1,43 @@ +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: 'ApiSelect', + componentProps: { + options: accountList.map((item) => ({ + label: item.name, + value: item.id, + })), + placeholder: '请选择公众号', + clearable: 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-ele/src/views/mp/statistics/index.vue b/apps/web-ele/src/views/mp/statistics/index.vue new file mode 100644 index 000000000..5cbda917a --- /dev/null +++ b/apps/web-ele/src/views/mp/statistics/index.vue @@ -0,0 +1,151 @@ + + +