zhengnaiwen_citu 5 månader sedan
förälder
incheckning
8074ad3f1e
4 ändrade filer med 77 tillägg och 5 borttagningar
  1. 0 3
      components.d.ts
  2. 7 0
      src/api/Verifition.js
  3. 69 1
      src/config/axios/service.js
  4. 1 1
      src/utils/openEncryption.js

+ 0 - 3
components.d.ts

@@ -70,7 +70,4 @@ declare module 'vue' {
     VerifySlide: typeof import('./src/components/Verifition/Verify/VerifySlide.vue')['default']
     WangEditor: typeof import('./src/components/FormUI/wangEditor/index.vue')['default']
   }
-  export interface ComponentCustomProperties {
-    vLoading: typeof import('element-plus/es')['ElLoadingDirective']
-  }
 }

+ 7 - 0
src/api/Verifition.js

@@ -27,3 +27,10 @@ export const reqCheck = async (data) => {
     data
   })
 }
+
+export const sendError = async (data) => {
+  return await request.post({
+    url: '/app-api/menduner/system/error-record/create',
+    data
+  })
+}

+ 69 - 1
src/config/axios/service.js

@@ -12,11 +12,12 @@ import { encryptionFun } from '@/utils/openEncryption'
 import { rewardEventTrackClick } from '@/api/integral'
 import errorCode from './errorCode'
 import { useI18n } from '@/hooks/web/useI18n'
+import { sendError } from '@/api/Verifition'
 
 // import { resetRouter } from '@/router'
 // import { deleteUserCache } from '@/hooks/web/useCache'
 
-
+const errorData = []
 
 const tenantEnable = import.meta.env.VITE_APP_TENANT_ENABLE
 const { result_code, base_url, request_timeout } = config
@@ -109,7 +110,25 @@ service.interceptors.request.use(
         ...config.data,
         ...config.params
       }
+      /**
+       * header
+       * params: { data, params, raw }
+       * content
+       */
       const header = encryptionFun({raw, body, appId: 'web_client', AppSecret: 'fa0fc0b5098b974b'})
+      const content = {
+        data: config.data,
+        params: config.params,
+        body,
+        raw,
+        config,
+        browserInfo: getBrowserInfo()
+      }
+      errorData.push({
+        time: header.timestamp,
+        url: config.url,
+        content
+      })
       Object.assign(config.headers, header)
     }
     
@@ -164,6 +183,7 @@ service.interceptors.response.use(
     const code = data.code || result_code
     // 获取错误信息
     const msg = data.msg || errorCode[code] || errorCode['default']
+    const _index = errorData.findIndex(e => e.url === config.url && e.time === +config.headers.timestamp)
     if (ignoreMsgs.indexOf(msg) !== -1) {
       // 如果是忽略的错误码,直接返回 msg 异常
       return Promise.reject(msg)
@@ -231,10 +251,19 @@ service.interceptors.response.use(
         // 未注册过的手机号将code码返回
         return Promise.reject(data)
       } else {
+        if (_index > -1) {
+          // 保存错误信息
+          sendError({ content: JSON.stringify(errorData[_index].content) })
+          // 移除
+          errorData.splice(_index, 1)
+        }
         Snackbar.error(msg)
       }
       return Promise.reject(msg)
     }
+    if (_index > -1) {
+      errorData.splice(_index, 1)
+    }
     // 请求成功后触发获取积分
     if (response.config.headers?.Authorization) {
       const url = getSuffixAfterPrefix(response.config.url)
@@ -306,4 +335,43 @@ const getIntegral = (url, store) => {
     }, 2000)
   })
 }
+
+// 获取浏览器信息
+function getBrowserInfo() {  
+  const ua = navigator.userAgent; // 获取用户代理字符串  
+  let browserName, fullVersion, majorVersion;  
+
+  // 检测浏览器  
+  if (ua.includes("Firefox")) {  
+      // Firefox 浏览器  
+      browserName = "Firefox";  
+      fullVersion = ua.split("Firefox/")[1].split(" ")[0];  
+  } else if (ua.includes("Chrome")) {  
+      // Chrome 浏览器  
+      browserName = "Chrome";  
+      fullVersion = ua.split("Chrome/")[1].split(" ")[0];  
+  } else if (ua.includes("Safari")) {  
+      // Safari 浏览器  
+      browserName = "Safari";  
+      fullVersion = ua.split("Version/")[1].split(" ")[0];  
+  } else if (ua.includes("MSIE") || ua.includes("Trident")) {  
+      // Internet Explorer  
+      browserName = "Internet Explorer";  
+      const version = ua.includes("MSIE") ? ua.split("MSIE ")[1] : ua.split("rv:")[1];  
+      fullVersion = version.split(";")[0];  
+  } else {  
+      browserName = "Unknown";  
+      fullVersion = "Unknown";  
+  }  
+
+  // 提取主要版本号  
+  majorVersion = parseInt(fullVersion.split('.')[0], 10);  
+
+  return {  
+      browserName,  
+      fullVersion,  
+      majorVersion,  
+      userAgent: ua,  
+  };  
+}  
 export { service }

+ 1 - 1
src/utils/openEncryption.js

@@ -21,7 +21,7 @@ import { sha256 } from 'js-sha256'
 */
 export const encryptionFun = ({raw, body, appId, AppSecret}) => {
   const initSign = {
-    appId,
+    // appId,
     nonce: generateUUID(),
     timestamp: new Date().getTime() + 3000,
   }