123
This commit is contained in:
@@ -14,6 +14,8 @@ import { setObjToUrlParams } from '@/utils/urlUtils';
|
||||
import { RequestOptions, Result, CreateAxiosOptions } from './types';
|
||||
|
||||
import { useUserStoreWidthOut } from '@/store/modules/user';
|
||||
import {domainStoreWidthOut} from "@/store/modules/domain";
|
||||
import {domainList} from "@/api/login";
|
||||
|
||||
const urlPrefix = '';
|
||||
|
||||
@@ -38,6 +40,10 @@ const transform: AxiosTransform = {
|
||||
isReturnNativeResponse,
|
||||
} = options;
|
||||
|
||||
if(res.request.responseURL.includes(domainList)){
|
||||
return res;
|
||||
}
|
||||
|
||||
// 是否返回原生响应头 比如:需要获取响应头时使用该属性
|
||||
if (isReturnNativeResponse) {
|
||||
return res;
|
||||
@@ -122,16 +128,22 @@ const transform: AxiosTransform = {
|
||||
// 请求之前处理config
|
||||
beforeRequestHook: (config, options) => {
|
||||
const { apiUrl, joinPrefix, joinParamsToUrl, formatDate, joinTime = true, urlPrefix } = options;
|
||||
|
||||
const isUrlStr = isUrl(config.url as string);
|
||||
|
||||
if (!isUrlStr && joinPrefix) {
|
||||
config.url = `${urlPrefix}${config.url}`;
|
||||
}
|
||||
|
||||
if (!isUrlStr && apiUrl && isString(apiUrl)) {
|
||||
config.url = `${apiUrl}${config.url}`;
|
||||
if(!isUrlStr){
|
||||
let domain = domainStoreWidthOut().getDomain;
|
||||
if(domain && domain.length > 0){
|
||||
let domainUrl = domain[Math.floor((Math.random()*domain.length))];
|
||||
config.url = domainUrl + config.url;
|
||||
}else if(apiUrl && isString(apiUrl)){
|
||||
config.url = `${apiUrl}${config.url}`;
|
||||
}
|
||||
}
|
||||
// if (!isUrlStr && apiUrl && isString(apiUrl)) {
|
||||
// config.url = `${apiUrl}${config.url}`;
|
||||
// }
|
||||
const params = config.params || {};
|
||||
const data = config.data || false;
|
||||
if (config.method?.toUpperCase() === RequestEnum.GET) {
|
||||
|
||||
Reference in New Issue
Block a user