feat(analytics): 添加访问统计功能

实现页面访问统计功能,包括:
1. 前端组件挂载时上报访问数据
2. 后端接口记录访问信息并存储
3. 管理后台新增访问统计视图
4. 相关API文档和设计说明更新
This commit is contained in:
anghunk
2026-01-21 21:56:57 +08:00
parent aabf370f65
commit d5a7a15344
12 changed files with 1241 additions and 201 deletions

View File

@@ -83,6 +83,23 @@ export type CommentStatsResponse = {
}[];
};
export type VisitOverviewResponse = {
totalPv: number;
totalPages: number;
};
export type VisitPageItem = {
postSlug: string;
postTitle: string | null;
postUrl: string | null;
pv: number;
lastVisitAt: string | null;
};
export type VisitPagesResponse = {
items: VisitPageItem[];
};
export async function loginAdmin(name: string, password: string): Promise<string> {
const res = await post<AdminLoginResponse>('/admin/login', { name, password });
const key = res.data.key;
@@ -212,3 +229,11 @@ export function importComments(data: any[]): Promise<{ message: string }> {
export function fetchCommentStats(): Promise<CommentStatsResponse> {
return get<CommentStatsResponse>('/admin/stats/comments');
}
export function fetchVisitOverview(): Promise<VisitOverviewResponse> {
return get<VisitOverviewResponse>('/admin/analytics/overview');
}
export function fetchVisitPages(): Promise<VisitPagesResponse> {
return get<VisitPagesResponse>('/admin/analytics/pages');
}