From a7fd34f1ecdf914f23fc98bd91366b04d3e1fed9 Mon Sep 17 00:00:00 2001 From: yangyin <1850366751@qq.com> Date: 星期二, 08 十月 2024 15:41:59 +0800 Subject: [PATCH] 新增指标详情页面 --- src/utils/request.ts | 19 ++++++++++++------- 1 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/utils/request.ts b/src/utils/request.ts index 11258fd..be836d4 100644 --- a/src/utils/request.ts +++ b/src/utils/request.ts @@ -1,15 +1,17 @@ -import type { AxiosInstance, AxiosRequestConfig } from 'axios'; +import type { AxiosInstance, AxiosRequestConfig, CancelToken } from 'axios'; import axios from 'axios'; import { ElLoadingService, ElMessage } from 'element-plus'; import router from '../router'; -import { debounce } from './util'; +import { debounce, decodeFormData } from './util'; import { AUTH_URL, MAIN_URL, SECONDARY_URL } from '/@/constants'; import { Local, Session } from '/@/utils/storage'; +import { Logger } from '../model/logger/Logger'; // import JSONbig from 'json-bigint'; export type ExtraConfig = { loading?: boolean; noAuth?: boolean; handleFail?: boolean; + cancelToken?: CancelToken | undefined; }; export const checkAuth = () => { const session = Local.get(accessSessionKey); @@ -37,11 +39,12 @@ clearAccessTokens(); window.location.reload(); }); +window.handleNoAuth = handleNoAuth; let requestNum = 0; let loadingInstance: ReturnType<typeof ElLoadingService>; const addLoading = () => { - // 澧炲姞loading 濡傛灉pending璇锋眰鏁伴噺绛変簬1锛屽脊鍑簂oading, 闃叉閲嶅寮瑰嚭 + // 澧炲姞loading 濡傛灉pending璇锋眰鏁伴噺绛変簬1锛屽脊鍑簂oading, 闃叉閲嶅寮瑰嚭F requestNum++; if (requestNum == 1) { loadingInstance = ElLoadingService({ @@ -112,17 +115,19 @@ case ErrorCode.Auth: handleNoAuth(); throw '鏉冮檺楠岃瘉澶辫触'; - break; case ErrorCode.Exception: + const param = res.config.data ? `\n 璇锋眰鍙傛暟锛�${JSON.stringify(decodeFormData(res.config.data))}\n` : ''; ElMessage.error('鍐呴儴閿欒锛�'); - throw '鍐呴儴閿欒'; + Logger.error(`${res.config.url} 鍝嶅簲澶辫触${param}`, serveData?.json_msg && new Error(serveData?.json_msg)); + return res.data; } // 闈� message error锛屼笖 handleFail 涓� true // message error 涓嶉渶瑕佸鐞� if (handleFail && serveData?.err_code !== ErrorCode.Message) { - const errorText = serveData?.json_msg || '鍝嶅簲澶辫触锛�'; + const errorText = serveData?.json_msg; ElMessage.error(errorText); - throw errorText; + const param = res.config.data ? `\n 璇锋眰鍙傛暟锛�${JSON.stringify(decodeFormData(res.config.data))}\n` : ''; + Logger.error(`${res.config.url} 鍝嶅簲澶辫触${param}`, errorText && new Error(errorText)); } } return res.data; -- Gitblit v1.9.3