feat(widget): 添加页面访问量显示功能
- 新增公开 API GET /api/analytics/pv 获取页面访问量 - 前端组件初始化时自动填充 #cwd-page-pv 容器 - 支持数字格式化(如 1.2k、1.5M) - 将版本号更新至 0.1.8
This commit is contained in:
@@ -209,6 +209,24 @@ export function createApiClient(config) {
|
||||
} catch (e) {}
|
||||
throw new Error(msg);
|
||||
}
|
||||
return response.json();
|
||||
}
|
||||
|
||||
async function getPagePv() {
|
||||
const params = new URLSearchParams({
|
||||
post_slug: config.postUrl || config.postSlug
|
||||
});
|
||||
|
||||
if (config.siteId) {
|
||||
params.set('siteId', config.siteId);
|
||||
}
|
||||
|
||||
const response = await fetch(`${baseUrl}/api/analytics/pv?${params}`);
|
||||
|
||||
if (!response.ok) {
|
||||
return { pv: 0, postSlug: config.postSlug };
|
||||
}
|
||||
|
||||
return response.json();
|
||||
}
|
||||
|
||||
@@ -219,6 +237,7 @@ export function createApiClient(config) {
|
||||
trackVisit,
|
||||
getLikeStatus,
|
||||
likePage,
|
||||
likeComment
|
||||
likeComment,
|
||||
getPagePv
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user