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

@@ -169,6 +169,10 @@ export class CWDComments {
this._render();
this.store.loadComments();
if (this.api && typeof this.api.trackVisit === 'function') {
this.api.trackVisit();
}
})();
this._mounted = true;

View File

@@ -97,9 +97,27 @@
return response.json();
}
async function trackVisit() {
try {
await fetch(`${baseUrl}/api/analytics/visit`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
postSlug: config.postSlug,
postTitle: config.postTitle,
postUrl: config.postUrl
})
});
} catch (e) {
}
}
return {
fetchComments,
submitComment,
verifyAdminKey
verifyAdminKey,
trackVisit
};
}