feat(数据看板): 将评论趋势统计从7天改为30天

修改前端展示、API文档和后端逻辑,将评论趋势统计的时间范围从7天扩展至30天,以提供更全面的数据分析视角
This commit is contained in:
anghunk
2026-01-21 22:01:14 +08:00
parent d5a7a15344
commit 73eaa975fe
3 changed files with 6 additions and 6 deletions

View File

@@ -40,7 +40,7 @@
</div> </div>
<div class="card"> <div class="card">
<h3 class="card-title">最近 7 天评论数趋势</h3> <h3 class="card-title">最近 30 天评论数趋势</h3>
<div v-if="statsLoading" class="page-hint">加载中...</div> <div v-if="statsLoading" class="page-hint">加载中...</div>
<div v-else-if="statsError" class="page-error">{{ statsError }}</div> <div v-else-if="statsError" class="page-error">{{ statsError }}</div>
<div v-else class="chart-wrapper"> <div v-else class="chart-wrapper">

View File

@@ -94,12 +94,12 @@ export const getStats = async (c: Context<{ Bindings: Bindings }>) => {
.sort((a, b) => b.total - a.total); .sort((a, b) => b.total - a.total);
const now = Date.now(); const now = Date.now();
const sevenDaysAgo = now - 6 * 24 * 60 * 60 * 1000; const thirtyDaysAgo = now - 29 * 24 * 60 * 60 * 1000;
const { results: dailyRows } = await c.env.CWD_DB.prepare( const { results: dailyRows } = await c.env.CWD_DB.prepare(
"SELECT date(created / 1000, 'unixepoch') as day, COUNT(*) as total FROM Comment WHERE created >= ? GROUP BY day ORDER BY day ASC" "SELECT date(created / 1000, 'unixepoch') as day, COUNT(*) as total FROM Comment WHERE created >= ? GROUP BY day ORDER BY day ASC"
) )
.bind(sevenDaysAgo) .bind(thirtyDaysAgo)
.all<{ day: string; total: number }>(); .all<{ day: string; total: number }>();
const dailyMap = new Map<string, number>(); const dailyMap = new Map<string, number>();
@@ -110,7 +110,7 @@ export const getStats = async (c: Context<{ Bindings: Bindings }>) => {
} }
const last7Days: { date: string; total: number }[] = []; const last7Days: { date: string; total: number }[] = [];
for (let i = 6; i >= 0; i--) { for (let i = 29; i >= 0; i--) {
const d = new Date(now - i * 24 * 60 * 60 * 1000); const d = new Date(now - i * 24 * 60 * 60 * 1000);
const year = d.getUTCFullYear(); const year = d.getUTCFullYear();
const month = String(d.getUTCMonth() + 1).padStart(2, '0'); const month = String(d.getUTCMonth() + 1).padStart(2, '0');

View File

@@ -1085,7 +1085,7 @@ POST /admin/settings/email-test
GET /admin/stats/comments GET /admin/stats/comments
``` ```
用于管理后台「数据看板」展示评论整体统计、按域名统计以及最近 7 天评论趋势。 用于管理后台「数据看板」展示评论整体统计、按域名统计以及最近 30 天评论趋势。
- 方法:`GET` - 方法:`GET`
- 路径:`/admin/stats/comments` - 路径:`/admin/stats/comments`
@@ -1147,7 +1147,7 @@ GET /admin/stats/comments
| `domains[].approved` | number | 该域名下已通过评论数 | | `domains[].approved` | number | 该域名下已通过评论数 |
| `domains[].pending` | number | 该域名下待审核评论数 | | `domains[].pending` | number | 该域名下待审核评论数 |
| `domains[].rejected` | number | 该域名下已拒绝评论数 | | `domains[].rejected` | number | 该域名下已拒绝评论数 |
| `last7Days` | Array\<DailyStat\> | 最近 7 天的每日评论数(按自然日聚合) | | `last7Days` | Array\<DailyStat\> | 最近 30 天的每日评论数(按自然日聚合) |
| `last7Days[].date` | string (YYYY-MM-DD) | 日期UTC 时间格式化后的自然日 | | `last7Days[].date` | string (YYYY-MM-DD) | 日期UTC 时间格式化后的自然日 |
| `last7Days[].total` | number | 当日评论总数 | | `last7Days[].total` | number | 当日评论总数 |