Commit d5f9919b60fdd7d5c435129e8db519c0bbd37529

Authored by JinMao
1 parent aed622bd

fix: fix defHttp baseUrl work

Showing 1 changed file with 5 additions and 1 deletions
src/utils/http/axios/index.ts
@@ -80,6 +80,7 @@ const transform: AxiosTransform = { @@ -80,6 +80,7 @@ const transform: AxiosTransform = {
80 80
81 // 请求之前处理config 81 // 请求之前处理config
82 beforeRequestHook: (config, options) => { 82 beforeRequestHook: (config, options) => {
  83 + const { baseURL } = config;
83 const { apiUrl, joinPrefix, joinParamsToUrl, formatDate, joinTime = true } = options; 84 const { apiUrl, joinPrefix, joinParamsToUrl, formatDate, joinTime = true } = options;
84 85
85 if (joinPrefix) { 86 if (joinPrefix) {
@@ -89,6 +90,9 @@ const transform: AxiosTransform = { @@ -89,6 +90,9 @@ const transform: AxiosTransform = {
89 if (apiUrl && isString(apiUrl)) { 90 if (apiUrl && isString(apiUrl)) {
90 config.url = `${apiUrl}${config.url}`; 91 config.url = `${apiUrl}${config.url}`;
91 } 92 }
  93 + if (baseURL && isString(baseURL)) {
  94 + config.url = `${baseURL}${config.url}`;
  95 + }
92 const params = config.params || {}; 96 const params = config.params || {};
93 if (config.method?.toUpperCase() === RequestEnum.GET) { 97 if (config.method?.toUpperCase() === RequestEnum.GET) {
94 if (!isString(params)) { 98 if (!isString(params)) {
@@ -186,7 +190,7 @@ function createAxios(opt?: Partial<CreateAxiosOptions>) { @@ -186,7 +190,7 @@ function createAxios(opt?: Partial<CreateAxiosOptions>) {
186 authenticationScheme: '', 190 authenticationScheme: '',
187 timeout: 10 * 1000, 191 timeout: 10 * 1000,
188 // 基础接口地址 192 // 基础接口地址
189 - // baseURL: globSetting.apiUrl, 193 + baseURL: globSetting.apiUrl,
190 // 接口可能会有通用的地址部分,可以统一抽取出来 194 // 接口可能会有通用的地址部分,可以统一抽取出来
191 urlPrefix: urlPrefix, 195 urlPrefix: urlPrefix,
192 headers: { 'Content-Type': ContentTypeEnum.JSON }, 196 headers: { 'Content-Type': ContentTypeEnum.JSON },