feat: 添加统计服务

This commit is contained in:
alger
2025-04-12 23:16:12 +08:00
parent b9b52f4d9f
commit a7f2045c7b
10 changed files with 364 additions and 25 deletions
+10
View File
@@ -1,5 +1,6 @@
import { createRouter, createWebHashHistory } from 'vue-router';
import { recordVisit } from '@/api/stats';
import AppLayout from '@/layout/AppLayout.vue';
import MiniLayout from '@/layout/MiniLayout.vue';
import homeRouter from '@/router/home';
@@ -80,4 +81,13 @@ router.beforeEach((to, _, next) => {
}
});
// 添加全局后置钩子,记录页面访问
router.afterEach((to) => {
const pageName = to.name?.toString() || to.path;
// 使用setTimeout避免阻塞路由导航
setTimeout(() => {
recordVisit(pageName).catch((error) => console.error('记录页面访问失败:', error));
}, 100);
});
export default router;