Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kne-components/components-admin",
"version": "1.1.47",
"version": "1.1.48",
"description": "用于实现一个后台管理系统的必要组件",
"scripts": {
"init": "husky",
Expand Down
2 changes: 1 addition & 1 deletion src/components/Apis/getApis.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ const getApis = options => {
statistics: {
/**
* 历史统计看板(GET)。
* Query:`range`(7d|1m|1y)、`timezone`(IANA,与「今日」划界一致)。
* Query:`range`(7d|1m|3m|1y)、`timezone`(IANA,与「今日」划界一致)。
* 响应字段约定见 `src/components/Task/doc/api.md`「任务统计 HTTP」。
*/
getOverview: {
Expand Down
59 changes: 51 additions & 8 deletions src/components/MessageManger/Dashboard/HistorySection.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,47 @@ import SectionHeader from './SectionHeader';
import { getClientIanaTimezone } from '../utils';
import style from './dashboard.module.scss';

const RANGE_DAY_COUNT = { '7d': 7, '1m': 30, '1y': 365 };
const RANGE_DAY_COUNT = { '7d': 7, '1m': 30, '3m': 90, '1y': 365 };
const RANGE_AXIS_UNIT = { '7d': 'day', '1m': 'month', '3m': 'month', '1y': 'year' };
const RANGE_MONTH_COUNT = { '1m': 1, '3m': 3 };

const getAxisUnit = rangeKey => RANGE_AXIS_UNIT[rangeKey] || 'day';

const formatAxisKey = (date, unit) => {
const value = String(date || '');
if (unit === 'year') return value.slice(0, 4);
if (unit === 'month') return value.slice(0, 7);
return value.slice(0, 10);
};

/** 本地日历上从 range 起点到今天的时间轴,随视图切换日/月/年粒度 */
const buildLocalAxisForRange = rangeKey => {
const axisUnit = getAxisUnit(rangeKey);
if (axisUnit === 'year') {
const now = new Date();
const startYear = now.getFullYear() - 1;
return Array.from({ length: now.getFullYear() - startYear + 1 }, (_, i) => String(startYear + i));
}

if (axisUnit === 'month') {
const cursor = new Date();
cursor.setHours(0, 0, 0, 0);
cursor.setDate(1);
cursor.setMonth(cursor.getMonth() - (RANGE_MONTH_COUNT[rangeKey] || 1));
const end = new Date();
end.setHours(0, 0, 0, 0);
end.setDate(1);

const months = [];
while (cursor <= end) {
const y = cursor.getFullYear();
const m = String(cursor.getMonth() + 1).padStart(2, '0');
months.push(`${y}-${m}`);
cursor.setMonth(cursor.getMonth() + 1);
}
return months;
}

/** 本地日历上从 range 起点到今天的日期轴(YYYY-MM-DD) */
const buildLocalDateAxisForRange = rangeKey => {
const days = RANGE_DAY_COUNT[rangeKey] || 7;
const dates = [];
for (let i = days - 1; i >= 0; i -= 1) {
Expand Down Expand Up @@ -88,24 +125,30 @@ const HistorySection = createWithRemoteLoader({
const trendOption = (() => {
const recentTrend = data?.recentTrend || [];
const recentTrendByType = data?.recentTrendByType || [];
const axisDates = recentTrend.length > 0 ? null : buildLocalDateAxisForRange(range);
const axisUnit = getAxisUnit(range);
const axisDates = recentTrend.length > 0 ? null : buildLocalAxisForRange(range);

const dateMap = {};
if (recentTrend.length > 0) {
recentTrend.forEach(item => {
dateMap[item.date] = { date: item.date, total: item.count };
const date = formatAxisKey(item.date, axisUnit);
if (!dateMap[date]) {
dateMap[date] = { date, total: 0 };
}
dateMap[date].total += Number(item.count) || 0;
});
} else {
axisDates.forEach(d => {
dateMap[d] = { date: d, total: 0 };
});
}
recentTrendByType.forEach(item => {
if (!dateMap[item.date]) {
dateMap[item.date] = { date: item.date, total: 0 };
const date = formatAxisKey(item.date, axisUnit);
if (!dateMap[date]) {
dateMap[date] = { date, total: 0 };
}
const key = item.type === 0 ? 'email' : 'sms';
dateMap[item.date][key] = item.count;
dateMap[date][key] = (dateMap[date][key] || 0) + (Number(item.count) || 0);
});

const sorted = Object.values(dateMap).sort((a, b) => a.date.localeCompare(b.date));
Expand Down
2 changes: 1 addition & 1 deletion src/components/MessageManger/Dashboard/constants.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const RANGE_OPTIONS = ['7d', '1m', '1y'];
export const RANGE_OPTIONS = ['7d', '1m', '3m', '1y'];

export const buildUrlWithParams = (url, params = {}) => {
const query = Object.keys(params)
Expand Down
1 change: 1 addition & 0 deletions src/components/MessageManger/locale/en-US.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const messages = {
TotalCount: 'Total Count',
Range_7d: 'Last 7 Days',
Range_1m: 'Last Month',
Range_3m: 'Last 3 Months',
Range_1y: 'Last Year',
Refresh: 'Refresh',
RealtimeConnected: 'Realtime Connected',
Expand Down
1 change: 1 addition & 0 deletions src/components/MessageManger/locale/zh-CN.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const messages = {
TotalCount: '总数',
Range_7d: '近7天',
Range_1m: '近1个月',
Range_3m: '近3个月',
Range_1y: '近1年',
Refresh: '刷新',
RealtimeConnected: '实时已连接',
Expand Down
Loading