소스 검색

Merge branch 'master' of http://182.92.126.35:3000/hrx/mky-vent-base

wangkeyi 3 일 전
부모
커밋
3bc153f75c
4개의 변경된 파일184개의 추가작업 그리고 6개의 파일을 삭제
  1. 52 6
      src/router/index.ts
  2. 63 0
      src/views/monitor/logRouter/index.vue
  3. 13 0
      src/views/monitor/logRouter/log.api.ts
  4. 56 0
      src/views/monitor/logRouter/log.data.ts

+ 52 - 6
src/router/index.ts

@@ -1,9 +1,9 @@
 import type { RouteRecordRaw } from 'vue-router';
 import type { App } from 'vue';
-
 import { createRouter, createWebHashHistory, createWebHistory } from 'vue-router';
 import { basicRoutes } from './routes';
-
+import { defHttp } from '/@/utils/http/axios';
+// let userName = unref(userStore.getUserInfo).username;
 // 白名单应该包含基本静态路由
 const WHITE_NAME_LIST: string[] = [];
 const getRouteNames = (array: any[]) =>
@@ -22,11 +22,57 @@ export const router = createRouter({
 });
 
 // TODO 【QQYUN-4517】【表单设计器】记录分享路由守卫测试
+// 存储当前页面的browseId(用于关联离开/进入日志)
+let currentBrowseId = '';
 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();
 });
 

+ 63 - 0
src/views/monitor/logRouter/index.vue

@@ -0,0 +1,63 @@
+<template>
+  <BasicTable @register="registerTable" :searchInfo="searchInfo" :columns="logColumns">
+    <template #tableTitle>
+      <a-tabs defaultActiveKey="1" @change="tabChange" size="small">
+        <a-tab-pane tab="浏览器日志" key="1"></a-tab-pane>
+      </a-tabs>
+    </template>
+  </BasicTable>
+</template>
+<script lang="ts" name="monitor-log" setup>
+import { ref } from 'vue';
+import { BasicTable, useTable, TableAction } from '/@/components/Table';
+import { getLogList } from './log.api';
+import { columns, searchFormSchema } from './log.data';
+import { useMessage } from '/@/hooks/web/useMessage';
+import { useListPage } from '/@/hooks/system/useListPage';
+const { createMessage } = useMessage();
+const checkedKeys = ref<Array<string | number>>([]);
+
+const logColumns = ref<any>(columns);
+const searchInfo = { logType: '3' };
+// 列表页面公共参数、方法
+const { prefixCls, tableContext } = useListPage({
+  designScope: 'user-list',
+  tableProps: {
+    title: '日志列表',
+    api: getLogList,
+    expandRowByClick: true,
+    showActionColumn: false,
+    rowSelection: {
+      columnWidth: 20,
+    },
+    formConfig: {
+      schemas: searchFormSchema,
+      fieldMapToTime: [['fieldTime', ['createTime_begin', 'createTime_end'], 'YYYY-MM-DD']],
+    },
+  },
+});
+
+const [registerTable, { reload }] = tableContext;
+
+// 日志类型
+function tabChange(key) {
+  searchInfo.logType = key;
+  if (key == '3') {
+    logColumns.value = columns;
+  }
+  reload();
+}
+
+/**
+ * 选择事件
+ */
+function onSelectChange(selectedRowKeys: (string | number)[]) {
+  checkedKeys.value = selectedRowKeys;
+}
+</script>
+<style lang="less" scoped>
+::v-deep .table-form {
+  padding: 0 !important;
+  margin: 0 !important;
+}
+</style>

+ 13 - 0
src/views/monitor/logRouter/log.api.ts

@@ -0,0 +1,13 @@
+import { defHttp } from '/@/utils/http/axios';
+
+enum Api {
+  list = '/sys/log/list',
+}
+
+/**
+ * 查询日志列表
+ * @param params
+ */
+export const getLogList = (params) => {
+  return defHttp.get({ url: Api.list, params });
+};

+ 56 - 0
src/views/monitor/logRouter/log.data.ts

@@ -0,0 +1,56 @@
+import { BasicColumn, FormSchema } from '/@/components/Table';
+
+export const columns: BasicColumn[] = [
+  {
+    title: '日志内容',
+    dataIndex: 'logContent',
+    width: 100,
+    align: 'left',
+  },
+  {
+    title: '操作人ID',
+    dataIndex: 'userid',
+    width: 80,
+  },
+  {
+    title: '操作人',
+    dataIndex: 'username',
+    width: 80,
+  },
+  {
+    title: 'IP',
+    dataIndex: 'ip',
+    width: 80,
+  },
+  {
+    title: '耗时(毫秒)',
+    dataIndex: 'costTime',
+    width: 80,
+  },
+  {
+    title: '创建时间',
+    dataIndex: 'createTime',
+    sorter: true,
+    width: 80,
+  },
+  {
+    title: '结束时间',
+    dataIndex: 'endTime',
+    sorter: true,
+    width: 80,
+  },
+];
+
+export const searchFormSchema: FormSchema[] = [
+  {
+    field: 'fieldTime',
+    component: 'RangePicker',
+    label: '创建时间',
+    componentProps: {
+      valueType: 'Date',
+    },
+    colProps: {
+      span: 4,
+    },
+  },
+];