CzRger 1 месяц назад
Родитель
Сommit
3f09603c9f
1 измененных файлов с 55 добавлено и 52 удалено
  1. 55 52
      src/api/interceptors.ts

+ 55 - 52
src/api/interceptors.ts

@@ -70,59 +70,62 @@ export class Interceptors {
   }
 
   private errorHandle(res: any) {
-    console.error('错误接口:' + res.request.responseURL)
-    const exportLog = () => {
-      let str = ''
-      const arr = [
-        `错误日期:${YMDHms(res.headers.date)}`,
-        `请求方式:${res.config.method.toUpperCase()}`,
-        `接口地址:${res.request.responseURL}`,
-        `接口状态:${res.status} ${res.statusText}`,
-        `请求Token:${res.config.headers.Authorization}`,
-        `请求参数:${res.config.data || ''}`,
-        `返回结果:${res.request.response}`,
-      ]
-      arr.forEach((v) => {
-        str += v
-        str += '\n\n'
+    const hasLogin = (import.meta as any).env.VITE_LOGIN_MUST === 'Y'
+    if (hasLogin) {
+      console.error('错误接口:' + res.request.responseURL)
+      const exportLog = () => {
+        let str = ''
+        const arr = [
+          `错误日期:${YMDHms(res.headers.date)}`,
+          `请求方式:${res.config.method.toUpperCase()}`,
+          `接口地址:${res.request.responseURL}`,
+          `接口状态:${res.status} ${res.statusText}`,
+          `请求Token:${res.config.headers.Authorization}`,
+          `请求参数:${res.config.data || ''}`,
+          `返回结果:${res.request.response}`,
+        ]
+        arr.forEach((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 = `错误日志(${YMDHms(res.headers.date)}).txt`
+        document.body.appendChild(a)
+        a.click()
+        setTimeout(() => {
+          document.body.removeChild(a)
+          URL.revokeObjectURL(url)
+        }, 0)
+      }
+      ElNotification({
+        title: res.data.message,
+        message: h('div', null, [
+          h(
+            ElButton,
+            {
+              type: 'warning',
+              size: 'small',
+              plain: true,
+              onClick: () => exportLog(),
+            },
+            { default: () => '错误日志' },
+          ),
+          h(
+            'div',
+            { class: 'mt-2 overflow-y-auto', style: 'max-height: 50vh;' },
+            res.data.data
+              ? typeof res.data.data === 'string'
+                ? res.data.data
+                : JSON.stringify(res.data.data)
+              : '',
+          ),
+        ]),
+        type: 'error',
+        duration: 0,
       })
-      const blob = new Blob([str], { type: 'text/plain' })
-      const url = URL.createObjectURL(blob)
-      const a = document.createElement('a')
-      a.href = url
-      a.download = `错误日志(${YMDHms(res.headers.date)}).txt`
-      document.body.appendChild(a)
-      a.click()
-      setTimeout(() => {
-        document.body.removeChild(a)
-        URL.revokeObjectURL(url)
-      }, 0)
     }
-    ElNotification({
-      title: res.data.message,
-      message: h('div', null, [
-        h(
-          ElButton,
-          {
-            type: 'warning',
-            size: 'small',
-            plain: true,
-            onClick: () => exportLog(),
-          },
-          { default: () => '错误日志' },
-        ),
-        h(
-          'div',
-          { class: 'mt-2 overflow-y-auto', style: 'max-height: 50vh;' },
-          res.data.data
-            ? typeof res.data.data === 'string'
-              ? res.data.data
-              : JSON.stringify(res.data.data)
-            : '',
-        ),
-      ]),
-      type: 'error',
-      duration: 0,
-    })
   }
 }