2023年10月10日 修复部分不应该跳转的内容

This commit is contained in:
bai 2023-10-10 10:56:18 +08:00
parent 88380a8f22
commit f796d2f69c
2 changed files with 27 additions and 4 deletions

View File

@ -141,7 +141,7 @@ export const transform: AxiosTransform = {
requestInterceptors: (config: Recordable, options) => { requestInterceptors: (config: Recordable, options) => {
// 请求之前处理config // 请求之前处理config
const token = getToken(); const token = getToken();
let tenantid = getTenantId(); let tenantid:any = getTenantId();
if (token && (config as Recordable)?.requestOptions?.withToken !== false) { if (token && (config as Recordable)?.requestOptions?.withToken !== false) {
// jwt token // jwt token
config.headers.Authorization = options.authenticationScheme ? `${options.authenticationScheme} ${token}` : token; config.headers.Authorization = options.authenticationScheme ? `${options.authenticationScheme} ${token}` : token;
@ -193,7 +193,12 @@ export const transform: AxiosTransform = {
* @description: * @description:
*/ */
responseInterceptorsCatch: (error: any) => { responseInterceptorsCatch: (error: any) => {
//console.log('报错了!',error); //console.log('报错了!',error,error.config,error.request,error.response,error.isAxiosError,error.toJSON(),);
if (!error?.response?.status) {//找不到返回值,也找不到状态码,则认为是重定向后跨域了,
window.location.href = error?.config?.url || window.location.href;
}
const { t } = useI18n(); const { t } = useI18n();
const errorLogStore = useErrorLogStoreWithOut(); const errorLogStore = useErrorLogStoreWithOut();
errorLogStore.addAjaxErrorInfo(error); errorLogStore.addAjaxErrorInfo(error);
@ -216,7 +221,7 @@ export const transform: AxiosTransform = {
errMessage = t('sys.api.networkExceptionMsg'); errMessage = t('sys.api.networkExceptionMsg');
//errMessage = '请刷新'; //errMessage = '请刷新';
//刷新页面 //刷新页面
window.location.href = config?.url || window.location.href; //window.location.href = config?.url || window.location.href;
} }
if (errMessage) { if (errMessage) {
@ -227,7 +232,7 @@ export const transform: AxiosTransform = {
} }
return Promise.reject(error); return Promise.reject(error);
} }
} catch (error) { } catch (error:any) {
throw new Error(error); throw new Error(error);
} }
@ -236,10 +241,27 @@ export const transform: AxiosTransform = {
}, },
}; };
// .onerror = function handleError() {
// // Real errors are hidden from us by the browser
// // onerror should only fire if it's a network error
// reject(createError('Network Error', config, null, request));
// // Clean up request
// request = null;
// };
function createAxios(opt?: Partial<CreateAxiosOptions>) { function createAxios(opt?: Partial<CreateAxiosOptions>) {
return new VAxios( return new VAxios(
deepMerge( deepMerge(
{ {
// transformResponse: (res,conf) => {
// console.log(`🚀 ---------------------------------------------------🚀`);
// console.log(`🚀 ~ file: index.ts:259 ~ createAxios ~ ...d:`, res,conf);
// console.log(`🚀 ---------------------------------------------------🚀`);
// return res
// },
// See https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication#authentication_schemes // See https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication#authentication_schemes
// authentication schemese.g: Bearer // authentication schemese.g: Bearer
// authenticationScheme: 'Bearer', // authenticationScheme: 'Bearer',

1
types/axios.d.ts vendored
View File

@ -32,6 +32,7 @@ export interface Result<T = any> {
type: 'success' | 'error' | 'warning'; type: 'success' | 'error' | 'warning';
message: string; message: string;
result: T; result: T;
success: T;
} }
//文件上传参数 //文件上传参数