Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c6341ea35b | ||
|
|
cd4b324740 |
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) {
|
||||
@@ -444,7 +458,14 @@ function recoMove(i: number, d: -1 | 1) {
|
||||
|
||||
const tab = ref<'overview' | 'files' | 'usage' | 'storage' | 'reco' | 'feedback'>('overview');
|
||||
|
||||
// 在线人数 30s 自动刷新(切走用量页签即停)
|
||||
let usageTimer: ReturnType<typeof setInterval> | null = null;
|
||||
|
||||
function switchTab(id: 'overview' | 'files' | 'usage' | 'storage' | 'reco' | 'feedback') {
|
||||
if (usageTimer) {
|
||||
clearInterval(usageTimer);
|
||||
usageTimer = null;
|
||||
}
|
||||
tab.value = id;
|
||||
if (id === 'overview') {
|
||||
loadOverview();
|
||||
@@ -454,6 +475,7 @@ function switchTab(id: 'overview' | 'files' | 'usage' | 'storage' | 'reco' | 'fe
|
||||
}
|
||||
if (id === 'usage') {
|
||||
loadUsage();
|
||||
usageTimer = setInterval(loadUsage, 30000);
|
||||
}
|
||||
if (id === 'storage') {
|
||||
loadStorage();
|
||||
@@ -674,7 +696,8 @@ 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" style="color:#16a34a;font-weight:600">● 当前在线(未登录,停留>1分钟):{{ usage.online ?? 0 }} 人</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 +714,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, startOnlineHeartbeat } from './tools/license/license';
|
||||
import { routes as demoRoutes } from './ui/demo/demo.routes';
|
||||
|
||||
const toolsRoutes = tools.map(({ path, name, component, ...config }) => ({
|
||||
@@ -58,4 +59,13 @@ const router = createRouter({
|
||||
],
|
||||
});
|
||||
|
||||
// 打开任意工具页即上报一次使用(未登录访客同样统计,见 license.ts reportToolUsage)
|
||||
router.afterEach((to) => {
|
||||
if (to.meta?.isTool) {
|
||||
reportToolUsage(String(to.path));
|
||||
}
|
||||
// 全站在线心跳:停留满 1 分钟的未登录访客才计在线(内部 once 保护)
|
||||
startOnlineHeartbeat();
|
||||
});
|
||||
|
||||
export default router;
|
||||
@@ -238,3 +238,78 @@ 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 {
|
||||
// 统计失败绝不影响功能
|
||||
}
|
||||
}
|
||||
|
||||
// ---- 在线统计心跳:打开满 1 分钟才开始上报;仅未登录访客被统计 ----
|
||||
const ONLINE_DELAY_MS = 60 * 1000; // 停留超过 1 分钟才计入在线(由前端延迟首发实现)
|
||||
const ONLINE_BEAT_MS = 30 * 1000; // 之后每 30s 心跳一次(后台标签被浏览器节流为 60s,服务端 90s 窗口判定)
|
||||
let onlineStarted = false;
|
||||
|
||||
function isGuest(): boolean {
|
||||
try {
|
||||
return !JSON.parse(localStorage.getItem('it-tools-auth') ?? 'null');
|
||||
}
|
||||
catch {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
export function startOnlineHeartbeat(): void {
|
||||
if (onlineStarted) {
|
||||
return;
|
||||
}
|
||||
onlineStarted = true;
|
||||
const beat = () => {
|
||||
try {
|
||||
fetch('/relay/online', {
|
||||
method: 'POST',
|
||||
keepalive: true,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ machine_id: getMachineId(), guest: isGuest() }),
|
||||
}).catch(() => {});
|
||||
}
|
||||
catch {
|
||||
// 统计失败绝不影响功能
|
||||
}
|
||||
};
|
||||
setTimeout(() => {
|
||||
beat();
|
||||
setInterval(beat, ONLINE_BEAT_MS);
|
||||
// 登录/登出立即同步:登录后该机器被移出在线统计
|
||||
window.addEventListener('it-tools-auth-changed', beat);
|
||||
}, ONLINE_DELAY_MS);
|
||||
}
|
||||
Reference in new issue
Block a user