feat(usage): 使用统计纳入未登录访客 — 任意工具页打开即上报(router afterEach+localStorage 10min去重+beacon), 后台总次数显示其中未登录N次+用户排行新增未登录访客行+工具名回退目录名
This commit is contained in:
1 parent
15d21235cd
commit
cd4b324740
4 files changed
+69
-5
No files matched your search
@@ -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)
|
||||
|
||||
@@ -276,6 +276,15 @@ async function saveStorage() {
|
||||
// ============ 使用统计 ============
|
||||
const usageDays = ref(7);
|
||||
const usage = ref<any>(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<string, string> = {
|
||||
};
|
||||
|
||||
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
|
||||
<option :value="30">近 30 天</option>
|
||||
<option :value="90">近 90 天</option>
|
||||
</select>
|
||||
<span v-if="usage" class="adm-sub">总使用次数:{{ usage.total }}</span>
|
||||
<span v-if="usage" class="adm-sub">总使用次数:{{ usage.total }}<template v-if="usage.guest?.count">(其中未登录 {{ usage.guest.count }} 次)</template></span>
|
||||
</div>
|
||||
<div class="adm-usage-grid">
|
||||
<div>
|
||||
@@ -691,12 +705,12 @@ function switchTab(id: 'overview' | 'files' | 'usage' | 'storage' | 'reco' | 'fe
|
||||
<table class="adm-table">
|
||||
<thead><tr><th>用户</th><th>次数</th><th>最近活跃</th></tr></thead>
|
||||
<tbody>
|
||||
<tr v-for="u in usage?.by_user ?? []" :key="u.username">
|
||||
<td class="adm-user">{{ u.username }}</td>
|
||||
<tr v-for="u in userRows" :key="u.username">
|
||||
<td :class="u.username === '__guest__' ? 'adm-user adm-guest' : 'adm-user'">{{ u.username === '__guest__' ? '未登录访客' : u.username }}</td>
|
||||
<td>{{ u.count }}</td>
|
||||
<td>{{ fmtTime(u.last) }}</td>
|
||||
</tr>
|
||||
<tr v-if="!usage?.by_user?.length"><td colspan="3" class="adm-none">暂无登录用户使用记录</td></tr>
|
||||
<tr v-if="!userRows.length"><td colspan="3" class="adm-none">暂无登录用户使用记录</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
@@ -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;
|
||||
@@ -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 {
|
||||
// 统计失败绝不影响功能
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user