|
@@ -1,5 +1,6 @@
|
|
|
import axios from 'axios'
|
|
|
-import { ElMessage, ElNotification } from 'element-plus'
|
|
|
+import { ElButton, ElMessage, ElNotification } from 'element-plus'
|
|
|
+import { h } from 'vue'
|
|
|
|
|
|
// import {toLogin} from "@/utils/permissions";
|
|
|
export class Interceptors {
|
|
@@ -64,12 +65,62 @@ 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
|
|
|
+ }
|
|
|
+ let str = ''
|
|
|
+ arr.forEach((v) => {
|
|
|
+ if (typeof v === 'string') {
|
|
|
+ str += v
|
|
|
+ } else {
|
|
|
+ str += convertDataToText(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'
|
|
|
+ document.body.appendChild(a)
|
|
|
+ a.click()
|
|
|
+ setTimeout(() => {
|
|
|
+ document.body.removeChild(a)
|
|
|
+ URL.revokeObjectURL(url)
|
|
|
+ }, 0)
|
|
|
+ }
|
|
|
// 状态码判断
|
|
|
switch (res.status) {
|
|
|
case 400:
|
|
|
+ // ElNotification({
|
|
|
+ // title: res.data.message,
|
|
|
+ // message: res.data.data,
|
|
|
+ // type: 'error',
|
|
|
+ // duration: 0,
|
|
|
+ // })
|
|
|
ElNotification({
|
|
|
title: res.data.message,
|
|
|
- message: res.data.data,
|
|
|
+ message: h('div', null, [
|
|
|
+ h(
|
|
|
+ ElButton,
|
|
|
+ {
|
|
|
+ type: 'warning',
|
|
|
+ size: 'small',
|
|
|
+ plain: true,
|
|
|
+ onClick: exportLog,
|
|
|
+ },
|
|
|
+ { default: () => '错误日志' },
|
|
|
+ ),
|
|
|
+ h('div', { class: 'mt-2' }, res.data.data),
|
|
|
+ ]),
|
|
|
type: 'error',
|
|
|
duration: 0,
|
|
|
})
|