|
@@ -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 }
|