|
@@ -1,6 +1,7 @@
|
|
|
import axios from 'axios'
|
|
|
import { ElButton, ElMessage, ElNotification } from 'element-plus'
|
|
|
import { h } from 'vue'
|
|
|
+import { YMDHms } from '@/utils/czr-util'
|
|
|
|
|
|
// import {toLogin} from "@/utils/permissions";
|
|
|
export class Interceptors {
|
|
@@ -65,31 +66,17 @@ export class Interceptors {
|
|
|
|
|
|
private errorHandle(res: any) {
|
|
|
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 = ''
|
|
|
arr.forEach((v) => {
|
|
|
- if (typeof v === 'string') {
|
|
|
- str += v
|
|
|
- } else {
|
|
|
- str += convertDataToText(v)
|
|
|
- }
|
|
|
+ str += v
|
|
|
str += '\n\n'
|
|
|
})
|
|
|
-
|
|
|
const blob = new Blob([str], { type: 'text/plain' })
|
|
|
const url = URL.createObjectURL(blob)
|
|
|
-
|
|
|
const a = document.createElement('a')
|
|
|
a.href = url
|
|
|
- a.download = '错误日志.txt'
|
|
|
+ a.download = `错误日志_${date}.txt`
|
|
|
document.body.appendChild(a)
|
|
|
a.click()
|
|
|
setTimeout(() => {
|
|
@@ -100,12 +87,6 @@ export class Interceptors {
|
|
|
// 状态码判断
|
|
|
switch (res.status) {
|
|
|
case 400:
|
|
|
- // ElNotification({
|
|
|
- // title: res.data.message,
|
|
|
- // message: res.data.data,
|
|
|
- // type: 'error',
|
|
|
- // duration: 0,
|
|
|
- // })
|
|
|
ElNotification({
|
|
|
title: res.data.message,
|
|
|
message: h('div', null, [
|
|
@@ -115,7 +96,18 @@ export class Interceptors {
|
|
|
type: 'warning',
|
|
|
size: 'small',
|
|
|
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: () => '错误日志' },
|
|
|
),
|