From d864bd0718d30686cfd1db689d3fb43b7c834551 Mon Sep 17 00:00:00 2001 From: AdingApkgg Date: Sun, 1 Feb 2026 15:50:29 +0800 Subject: [PATCH] refactor: update StatsCorner component to use new busuanzi API and remove obsolete script - Removed the old busuanzi script from index.html. - Updated StatsCorner.vue to use the new busuanzi API for fetching statistics. - Improved error handling and response parsing in the fetchBusuanziStats function. --- index.html | 5 ----- src/components/StatsCorner.vue | 26 ++++++++++++++++++-------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/index.html b/index.html index 67a250b..929994f 100644 --- a/index.html +++ b/index.html @@ -222,11 +222,6 @@ } - - diff --git a/src/components/StatsCorner.vue b/src/components/StatsCorner.vue index 536485f..a556814 100644 --- a/src/components/StatsCorner.vue +++ b/src/components/StatsCorner.vue @@ -92,21 +92,31 @@ const statusIconClass = computed(() => { return 'text-red-500' }) -// 使用新的 busuanzi API 获取统计 +// 不蒜子 API 配置 +// 文档: http://bsz.saop.cc/ +const BUSUANZI_API = 'https://bsz.saop.cc/api' + +// 获取统计数据(POST 方法会同时计数) async function fetchBusuanziStats() { try { - const res = await fetch('https://bsz.saop.cc/api', { + const res = await fetch(BUSUANZI_API, { method: 'POST', - credentials: 'include', - headers: { 'x-bsz-referer': window.location.href }, + credentials: 'include', // 携带 Cookie(用于识别访客) + headers: { + 'x-bsz-referer': window.location.href, // 必须:当前页面 URL + }, }) - if (!res.ok) {return} + if (!res.ok) { + throw new Error(`HTTP ${res.status}`) + } - const { success, data } = await res.json() + const json = await res.json() - if (success && data) { - statsStore.updateVisitorStats(data.site_pv, data.site_uv) + // 响应格式: { success: true, data: { site_pv, site_uv, page_pv } } + if (json.success && json.data) { + const { site_pv, site_uv } = json.data + statsStore.updateVisitorStats(site_pv, site_uv) showStats.value = true } } catch (error) {