feat(analytics): 添加今日/本周/本月访问量统计功能

- 在访问统计概览中新增今日、本周、本月访问量数据展示
- 更新API文档和前端界面以支持新的统计维度
- 优化图表显示样式,减小数据点大小
- 调整统计网格布局适配移动端
This commit is contained in:
anghunk
2026-01-22 09:52:44 +08:00
parent 4550b3c972
commit 5164f2c490
6 changed files with 302 additions and 9 deletions

View File

@@ -421,3 +421,73 @@ POST /api/verify-admin
"message": "验证失败次数过多请30分钟后再试"
}
```
## 4. 访问统计相关
### 4.1 记录页面访问
```
POST /api/analytics/visit
```
前端组件在加载时调用此接口,记录页面访问数据,用于后台访问统计分析。
- 方法:`POST`
- 路径:`/api/analytics/visit`
- 鉴权:不需要
**请求头**
| 名称 | 必填 | 示例 |
| -------------- | ---- | ------------------ |
| `Content-Type` | 是 | `application/json` |
**请求体**
```json
{
"postSlug": "https://example.com/blog/hello-world",
"postTitle": "博客标题",
"postUrl": "https://example.com/blog/hello-world"
}
```
字段说明:
| 字段名 | 类型 | 必填 | 说明 |
| ----------- | ------ | ---- | -------------------------------------------------------------------- |
| `postSlug` | string | 是 | 文章唯一标识符,`window.location.origin + window.location.pathname` |
| `postTitle` | string | 否 | 文章标题,用于后台展示页面名称 |
| `postUrl` | string | 否 | 文章 URL用于后台展示页面链接和域名统计 |
**成功响应**
- 状态码:`200`
```json
{
"success": true
}
```
**错误响应**
- 缺少 `postSlug`
- 状态码:`400`
```json
{
"message": "postSlug is required"
}
```
- 服务器内部错误:
- 状态码:`500`
```json
{
"message": "记录访问数据失败"
}
```