Commit 50f94bfee4c58b864e335269d698a26f48b75ccb
1 parent
ee384b1f
chore(axios): remove useless code
Showing
5 changed files
with
9 additions
and
14 deletions
src/utils/http/axios/Axios.ts
@@ -8,7 +8,6 @@ import { AxiosCanceler } from './axiosCancel'; | @@ -8,7 +8,6 @@ import { AxiosCanceler } from './axiosCancel'; | ||
8 | import { isFunction } from '/@/utils/is'; | 8 | import { isFunction } from '/@/utils/is'; |
9 | import { cloneDeep } from 'lodash-es'; | 9 | import { cloneDeep } from 'lodash-es'; |
10 | 10 | ||
11 | -//import { errorResult } from './const'; | ||
12 | import { ContentTypeEnum } from '/@/enums/httpEnum'; | 11 | import { ContentTypeEnum } from '/@/enums/httpEnum'; |
13 | import { RequestEnum } from '../../../enums/httpEnum'; | 12 | import { RequestEnum } from '../../../enums/httpEnum'; |
14 | 13 |
src/utils/http/axios/axiosTransform.ts
@@ -5,7 +5,7 @@ import type { AxiosRequestConfig, AxiosResponse } from 'axios'; | @@ -5,7 +5,7 @@ import type { AxiosRequestConfig, AxiosResponse } from 'axios'; | ||
5 | import type { RequestOptions, Result } from './types'; | 5 | import type { RequestOptions, Result } from './types'; |
6 | 6 | ||
7 | export interface CreateAxiosOptions extends AxiosRequestConfig { | 7 | export interface CreateAxiosOptions extends AxiosRequestConfig { |
8 | - prefixUrl?: string; | 8 | + urlPrefix?: string; |
9 | transform?: AxiosTransform; | 9 | transform?: AxiosTransform; |
10 | requestOptions?: RequestOptions; | 10 | requestOptions?: RequestOptions; |
11 | } | 11 | } |
src/utils/http/axios/const.ts deleted
100644 → 0
src/utils/http/axios/helper.ts
@@ -2,12 +2,12 @@ import { isObject, isString } from '/@/utils/is'; | @@ -2,12 +2,12 @@ import { isObject, isString } from '/@/utils/is'; | ||
2 | 2 | ||
3 | const DATE_TIME_FORMAT = 'YYYY-MM-DD HH:mm'; | 3 | const DATE_TIME_FORMAT = 'YYYY-MM-DD HH:mm'; |
4 | 4 | ||
5 | -export function createNow<T extends boolean>( | 5 | +export function joinTimestamp<T extends boolean>( |
6 | join: boolean, | 6 | join: boolean, |
7 | restful: T | 7 | restful: T |
8 | ): T extends true ? string : object; | 8 | ): T extends true ? string : object; |
9 | 9 | ||
10 | -export function createNow(join: boolean, restful = false): string | object { | 10 | +export function joinTimestamp(join: boolean, restful = false): string | object { |
11 | if (!join) { | 11 | if (!join) { |
12 | return restful ? '' : {}; | 12 | return restful ? '' : {}; |
13 | } | 13 | } |
src/utils/http/axios/index.ts
@@ -18,12 +18,11 @@ import { getToken } from '/@/utils/auth'; | @@ -18,12 +18,11 @@ import { getToken } from '/@/utils/auth'; | ||
18 | import { setObjToUrlParams, deepMerge } from '/@/utils'; | 18 | import { setObjToUrlParams, deepMerge } from '/@/utils'; |
19 | import { useErrorLogStoreWithOut } from '/@/store/modules/errorLog'; | 19 | import { useErrorLogStoreWithOut } from '/@/store/modules/errorLog'; |
20 | 20 | ||
21 | -//import { errorResult } from './const'; | ||
22 | import { useI18n } from '/@/hooks/web/useI18n'; | 21 | import { useI18n } from '/@/hooks/web/useI18n'; |
23 | -import { createNow, formatRequestDate } from './helper'; | 22 | +import { joinTimestamp, formatRequestDate } from './helper'; |
24 | 23 | ||
25 | const globSetting = useGlobSetting(); | 24 | const globSetting = useGlobSetting(); |
26 | -const prefix = globSetting.urlPrefix; | 25 | +const urlPrefix = globSetting.urlPrefix; |
27 | const { createMessage, createErrorModal } = useMessage(); | 26 | const { createMessage, createErrorModal } = useMessage(); |
28 | 27 | ||
29 | /** | 28 | /** |
@@ -51,7 +50,6 @@ const transform: AxiosTransform = { | @@ -51,7 +50,6 @@ const transform: AxiosTransform = { | ||
51 | if (!data) { | 50 | if (!data) { |
52 | // return '[HTTP] Request has no return value'; | 51 | // return '[HTTP] Request has no return value'; |
53 | throw new Error(t('sys.api.apiRequestFailed')); | 52 | throw new Error(t('sys.api.apiRequestFailed')); |
54 | - //return errorResult; | ||
55 | } | 53 | } |
56 | // 这里 code,result,message为 后台统一的字段,需要在 types.ts内修改为项目自己的接口返回格式 | 54 | // 这里 code,result,message为 后台统一的字段,需要在 types.ts内修改为项目自己的接口返回格式 |
57 | const { code, result, message } = data; | 55 | const { code, result, message } = data; |
@@ -91,7 +89,7 @@ const transform: AxiosTransform = { | @@ -91,7 +89,7 @@ const transform: AxiosTransform = { | ||
91 | const { apiUrl, joinPrefix, joinParamsToUrl, formatDate, joinTime = true } = options; | 89 | const { apiUrl, joinPrefix, joinParamsToUrl, formatDate, joinTime = true } = options; |
92 | 90 | ||
93 | if (joinPrefix) { | 91 | if (joinPrefix) { |
94 | - config.url = `${prefix}${config.url}`; | 92 | + config.url = `${urlPrefix}${config.url}`; |
95 | } | 93 | } |
96 | 94 | ||
97 | if (apiUrl && isString(apiUrl)) { | 95 | if (apiUrl && isString(apiUrl)) { |
@@ -101,10 +99,10 @@ const transform: AxiosTransform = { | @@ -101,10 +99,10 @@ const transform: AxiosTransform = { | ||
101 | if (config.method?.toUpperCase() === RequestEnum.GET) { | 99 | if (config.method?.toUpperCase() === RequestEnum.GET) { |
102 | if (!isString(params)) { | 100 | if (!isString(params)) { |
103 | // 给 get 请求加上时间戳参数,避免从缓存中拿数据。 | 101 | // 给 get 请求加上时间戳参数,避免从缓存中拿数据。 |
104 | - config.params = Object.assign(params || {}, createNow(joinTime, false)); | 102 | + config.params = Object.assign(params || {}, joinTimestamp(joinTime, false)); |
105 | } else { | 103 | } else { |
106 | // 兼容restful风格 | 104 | // 兼容restful风格 |
107 | - config.url = config.url + params + `${createNow(joinTime, true)}`; | 105 | + config.url = config.url + params + `${joinTimestamp(joinTime, true)}`; |
108 | config.params = undefined; | 106 | config.params = undefined; |
109 | } | 107 | } |
110 | } else { | 108 | } else { |
@@ -173,7 +171,7 @@ function createAxios(opt?: Partial<CreateAxiosOptions>) { | @@ -173,7 +171,7 @@ function createAxios(opt?: Partial<CreateAxiosOptions>) { | ||
173 | // 基础接口地址 | 171 | // 基础接口地址 |
174 | // baseURL: globSetting.apiUrl, | 172 | // baseURL: globSetting.apiUrl, |
175 | // 接口可能会有通用的地址部分,可以统一抽取出来 | 173 | // 接口可能会有通用的地址部分,可以统一抽取出来 |
176 | - prefixUrl: prefix, | 174 | + urlPrefix: urlPrefix, |
177 | headers: { 'Content-Type': ContentTypeEnum.JSON }, | 175 | headers: { 'Content-Type': ContentTypeEnum.JSON }, |
178 | // 如果是form-data格式 | 176 | // 如果是form-data格式 |
179 | // headers: { 'Content-Type': ContentTypeEnum.FORM_URLENCODED }, | 177 | // headers: { 'Content-Type': ContentTypeEnum.FORM_URLENCODED }, |