|
@@ -3,12 +3,11 @@ import type { MenuModule, Menu, AppRouteRecordRaw } from '/@/router/types';
|
|
|
import { findPath, treeMap } from '/@/utils/helper/treeHelper';
|
|
|
import { cloneDeep } from 'lodash-es';
|
|
|
import { isUrl } from '/@/utils/is';
|
|
|
-import { RouteParams } from 'vue-router';
|
|
|
+import { RouteLocationNormalized, RouteParams } from 'vue-router';
|
|
|
import { toRaw } from 'vue';
|
|
|
import { defHttp } from '/@/utils/http/axios';
|
|
|
-import { useUserStoreWithOut } from '/@/store/modules/user';
|
|
|
+import { Form } from 'ant-design-vue';
|
|
|
|
|
|
-let currentRouter = '';
|
|
|
export function getAllParentPath<T = Recordable>(treeData: T[], path: string) {
|
|
|
const menuList = findPath(treeData, (n) => n.path === path) as Menu[];
|
|
|
return (menuList || []).map((item) => item.path);
|
|
@@ -99,62 +98,65 @@ export function configureDynamicParamsMenu(menu: Menu, params: RouteParams) {
|
|
|
menu.children?.forEach((item) => configureDynamicParamsMenu(item, params));
|
|
|
}
|
|
|
|
|
|
-export async function addBrowseLog(to, from, whitePathList) {
|
|
|
- const userStore = useUserStoreWithOut();
|
|
|
- const token = userStore.getToken;
|
|
|
- if (token) {
|
|
|
- let currentBrowseId = '';
|
|
|
- if (to.path !== '/sys/log/addBrowseLog') {
|
|
|
- const url = '/sys/log/addBrowseLog';
|
|
|
+export async function addBrowseLog(
|
|
|
+ to: AppRouteRecordRaw | RouteLocationNormalized,
|
|
|
+ from: AppRouteRecordRaw | RouteLocationNormalized,
|
|
|
+ ignorePaths: string[]
|
|
|
+): Promise<void> {
|
|
|
+ // 在尝试添加浏览器记录时,应该先发出一个结束上次记录的请求(如有)再发出一个开发此次记录的请求
|
|
|
+ const url = '/sys/log/addBrowseLog';
|
|
|
|
|
|
- // 生成时间戳函数
|
|
|
- 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('');
|
|
|
- };
|
|
|
- // 2. 记录新页面进入日志
|
|
|
- currentBrowseId = formatTimestamp();
|
|
|
- if (!currentRouter && !whitePathList.includes(to.path)) {
|
|
|
- currentRouter = to.fullPath;
|
|
|
- try {
|
|
|
- await defHttp.post({
|
|
|
- url,
|
|
|
- params: {
|
|
|
- browseId: currentBrowseId,
|
|
|
- isEnd: false,
|
|
|
- method: to.fullPath,
|
|
|
- },
|
|
|
- });
|
|
|
- console.log('进入页面日志记录成功');
|
|
|
- } catch (e) {
|
|
|
- console.error('进入页面日志记录失败:', e);
|
|
|
- }
|
|
|
- } else {
|
|
|
- if (from.fullPath === currentRouter) {
|
|
|
- try {
|
|
|
- currentRouter = '';
|
|
|
- await defHttp.post({
|
|
|
- url,
|
|
|
- params: {
|
|
|
- browseId: currentBrowseId,
|
|
|
- isEnd: true,
|
|
|
- method: from.fullPath,
|
|
|
- },
|
|
|
- });
|
|
|
- console.log('进入页面日志记录成功');
|
|
|
- } catch (e) {
|
|
|
- console.error('进入页面日志记录失败:', e);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ // meta.browseId 是该方法动态添加的内容,可用于判断该路径是否记录
|
|
|
+ if (from.meta.browseId) {
|
|
|
+ await defHttp.post({
|
|
|
+ url,
|
|
|
+ params: {
|
|
|
+ browseId: from.meta.browseId,
|
|
|
+ isEnd: true,
|
|
|
+ method: from.fullPath,
|
|
|
+ },
|
|
|
+ });
|
|
|
}
|
|
|
+ if (!ignorePaths.includes(to.path)) {
|
|
|
+ const timestamp = Date.now();
|
|
|
+ to.meta.browseId = timestamp;
|
|
|
+ await defHttp.post({
|
|
|
+ url,
|
|
|
+ params: {
|
|
|
+ browseId: timestamp,
|
|
|
+ isEnd: false,
|
|
|
+ method: to.fullPath,
|
|
|
+ },
|
|
|
+ });
|
|
|
+ }
|
|
|
+ // if (to.path !== '/sys/log/addBrowseLog') {
|
|
|
+
|
|
|
+ // // 2. 记录新页面进入日志
|
|
|
+ // currentBrowseId = formatTimestamp();
|
|
|
+ // if (!currentRouter) {
|
|
|
+ // currentRouter = to.fullPath;
|
|
|
+ // try {
|
|
|
+ // console.log('进入页面日志记录成功');
|
|
|
+ // } catch (e) {
|
|
|
+ // console.error('进入页面日志记录失败:', e);
|
|
|
+ // }
|
|
|
+ // } else {
|
|
|
+ // if (from.fullPath === currentRouter) {
|
|
|
+ // try {
|
|
|
+ // currentRouter = '';
|
|
|
+ // await defHttp.post({
|
|
|
+ // url,
|
|
|
+ // params: {
|
|
|
+ // browseId: currentBrowseId,
|
|
|
+ // isEnd: true,
|
|
|
+ // method: from.fullPath,
|
|
|
+ // },
|
|
|
+ // });
|
|
|
+ // console.log('进入页面日志记录成功');
|
|
|
+ // } catch (e) {
|
|
|
+ // console.error('进入页面日志记录失败:', e);
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
}
|