瀏覽代碼

日志收集

CzRger 2 周之前
父節點
當前提交
6a05bf974d
共有 2 個文件被更改,包括 17 次插入25 次删除
  1. 16 24
      src/api/interceptors.ts
  2. 1 1
      src/views/manage/knowledge/index.vue

+ 16 - 24
src/api/interceptors.ts

@@ -1,6 +1,7 @@
 import axios from 'axios'
 import axios from 'axios'
 import { ElButton, ElMessage, ElNotification } from 'element-plus'
 import { ElButton, ElMessage, ElNotification } from 'element-plus'
 import { h } from 'vue'
 import { h } from 'vue'
+import { YMDHms } from '@/utils/czr-util'
 
 
 // import {toLogin} from "@/utils/permissions";
 // import {toLogin} from "@/utils/permissions";
 export class Interceptors {
 export class Interceptors {
@@ -65,31 +66,17 @@ export class Interceptors {
 
 
   private errorHandle(res: any) {
   private errorHandle(res: any) {
     console.error('错误接口:' + res.request.responseURL)
     console.error('错误接口:' + res.request.responseURL)
-    const exportLog = (arr) => {
-      // 将数据转换为字符串
-      const convertDataToText = (data) => {
-        let text = ''
-        for (const [key, value] of Object.entries(data)) {
-          text += `${key}: ${value}\n`
-        }
-        return text
-      }
+    const exportLog = (arr, date) => {
       let str = ''
       let str = ''
       arr.forEach((v) => {
       arr.forEach((v) => {
-        if (typeof v === 'string') {
-          str += v
-        } else {
-          str += convertDataToText(v)
-        }
+        str += v
         str += '\n\n'
         str += '\n\n'
       })
       })
-
       const blob = new Blob([str], { type: 'text/plain' })
       const blob = new Blob([str], { type: 'text/plain' })
       const url = URL.createObjectURL(blob)
       const url = URL.createObjectURL(blob)
-
       const a = document.createElement('a')
       const a = document.createElement('a')
       a.href = url
       a.href = url
-      a.download = '错误日志.txt'
+      a.download = `错误日志_${date}.txt`
       document.body.appendChild(a)
       document.body.appendChild(a)
       a.click()
       a.click()
       setTimeout(() => {
       setTimeout(() => {
@@ -100,12 +87,6 @@ export class Interceptors {
     // 状态码判断
     // 状态码判断
     switch (res.status) {
     switch (res.status) {
       case 400:
       case 400:
-        // ElNotification({
-        //   title: res.data.message,
-        //   message: res.data.data,
-        //   type: 'error',
-        //   duration: 0,
-        // })
         ElNotification({
         ElNotification({
           title: res.data.message,
           title: res.data.message,
           message: h('div', null, [
           message: h('div', null, [
@@ -115,7 +96,18 @@ export class Interceptors {
                 type: 'warning',
                 type: 'warning',
                 size: 'small',
                 size: 'small',
                 plain: true,
                 plain: true,
-                onClick: exportLog,
+                onClick: () =>
+                  exportLog(
+                    [
+                      '错误日期:' + YMDHms(res.headers.date),
+                      '接口地址:' + res.request.responseURL,
+                      '接口状态:' + res.status + '_' + res.statusText,
+                      '请求Token:' + res.config.headers.Authorization,
+                      '请求参数:' + res.config.data,
+                      '返回结果:' + res.request.response,
+                    ],
+                    YMDHms(res.headers.date),
+                  ),
               },
               },
               { default: () => '错误日志' },
               { default: () => '错误日志' },
             ),
             ),

+ 1 - 1
src/views/manage/knowledge/index.vue

@@ -251,7 +251,7 @@ const onPage = (pageNum, pageSize) => {
     pageSize: pageSize,
     pageSize: pageSize,
   }
   }
   const params = {
   const params = {
-    // tenantId: AppStore.tenantInfo?.id,
+    tenantId: AppStore.tenantInfo?.id,
     page: state.query.page.pageNum,
     page: state.query.page.pageNum,
     size: state.query.page.pageSize,
     size: state.query.page.pageSize,
   }
   }