|
@@ -1,9 +1,9 @@
|
|
import type { RouteRecordRaw } from 'vue-router';
|
|
import type { RouteRecordRaw } from 'vue-router';
|
|
import type { App } from 'vue';
|
|
import type { App } from 'vue';
|
|
-
|
|
|
|
import { createRouter, createWebHashHistory, createWebHistory } from 'vue-router';
|
|
import { createRouter, createWebHashHistory, createWebHistory } from 'vue-router';
|
|
import { basicRoutes } from './routes';
|
|
import { basicRoutes } from './routes';
|
|
-
|
|
|
|
|
|
+import { defHttp } from '/@/utils/http/axios';
|
|
|
|
+// let userName = unref(userStore.getUserInfo).username;
|
|
// 白名单应该包含基本静态路由
|
|
// 白名单应该包含基本静态路由
|
|
const WHITE_NAME_LIST: string[] = [];
|
|
const WHITE_NAME_LIST: string[] = [];
|
|
const getRouteNames = (array: any[]) =>
|
|
const getRouteNames = (array: any[]) =>
|
|
@@ -22,11 +22,57 @@ export const router = createRouter({
|
|
});
|
|
});
|
|
|
|
|
|
// TODO 【QQYUN-4517】【表单设计器】记录分享路由守卫测试
|
|
// TODO 【QQYUN-4517】【表单设计器】记录分享路由守卫测试
|
|
|
|
+// 存储当前页面的browseId(用于关联离开/进入日志)
|
|
|
|
+let currentBrowseId = '';
|
|
router.beforeEach(async (to, from, next) => {
|
|
router.beforeEach(async (to, from, next) => {
|
|
- //console.group('【QQYUN-4517】beforeEach');
|
|
|
|
- //console.warn('from', from);
|
|
|
|
- //console.warn('to', to);
|
|
|
|
- //console.groupEnd();
|
|
|
|
|
|
+ const url = '/sys/log/addBrowseLog';
|
|
|
|
+ const currentPath = to.fullPath;
|
|
|
|
+ // 生成时间戳函数
|
|
|
|
+ const formatTimestamp = () => {
|
|
|
|
+ const date = new Date();
|
|
|
|
+ return [
|
|
|
|
+ date.getFullYear(),
|
|
|
|
+ String(date.getMonth() + 1).padStart(2, '0'),
|
|
|
|
+ String(date.getDate()).padStart(2, '0'),
|
|
|
|
+ String(date.getHours()).padStart(2, '0'),
|
|
|
|
+ String(date.getMinutes()).padStart(2, '0'),
|
|
|
|
+ String(date.getSeconds()).padStart(2, '0'),
|
|
|
|
+ String(date.getMilliseconds()).padStart(3, '0'),
|
|
|
|
+ ].join('');
|
|
|
|
+ };
|
|
|
|
+ // 1. 如果存在上一个页面的browseId,发送离开日志
|
|
|
|
+ if (currentBrowseId && from.fullPath !== '/') {
|
|
|
|
+ try {
|
|
|
|
+ await defHttp.post({
|
|
|
|
+ url,
|
|
|
|
+ params: {
|
|
|
|
+ browseId: currentBrowseId,
|
|
|
|
+ isEnd: true,
|
|
|
|
+ method: from.fullPath,
|
|
|
|
+ },
|
|
|
|
+ });
|
|
|
|
+ console.log('离开页面日志记录成功');
|
|
|
|
+ } catch (e) {
|
|
|
|
+ console.error('离开页面日志记录失败:', e);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 2. 记录新页面进入日志
|
|
|
|
+ currentBrowseId = formatTimestamp();
|
|
|
|
+ try {
|
|
|
|
+ await defHttp.post({
|
|
|
|
+ url,
|
|
|
|
+ params: {
|
|
|
|
+ browseId: currentBrowseId,
|
|
|
|
+ isEnd: false,
|
|
|
|
+ method: to.fullPath,
|
|
|
|
+ },
|
|
|
|
+ });
|
|
|
|
+ console.log('进入页面日志记录成功');
|
|
|
|
+ } catch (e) {
|
|
|
|
+ console.error('进入页面日志记录失败:', e);
|
|
|
|
+ }
|
|
|
|
+
|
|
next();
|
|
next();
|
|
});
|
|
});
|
|
|
|
|