diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a26b39..2e1b220 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +## Version 2026.11.12-it-tools-pro + +### 📦 本次更新(2026-11-12) +- **使用统计纳入未登录访客(本次核心)**:任意工具页打开即自动上报一次使用(路由全局钩子,浏览器 beacon),**未登录、未绑定机器码的访客同样计数**——原先只有走中转接口的在线翻译/图片工具等少数功能会被统计,现在全部工具的使用都会进入管理后台「使用统计」 +- **防刷三层保障**:前端同一工具 10 分钟内只上报一次(localStorage 去重)、relay 服务端同机同工具 10 分钟去重、每 IP 10 分钟上限 300 条 + tool 名格式校验,刷新页面/恶意刷接口都不会灌水 +- **管理后台展示升级**:总使用次数后新增「其中未登录 N 次」;「用户活跃排行」新增**未登录访客**行(按次数参与排序,访客使用一目了然);「功能使用排行」的工具名自动回退查工具目录显示正式名称(不再显示英文路径代号) + ## Version 2026.11.11-it-tools-pro ### 📦 本次更新(2026-11-11) diff --git a/src/pages/Admin.page.vue b/src/pages/Admin.page.vue index 5a1d8a1..584b43c 100644 --- a/src/pages/Admin.page.vue +++ b/src/pages/Admin.page.vue @@ -276,6 +276,15 @@ async function saveStorage() { // ============ 使用统计 ============ const usageDays = ref(7); const usage = ref(null); +// 用户活跃排行 = 登录用户 + 未登录访客(访客功能使用也统计展示) +const userRows = computed(() => { + const rows: { username: string; count: number; last: number }[] = [...(usage.value?.by_user ?? [])]; + const g = usage.value?.guest; + if (g && g.count > 0) { + rows.push({ username: '__guest__', count: g.count, last: g.last }); + } + return rows.sort((a, b) => b.count - a.count); +}); async function loadUsage() { const b = await api(`/admin/usage?days=${usageDays.value}`); @@ -298,7 +307,12 @@ const TOOL_LABELS: Record = { }; function toolLabel(t: string) { - return TOOL_LABELS[t] ?? t; + if (TOOL_LABELS[t]) { + return TOOL_LABELS[t]; + } + // 前端上报的是工具路径(如 json-to-xml),回退查工具目录显示名称 + const hit = toolStore.tools.find((x: any) => x.path === `/${t}` || x.path === t); + return hit?.name || t; } function fmtTime(t: number) { @@ -674,7 +688,7 @@ function switchTab(id: 'overview' | 'files' | 'usage' | 'storage' | 'reco' | 'fe - 总使用次数:{{ usage.total }} + 总使用次数:{{ usage.total }}
@@ -691,12 +705,12 @@ function switchTab(id: 'overview' | 'files' | 'usage' | 'storage' | 'reco' | 'fe - - + + - +
用户次数最近活跃
{{ u.username }}
{{ u.username === '__guest__' ? '未登录访客' : u.username }} {{ u.count }} {{ fmtTime(u.last) }}
暂无登录用户使用记录
暂无登录用户使用记录
diff --git a/src/router.ts b/src/router.ts index 9071bd6..49bc34d 100644 --- a/src/router.ts +++ b/src/router.ts @@ -4,6 +4,7 @@ import HomePage from './pages/Home.page.vue'; import NotFound from './pages/404.page.vue'; import { tools } from './tools'; import { config } from './config'; +import { reportToolUsage } from './tools/license/license'; import { routes as demoRoutes } from './ui/demo/demo.routes'; const toolsRoutes = tools.map(({ path, name, component, ...config }) => ({ @@ -58,4 +59,11 @@ const router = createRouter({ ], }); +// 打开任意工具页即上报一次使用(未登录访客同样统计,见 license.ts reportToolUsage) +router.afterEach((to) => { + if (to.meta?.isTool) { + reportToolUsage(String(to.path)); + } +}); + export default router; diff --git a/src/tools/license/license.ts b/src/tools/license/license.ts index 1370885..11849fe 100644 --- a/src/tools/license/license.ts +++ b/src/tools/license/license.ts @@ -238,3 +238,38 @@ export async function activateCard(cardKey: string, contactQq: string, replace = licenseState.activating = false; } } + +// ---- 工具使用统计上报:任何访客(含未登录)打开工具页即计一次 ---- +// 同一工具 10 分钟内只上报一次(防刷新刷量),服务端还会再做一层去重与限流。 +const USAGE_THROTTLE_MS = 10 * 60 * 1000; + +export function reportToolUsage(path: string): void { + try { + const tool = String(path || '').replace(/^\/+/, '').slice(0, 64); + if (!tool) { + return; + } + const key = `it-tools-usage:${tool}`; + const last = Number(localStorage.getItem(key) || 0); + if (Date.now() - last < USAGE_THROTTLE_MS) { + return; + } + localStorage.setItem(key, String(Date.now())); + let machine = ''; + try { + machine = getMachineId(); + } + catch { + machine = ''; + } + fetch('/relay/usage', { + method: 'POST', + keepalive: true, + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ machine_id: machine, tool }), + }).catch(() => {}); + } + catch { + // 统计失败绝不影响功能 + } +}